From 084879908c947745e40819eaabaec4c9f91be288 Mon Sep 17 00:00:00 2001 From: Stuart Dilts Date: Fri, 10 May 2024 12:40:38 -0600 Subject: [PATCH] Add set-position generic function Add single function to set both the x and y coordinate so of an object and use it. --- lisp/interfaces/view-interface.lisp | 3 +++ lisp/tree/frame.lisp | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lisp/interfaces/view-interface.lisp b/lisp/interfaces/view-interface.lisp index c280c91..4dd5028 100644 --- a/lisp/interfaces/view-interface.lisp +++ b/lisp/interfaces/view-interface.lisp @@ -34,3 +34,6 @@ (print-unreadable-object (object stream :type t) (with-slots (x y) object (format stream ":x ~S :y ~S" x y)))) + +(defgeneric set-position (object x y) + (:documentation "Set the x-y position of the object")) diff --git a/lisp/tree/frame.lisp b/lisp/tree/frame.lisp index 49780a8..8fa6e23 100644 --- a/lisp/tree/frame.lisp +++ b/lisp/tree/frame.lisp @@ -36,12 +36,10 @@ (tmp-y (frame-y frame1)) (tmp-width (frame-width frame1)) (tmp-height (frame-height frame1))) - (setf (frame-x frame1) (frame-x frame2) - (frame-y frame1) (frame-y frame2)) + (set-position frame1 (frame-x frame2) (frame-y frame2)) (set-dimensions frame1 (frame-width frame2) (frame-height frame2)) - (setf (frame-x frame2) tmp-x - (frame-y frame2) tmp-y) + (set-position frame2 tmp-x tmp-y) (set-dimensions frame2 tmp-width tmp-height)) (let ((frame1-parent (frame-parent frame1)) @@ -101,6 +99,10 @@ (setf (frame-width frame) width (frame-height frame) height)) +(defmethod set-position ((frame frame) x y) + (setf (frame-x frame) x + (frame-y frame) y)) + (defmethod split-frame-h :before ((frame frame) &key ratio direction) (declare (ignore frame direction)) (when ratio @@ -141,8 +143,7 @@ of FRAME to those of ROOT." (setf (frame-parent frame) (frame-parent root)) ;; don't bother with an if-statement to see which values to change: (set-dimensions frame (frame-width root) (frame-height root)) - (setf (frame-x frame) (frame-x root) - (frame-y frame) (frame-y root))) + (set-position frame (frame-x root) (frame-y root))) (defun binary-split-h (frame ratio direction parent-type) "Split a frame in two, with the resulting parent frame of type parent-frame.