aboutsummaryrefslogtreecommitdiff
path: root/kscurses/ui/scene_manager.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-08-17 20:28:47 +0100
committerdam <dam@gudinoff>2023-08-17 20:28:47 +0100
commit709879ee56d31fe543a0ad882713bd4e3d17d2d2 (patch)
tree12a35282bdd0f1f8a2159ade147944c89254db24 /kscurses/ui/scene_manager.jai
parentfa1b8ea54646f1a0f3eadef33e3a660b875cc1ff (diff)
downloadtask-time-tracker-709879ee56d31fe543a0ad882713bd4e3d17d2d2.tar.zst
task-time-tracker-709879ee56d31fe543a0ad882713bd4e3d17d2d2.zip
Added kscurses and testing program.
Diffstat (limited to 'kscurses/ui/scene_manager.jai')
-rw-r--r--kscurses/ui/scene_manager.jai48
1 files changed, 48 insertions, 0 deletions
diff --git a/kscurses/ui/scene_manager.jai b/kscurses/ui/scene_manager.jai
new file mode 100644
index 0000000..1caff8b
--- /dev/null
+++ b/kscurses/ui/scene_manager.jai
@@ -0,0 +1,48 @@
+UI_Scene :: struct {
+ root : *UI_Elem;
+ entry : *UI_Elem;
+}
+UI_Popup :: struct {
+ root : *UI_Elem;
+ entry : *UI_Elem;
+ size : ivec2 = .{-1, -1};
+}
+
+UI_Scene_Manager :: struct {
+ #as using base_parent : UI_Parent = .{type = .SCENE_MANAGER, box_type = .NONE};
+ scenes : []UI_Scene;
+}
+
+set_sub_elements :: (ui_scene_manager : *UI_Scene_Manager, scenes : ..UI_Scene) {
+ ui_scene_manager.scenes = scenes;
+ for ui_scene_manager.scenes it.root.parent = ui_scene_manager;
+}
+
+handle_key_scene_manager :: (ui_elem : *UI_Elem, key : Key) -> handled:bool {
+ using cast(*UI_Scene_Manager) ui_elem;
+ assert(cursor_state == .ON || cursor_state == .OUTSIDE);
+
+ handled := false;
+ if cursor_state == .OUTSIDE {
+ assert(xx active_element);
+ {
+ ok := false;
+ for s : scenes if s.root == active_element ok = true;
+ assert(ok);
+ }
+ handled = handle_key(active_element, key);
+ } else {
+ assert(xx !active_element);
+ }
+ return handled;
+}
+
+c_draw_scene_manager :: (canvas : *Canvas, ui_elem : *UI_Elem, zone : Ibox2, style : *UI_Style) -> bool {
+ using cast(*UI_Scene_Manager) ui_elem;
+ return c_draw(canvas, active_element, zone, style);
+}
+
+switch_scene :: (using ui_scene_manager : *UI_Scene_Manager, id : int) {
+ unset_active_recursive(__last_set);
+ set_active_recursive(scenes[id].entry);
+}