mirror of
https://git.planet-casio.com/Lephenixnoir/JustUI.git
synced 2024-12-28 04:23:40 +01:00
jscene: add a stronger focus function
This commit is contained in:
parent
d0856d100b
commit
4e01a99b0b
4 changed files with 52 additions and 0 deletions
|
@ -87,6 +87,14 @@ void *jscene_focused_widget(jscene *scene);
|
||||||
The selected widget, obviously, must be a descendant of the scene. */
|
The selected widget, obviously, must be a descendant of the scene. */
|
||||||
void jscene_set_focused_widget(jscene *scene, void *widget);
|
void jscene_set_focused_widget(jscene *scene, void *widget);
|
||||||
|
|
||||||
|
/* jscene_show_and_focus(): Make a widget visible and focus it
|
||||||
|
This function does three things:
|
||||||
|
1. Set the visibility of the target widget to [true]
|
||||||
|
2. Configure any parent with a stacked layout to show the child that
|
||||||
|
contains the target widget
|
||||||
|
3. Focus the target widget */
|
||||||
|
void jscene_show_and_focus(jscene *scene, void *widget);
|
||||||
|
|
||||||
/* jscene_process_key_event(): Send a key event to the focused widget
|
/* jscene_process_key_event(): Send a key event to the focused widget
|
||||||
Returns true if the event was accepted, false if it was ignored. */
|
Returns true if the event was accepted, false if it was ignored. */
|
||||||
bool jscene_process_key_event(jscene *scene, key_event_t event);
|
bool jscene_process_key_event(jscene *scene, key_event_t event);
|
||||||
|
|
|
@ -204,6 +204,9 @@ void jwidget_insert_child(void *w, void *child, int position);
|
||||||
(w) must be the parent of (child). The child is left without a parent. */
|
(w) must be the parent of (child). The child is left without a parent. */
|
||||||
void jwidget_remove_child(void *w, void *child);
|
void jwidget_remove_child(void *w, void *child);
|
||||||
|
|
||||||
|
/* jwidget_child_position(): Find the position of a widget in the child list */
|
||||||
|
int jwidget_child_position(void *w, void *child);
|
||||||
|
|
||||||
//---
|
//---
|
||||||
// Sizing and stretching
|
// Sizing and stretching
|
||||||
//---
|
//---
|
||||||
|
|
29
src/jscene.c
29
src/jscene.c
|
@ -138,6 +138,35 @@ void jscene_set_focused_widget(jscene *s, void *w0)
|
||||||
(jevent){ .type = JWIDGET_FOCUS_IN, .source = w });
|
(jevent){ .type = JWIDGET_FOCUS_IN, .source = w });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void jscene_show_and_focus(jscene *scene, void *w0)
|
||||||
|
{
|
||||||
|
J_CAST(w)
|
||||||
|
|
||||||
|
/* Ensure the widget is visible */
|
||||||
|
jwidget_set_visible(w, true);
|
||||||
|
|
||||||
|
/* Force stacked layouts all the wat up to [scene] to show [w] */
|
||||||
|
jwidget *current = w;
|
||||||
|
jwidget *parent = w->parent;
|
||||||
|
|
||||||
|
while(parent != (jwidget *)scene) {
|
||||||
|
jlayout_stack *stack = jlayout_get_stack(parent);
|
||||||
|
if(stack) {
|
||||||
|
int pos = jwidget_child_position(parent, current);
|
||||||
|
if(stack->active != pos) {
|
||||||
|
stack->active = pos;
|
||||||
|
parent->update = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
current = parent;
|
||||||
|
parent = current->parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Give the widget focus */
|
||||||
|
jscene_set_focused_widget(scene, w);
|
||||||
|
}
|
||||||
|
|
||||||
bool jscene_process_key_event(jscene *scene, key_event_t event)
|
bool jscene_process_key_event(jscene *scene, key_event_t event)
|
||||||
{
|
{
|
||||||
jwidget *candidate = scene->focus;
|
jwidget *candidate = scene->focus;
|
||||||
|
|
|
@ -249,6 +249,18 @@ void jwidget_remove_child(void *w0, void *child0)
|
||||||
w->dirty = 1;
|
w->dirty = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int jwidget_child_position(void *w0, void *child0)
|
||||||
|
{
|
||||||
|
J_CAST(w, child)
|
||||||
|
|
||||||
|
for(int i = 0; i < w->child_count; i++) {
|
||||||
|
if(w->children[i] == child)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
//---
|
//---
|
||||||
// Sizing and stretching
|
// Sizing and stretching
|
||||||
//---
|
//---
|
||||||
|
|
Loading…
Reference in a new issue