summaryrefslogtreecommitdiff
path: root/src/ui/widget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-02-02 14:17:00 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-02-02 14:17:00 +0200
commit6d885dee5e3a9fc7316c901542eec21e39ae1f12 (patch)
tree2b8a2acb393329317e975d4294f28a5a34967d9a /src/ui/widget.c
parentec82863a833d3533381dddbb170a8505a24e159d (diff)
Improved focus switching for dialogs
Widgets can now be defined as being the "focus root", i.e., the topmost widget under which focus switching happens. Normally this is the window root widget, but dialogs use this flag to confine focus switching inside the dialog. InputWidget in Overwrite mode will focus switch to the next focusable widget when the text field becomes full.
Diffstat (limited to 'src/ui/widget.c')
-rw-r--r--src/ui/widget.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c
index e2d0f922..ddb3f092 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -877,8 +877,22 @@ static const iWidget *findFocusable_Widget_(const iWidget *d, const iWidget *sta
877 return NULL; 877 return NULL;
878} 878}
879 879
880static const iWidget *findFocusRoot_Widget_(const iWidget *d) {
881 iForEach(ObjectList, i, d->children) {
882 const iWidget *root = findFocusRoot_Widget_(constAs_Widget(i.object));
883 if (root) {
884 return root;
885 }
886 }
887 if (d->flags & focusRoot_WidgetFlag) {
888 return d;
889 }
890 return NULL;
891}
892
880iAny *findFocusable_Widget(const iWidget *startFrom, enum iWidgetFocusDir focusDir) { 893iAny *findFocusable_Widget(const iWidget *startFrom, enum iWidgetFocusDir focusDir) {
881 iWidget *root = get_Window()->root; 894 const iWidget *root = findFocusRoot_Widget_(get_Window()->root);
895 iAssert(root != NULL);
882 iBool getNext = (startFrom ? iFalse : iTrue); 896 iBool getNext = (startFrom ? iFalse : iTrue);
883 const iWidget *found = findFocusable_Widget_(root, startFrom, &getNext, focusDir); 897 const iWidget *found = findFocusable_Widget_(root, startFrom, &getNext, focusDir);
884 if (!found && startFrom) { 898 if (!found && startFrom) {