-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and optimize position setting methods for frames
In set-position, instead of delegating to the frame-x and frame-y setters, calculate the values in the method and call set-position again. This reduces method calls overall, especially to clients. + Fix (setf (frame-x tree-frame)) and (setf (frame-y tree-frame)) so that they translate their children in the correct direction
- Loading branch information
Showing
3 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
(fiasco:define-test-package #:mahogany-tests/tree-2 | ||
(:use #:mahogany/tree #:mahogany/wm-interface)) | ||
|
||
(in-package #:mahogany-tests/tree-2) | ||
|
||
(defun make-basic-tree (&key (x 0) (y 0) (width 100) (height 100)) | ||
(let ((container (make-instance 'tree-container)) | ||
(frame (make-instance 'view-frame :x x :y y :width width :height height))) | ||
(setf (frame-parent frame) container) | ||
(setf (root-tree container) frame) | ||
(values frame container))) | ||
|
||
(defun make-tree-frame (children &key (x 0) (y 0) (width 100) (height 100)) | ||
(let ((parent (make-instance 'tree-frame :x 0 :y 0 :width 100 :height 100))) | ||
(dolist (c children) | ||
(setf (frame-parent c) parent)) | ||
(setf (tree-children parent) children) | ||
parent)) | ||
|
||
(fiasco:deftest set-position-view-frame () | ||
(let ((tree (make-basic-tree :x 0 :y 0))) | ||
(set-position tree 100 200) | ||
(is (= (frame-x tree) 100)) | ||
(is (= (frame-y tree) 200)))) | ||
|
||
(fiasco:deftest set-position-tree-frame () | ||
(let* ((child-1 (make-instance 'view-frame :x 0 :y 0 :width 50 :height 100)) | ||
(child-2 (make-instance 'view-frame :x 51 :y 0 :width 50 :height 100)) | ||
(parent (make-tree-frame (list child-1 child-2)))) | ||
(set-position parent 100 200) | ||
(is (= (frame-x child-1) 100)) | ||
(is (= (frame-y child-1) 200)) | ||
(is (= (frame-x child-2) 151)) | ||
(is (= (frame-y child-2) 200)))) | ||
|
||
(fiasco:deftest setf-frame-x-view-frame-sets-value () | ||
(let ((tree (make-basic-tree :x 0 :y 0))) | ||
(setf (frame-x tree) 100) | ||
(is (= 100 (frame-x tree))))) | ||
|
||
(fiasco:deftest setf-frame-y-view-frame-sets-value () | ||
(let ((tree (make-basic-tree :x 0 :y 0))) | ||
(setf (frame-y tree) 223) | ||
(is (= (frame-y tree) 223)))) | ||
|
||
(fiasco:deftest setf-frame-y-tree-frame () | ||
(let* ((child-1 (make-instance 'view-frame :x 0 :y 0 :width 50 :height 100)) | ||
(child-2 (make-instance 'view-frame :x 51 :y 0 :width 50 :height 100)) | ||
(parent (make-tree-frame (list child-1 child-2)))) | ||
(setf (frame-y parent) 100) | ||
(is (= (frame-x parent) 0)) | ||
(is (= (frame-y parent) 100)) | ||
(is (= (frame-x child-1) 0)) | ||
(is (= (frame-y child-2) 100)) | ||
(is (= (frame-x child-2) 51)))) | ||
|
||
(fiasco:deftest setf-frame-x-tree-frame () | ||
(let* ((child-1 (make-instance 'view-frame :x 0 :y 0 :width 50 :height 100)) | ||
(child-2 (make-instance 'view-frame :x 51 :y 0 :width 50 :height 100)) | ||
(parent (make-tree-frame (list child-1 child-2)))) | ||
(setf (frame-x parent) 100) | ||
(is (= (frame-x parent) 100)) | ||
(is (= (frame-y parent) 0)) | ||
(is (= (frame-x child-1) 100)) | ||
(is (= (frame-y child-2) 0)) | ||
(is (= (frame-x child-2) 151)))) |