From 9c058339dde198062e96674c515ea946de5902b5 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Mon, 27 Jun 2022 10:43:04 -0500 Subject: [modify] get-focus & refocus-on: allow focus on not focusablep --- examples/03-font-render.lisp | 14 +++++++++++++- wheelwork.lisp | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/03-font-render.lisp b/examples/03-font-render.lisp index 6e1637a..e04d0c8 100644 --- a/examples/03-font-render.lisp +++ b/examples/03-font-render.lisp @@ -4,9 +4,16 @@ (in-package #:ww.example/3) - (defclass font-display (ww::application) ()) +(ww::defhandler move-on-keydown + (ww::on-keydown () + (case scancode + (:scancode-up (incf (ww::unit-y target))) + (:scancode-down (decf (ww::unit-y target))) + (:scancode-left (decf (ww::unit-x target))) + (:scancode-right (incf (ww::unit-x target)))))) + (defmethod ww::boot ((app font-display)) (let ((hello (make-instance @@ -24,11 +31,16 @@ (ww::unit-y hello) 100) + (ww::set-handler hello #'move-on-keydown) + + (ww::refocus-on hello) + (ww::add-unit app hello))) (defun start () (ww::start (make-instance 'font-display + :refocus-on-mousedown-p nil :title "Wheelwork Example: Font display" :asset-root "~/projects/wheelwork/examples/"))) diff --git a/wheelwork.lisp b/wheelwork.lisp index c03a444..952dd22 100644 --- a/wheelwork.lisp +++ b/wheelwork.lisp @@ -372,9 +372,9 @@ necessary." (defun refocus-on (target &optional (app *application*)) - "Sets focus of application to TARGET, if TARGET is focusable. " - (when (focusablep target) - (setf (application-focus app) target))) + "Sets focus of application to TARGET. This works whether or not +TARGET is FOCUSABLEP" + (setf (application-focus app) target)) (defun get-focus (&optional (app *application*)) (or (application-focus app) app)) @@ -428,7 +428,7 @@ give focus to whatever was clicked." (let ((target (or (unit-under app x y) ; if no unit is under the mouse, app))) ; then target the app itself - (when (refocus-on-mousedown-p app) + (when (and (refocus-on-mousedown-p app) (focusablep target)) (refocus-on target)) (when-let (handler (get-handler-for target 'mousedown)) (funcall handler target x y clicks button wx wy))))) -- cgit v1.2.3