more reduction of direct mutuable state referencing
This commit is contained in:
parent
7ed0010761
commit
841260849e
@ -1,5 +1,14 @@
|
||||
package sectr
|
||||
|
||||
UI_ScreenMenuBar :: struct {
|
||||
pos, size : Vec2,
|
||||
container : UI_HBox,
|
||||
settings_btn : struct
|
||||
{
|
||||
using widget : UI_Widget,
|
||||
}
|
||||
}
|
||||
|
||||
UI_ScreenState :: struct
|
||||
{
|
||||
using base : UI_State,
|
||||
@ -9,43 +18,35 @@ UI_ScreenState :: struct
|
||||
// TODO(Ed): The docked should be the base, floating is should be nested within as a 'veiwport' to a 'desktop' or 'canvas'
|
||||
// docked : UI_Docking,
|
||||
|
||||
menu_bar : struct
|
||||
{
|
||||
pos, size : Vec2,
|
||||
container : UI_HBox,
|
||||
settings_btn : struct
|
||||
{
|
||||
using widget : UI_Widget,
|
||||
}
|
||||
},
|
||||
|
||||
menu_bar : UI_ScreenMenuBar,
|
||||
settings_menu : UI_SettingsMenu
|
||||
}
|
||||
|
||||
ui_screen_reload :: proc() {
|
||||
using state := get_state()
|
||||
using screen_ui.settings_menu
|
||||
ui_screen_reload :: proc( screen_ui : ^UI_ScreenState ) {
|
||||
|
||||
min_zoom_inputbox.input_str.backing = persistent_slab_allocator()
|
||||
max_zoom_inputbox.input_str.backing = persistent_slab_allocator()
|
||||
{
|
||||
using screen_ui.settings_menu
|
||||
ui_text_input_box_reload( & min_zoom_inputbox, persistent_slab_allocator() )
|
||||
ui_text_input_box_reload( & max_zoom_inputbox, persistent_slab_allocator() )
|
||||
}
|
||||
}
|
||||
|
||||
ui_screen_tick :: proc() {
|
||||
ui_screen_tick :: proc( screen_ui : ^UI_ScreenState ) {
|
||||
profile("Screenspace Imgui")
|
||||
|
||||
using state := get_state()
|
||||
ui_graph_build( & screen_ui )
|
||||
ui := ui_context
|
||||
|
||||
ui_graph_build( screen_ui )
|
||||
ui_floating_manager( & screen_ui.floating )
|
||||
ui_floating("Menu Bar", ui_screen_menu_bar)
|
||||
ui_floating("Settings Menu", ui_screen_settings_menu)
|
||||
ui_floating("Menu Bar", & screen_ui.menu_bar, ui_screen_menu_bar_builder)
|
||||
ui_floating("Settings Menu", & screen_ui.settings_menu, ui_settings_menu_builder)
|
||||
}
|
||||
|
||||
ui_screen_menu_bar :: proc( captures : rawptr = nil ) -> (should_raise : b32 = false )
|
||||
ui_screen_menu_bar_builder :: proc( captures : rawptr = nil ) -> (should_raise : b32 = false )
|
||||
{
|
||||
profile("App Menu Bar")
|
||||
|
||||
menu_bar := cast(^UI_ScreenMenuBar) captures
|
||||
using menu_bar
|
||||
|
||||
theme_app_menu_bar :: proc() -> UI_Theme
|
||||
{
|
||||
@static theme : UI_Theme
|
||||
@ -70,7 +71,7 @@ ui_screen_menu_bar :: proc( captures : rawptr = nil ) -> (should_raise : b32 = f
|
||||
border_color = app_color.border_default,
|
||||
corner_radii = {},
|
||||
blur_size = 0,
|
||||
font = get_state().default_font,
|
||||
font = get_default_font(),
|
||||
text_color = app_color.text_default,
|
||||
cursor = {},
|
||||
}
|
||||
@ -94,10 +95,6 @@ ui_screen_menu_bar :: proc( captures : rawptr = nil ) -> (should_raise : b32 = f
|
||||
return theme
|
||||
}
|
||||
|
||||
using state := get_state()
|
||||
using screen_ui
|
||||
using screen_ui.menu_bar
|
||||
|
||||
scope(theme_app_menu_bar)
|
||||
container = ui_hbox( .Left_To_Right, "Menu Bar" ); {
|
||||
using container
|
||||
@ -114,7 +111,7 @@ ui_screen_menu_bar :: proc( captures : rawptr = nil ) -> (should_raise : b32 = f
|
||||
using move_box
|
||||
layout.size.min.x = 20
|
||||
if active {
|
||||
pos += input.mouse.delta
|
||||
pos += get_input_state().mouse.delta
|
||||
should_raise = true
|
||||
}
|
||||
}
|
||||
@ -130,7 +127,7 @@ ui_screen_menu_bar :: proc( captures : rawptr = nil ) -> (should_raise : b32 = f
|
||||
text = str_intern("Settings")
|
||||
layout.flags = { .Scale_Width_By_Height_Ratio }
|
||||
layout.size.ratio.x = 2.0
|
||||
if pressed do screen_ui.settings_menu.is_open = true
|
||||
if pressed do ui_settings_menu_open()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -19,12 +19,10 @@ UI_SettingsMenu :: struct
|
||||
is_maximized : b32,
|
||||
}
|
||||
|
||||
ui_screen_settings_menu :: proc( captures : rawptr = nil ) -> ( should_raise : b32 = false)
|
||||
ui_settings_menu_builder :: proc( captures : rawptr = nil ) -> ( should_raise : b32 = false)
|
||||
{
|
||||
profile("Settings Menu")
|
||||
state := get_state()
|
||||
using state
|
||||
using screen_ui
|
||||
settings_menu := cast(^UI_SettingsMenu) captures
|
||||
|
||||
if ! settings_menu.is_open do return
|
||||
app_color := app_color_theme()
|
||||
@ -59,7 +57,7 @@ ui_screen_settings_menu :: proc( captures : rawptr = nil ) -> ( should_raise : b
|
||||
dragged := ui_resizable_handles( & container, & pos, & size)
|
||||
should_raise |= dragged
|
||||
|
||||
old_vbox := ui_box_from_key(prev_cache, ui_key_from_string("Settings Menu: VBox"))
|
||||
old_vbox := ui_box_from_key(get_ui_context_mut().prev_cache, ui_key_from_string("Settings Menu: VBox"))
|
||||
if old_vbox != nil
|
||||
{
|
||||
vbox_children_bounds := ui_compute_children_overall_bounds(old_vbox)
|
||||
@ -116,17 +114,17 @@ ui_screen_settings_menu :: proc( captures : rawptr = nil ) -> ( should_raise : b
|
||||
}
|
||||
}
|
||||
if frame_bar.active {
|
||||
pos += input.mouse.delta
|
||||
pos += get_input_state().mouse.delta
|
||||
should_raise = true
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(Ed): This will eventually be most likely generalized/compressed. For now its the main scope for implementing new widgets.
|
||||
app_config := ui_drop_down( & cfg_drop_down, "settings_menu.config", str_intern("App Config"), vb_compute_layout = true);
|
||||
dd_app_config := ui_drop_down( & cfg_drop_down, "settings_menu.config", str_intern("App Config"), vb_compute_layout = true);
|
||||
app_config_closed:
|
||||
{
|
||||
app_config.title.layout.font_size = 12
|
||||
if ! app_config.is_open do break app_config_closed
|
||||
dd_app_config.title.layout.font_size = 12
|
||||
if ! dd_app_config.is_open do break app_config_closed
|
||||
|
||||
ui_settings_entry_inputbox :: proc( input_box : ^UI_TextInputBox, is_even : bool, label : string, setting_title : StrRunesPair, input_policy : UI_TextInput_Policy )
|
||||
{
|
||||
@ -158,6 +156,8 @@ ui_screen_settings_menu :: proc( captures : rawptr = nil ) -> ( should_raise : b
|
||||
}
|
||||
}
|
||||
|
||||
config := app_config()
|
||||
|
||||
Engine_Refresh_Hz:
|
||||
{
|
||||
scope(theme_table_row(is_even = false))
|
||||
@ -344,7 +344,7 @@ ui_screen_settings_menu :: proc( captures : rawptr = nil ) -> ( should_raise : b
|
||||
idx := 1
|
||||
for entry in CameraZoomMode
|
||||
{
|
||||
ui_parent(app_config.vbox)
|
||||
ui_parent(dd_app_config.vbox)
|
||||
scope(theme_button)
|
||||
btn := ui_button(str_intern_fmt("settings_menu.cam_zoom_mode.%s.btn", entry).str)
|
||||
{
|
||||
@ -361,9 +361,9 @@ ui_screen_settings_menu :: proc( captures : rawptr = nil ) -> ( should_raise : b
|
||||
}
|
||||
|
||||
if btn.pressed {
|
||||
mode_selector.should_close = true
|
||||
config.cam_zoom_mode = entry
|
||||
screen_ui.active = 0
|
||||
mode_selector.should_close = true
|
||||
config.cam_zoom_mode = entry
|
||||
get_ui_context_mut().active = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -549,3 +549,7 @@ ui_screen_settings_menu :: proc( captures : rawptr = nil ) -> ( should_raise : b
|
||||
ui_parent_pop() // container
|
||||
return
|
||||
}
|
||||
|
||||
ui_settings_menu_open :: #force_inline proc "contextless" () {
|
||||
get_state().screen_ui.settings_menu.is_open = true
|
||||
}
|
||||
|
@ -274,18 +274,21 @@ get_state :: #force_inline proc "contextless" () -> ^ State {
|
||||
return cast( ^ State ) Memory_App.persistent.reserve_start
|
||||
}
|
||||
|
||||
|
||||
get_input_state :: #force_inline proc "contextless" () -> InputState {
|
||||
return (get_state().input ^)
|
||||
}
|
||||
|
||||
frametime_delta32 :: #force_inline proc "contextless" () -> f32 {
|
||||
return cast(f32) get_state().frametime.delta_ms
|
||||
}
|
||||
|
||||
app_config :: #force_inline proc "contextless" () -> AppConfig { return get_state().config }
|
||||
app_color_theme :: #force_inline proc "contextless" () -> AppColorTheme { return get_state().config.color_theme }
|
||||
debug_data :: #force_inline proc "contextless" () -> DebugData { return get_state().debug }
|
||||
get_frametime :: #force_inline proc "contextless" () -> FrameTime { return get_state().frametime }
|
||||
app_config :: #force_inline proc "contextless" () -> AppConfig { return get_state().config }
|
||||
app_color_theme :: #force_inline proc "contextless" () -> AppColorTheme { return get_state().config.color_theme }
|
||||
debug_data :: #force_inline proc "contextless" () -> DebugData { return get_state().debug }
|
||||
get_frametime :: #force_inline proc "contextless" () -> FrameTime { return get_state().frametime }
|
||||
get_default_font :: #force_inline proc "contextless" () -> FontID { return get_state().default_font }
|
||||
get_input_state :: #force_inline proc "contextless" () -> InputState { return (get_state().input ^) }
|
||||
|
||||
get_ui_context_mut :: #force_inline proc "contextless" () -> ^UI_State { return get_state().ui_context }
|
||||
|
||||
set_ui_context :: #force_inline proc "contextless" ( ui : ^UI_State ) {
|
||||
get_state().ui_context = ui
|
||||
}
|
||||
|
||||
#endregion("State")
|
||||
|
@ -302,7 +302,7 @@ update :: proc( delta_time : f64 ) -> b32
|
||||
|
||||
// TODO(Ed): We need input buffer so that we can consume input actions based on the UI with priority
|
||||
|
||||
ui_screen_tick()
|
||||
ui_screen_tick( & get_state().screen_ui )
|
||||
|
||||
//region WorkspaceImgui Tick
|
||||
if true
|
||||
|
@ -34,7 +34,7 @@ theme_button :: proc() -> UI_Theme
|
||||
border_color = app_color.border_default,
|
||||
corner_radii = {},
|
||||
blur_size = 0,
|
||||
font = get_state().default_font,
|
||||
font = get_default_font(),
|
||||
text_color = app_color.text_default,
|
||||
cursor = {},
|
||||
}
|
||||
@ -83,7 +83,7 @@ theme_drop_down_btn :: proc() -> UI_Theme
|
||||
border_color = app_color.border_default,
|
||||
corner_radii = {},
|
||||
blur_size = 0,
|
||||
font = get_state().default_font,
|
||||
font = get_default_font(),
|
||||
text_color = app_color.text_default,
|
||||
cursor = {},
|
||||
}
|
||||
@ -140,7 +140,7 @@ theme_table_row :: proc( is_even : bool ) -> UI_Theme
|
||||
border_color = Color_Transparent,
|
||||
corner_radii = {},
|
||||
blur_size = 0,
|
||||
font = get_state().default_font,
|
||||
font = get_default_font(),
|
||||
text_color = app_color_theme().text_default,
|
||||
cursor = {},
|
||||
}
|
||||
@ -188,7 +188,7 @@ theme_window_bar :: proc() -> UI_Theme
|
||||
border_color = Color_Transparent,
|
||||
corner_radii = {0, 0, 0, 0 },
|
||||
blur_size = 0,
|
||||
font = get_state().default_font,
|
||||
font = get_default_font(),
|
||||
text_color = app_color.text_default,
|
||||
cursor = {},
|
||||
}
|
||||
@ -240,7 +240,7 @@ theme_window_bar_title :: proc() -> UI_Theme
|
||||
border_color = Color_Transparent,
|
||||
corner_radii = {0, 0, 0, 0},
|
||||
blur_size = 0,
|
||||
font = get_state().default_font,
|
||||
font = get_default_font(),
|
||||
text_color = app_color.text_default,
|
||||
cursor = {},
|
||||
}
|
||||
@ -288,7 +288,7 @@ theme_window_bar_btn :: proc() -> UI_Theme
|
||||
border_color = app_color.border_default,
|
||||
corner_radii = {},
|
||||
blur_size = 0,
|
||||
font = get_state().default_font,
|
||||
font = get_default_font(),
|
||||
text_color = app_color.text_default,
|
||||
cursor = {},
|
||||
}
|
||||
@ -337,7 +337,7 @@ theme_window_panel :: proc() -> UI_Theme
|
||||
border_color = app_color.window_panel_border,
|
||||
corner_radii = { 0, 0, 0, 0 },
|
||||
blur_size = 0,
|
||||
font = get_state().default_font,
|
||||
font = get_default_font(),
|
||||
text_color = app_color.text_default,
|
||||
cursor = {},
|
||||
}
|
||||
@ -385,7 +385,7 @@ theme_transparent :: proc() -> UI_Theme
|
||||
border_color = Color_Transparent,
|
||||
corner_radii = {},
|
||||
blur_size = 0,
|
||||
font = get_state().default_font,
|
||||
font = get_default_font(),
|
||||
text_color = app_color.text_default,
|
||||
cursor = {},
|
||||
}
|
||||
@ -433,7 +433,7 @@ theme_text :: proc() -> UI_Theme
|
||||
border_color = Color_Transparent,
|
||||
corner_radii = {},
|
||||
blur_size = 0,
|
||||
font = get_state().default_font,
|
||||
font = get_default_font(),
|
||||
text_color = app_color.text_default,
|
||||
cursor = {},
|
||||
}
|
||||
|
@ -581,6 +581,10 @@ UI_TextInputBox :: struct {
|
||||
using policy : UI_TextInput_Policy,
|
||||
}
|
||||
|
||||
ui_text_input_box_reload :: #force_inline proc ( text_box : ^UI_TextInputBox, allocator : Allocator ) {
|
||||
text_box.input_str.backing = allocator
|
||||
}
|
||||
|
||||
ui_text_input_box :: proc( text_input_box : ^UI_TextInputBox, label : string,
|
||||
flags : UI_BoxFlags = {.Mouse_Clickable, .Focusable, .Click_To_Focus},
|
||||
allocator := context.allocator,
|
||||
|
Loading…
Reference in New Issue
Block a user