From 709879ee56d31fe543a0ad882713bd4e3d17d2d2 Mon Sep 17 00:00:00 2001 From: dam Date: Thu, 17 Aug 2023 20:28:47 +0100 Subject: Added kscurses and testing program. --- kscurses/ui/scene_manager.jai | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 kscurses/ui/scene_manager.jai (limited to 'kscurses/ui/scene_manager.jai') 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); +} -- cgit v1.2.3