From c82d6751e9414d5c17aca7f8a1138086bd4f9c1d Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sat, 23 Jul 2022 13:49:09 -0500 Subject: [add] menu-specific option focus support --- gui/menus.lisp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gui/menus.lisp b/gui/menus.lisp index 2bc5c22..f758d51 100644 --- a/gui/menus.lisp +++ b/gui/menus.lisp @@ -5,6 +5,8 @@ (defclass/std menu (unit interactive) ((options :with :std nil :doc "A list of interactive units") + (focus :with :std nil + :doc "The option that is focused in this menu, if any.") (region :std (error "Menus require an explicit region")))) (defmethod initialize-instance :after ((menu menu) &key) @@ -14,6 +16,20 @@ (x menu) (region-left region) (y menu) (region-bottom region)))) +(defmethod (setf closer-mop:slot-value-using-class) :before + (new-value class (menu menu) slot) + (case (closer-mop:slot-definition-name slot) + (focus + (when (slot-boundp menu 'focus) + (unless (eq new-value (slot-value menu 'focus)) + (fire-blur-event-on (slot-value menu 'focus))))))) + +(defmethod (setf closer-mop:slot-value-using-class ) :after + (new-value class (menu menu) slot) + (case (closer-mop:slot-definition-name slot) + (focus + (fire-focus-event-on new-value)))) + (macrolet ((def-menu-accessors (&rest accessor-names) (let ((defs -- cgit v1.2.3