small refactors for organization
This commit is contained in:
parent
2b1565e35b
commit
e40e3ddf85
@ -192,9 +192,9 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
|
||||
|
||||
// Setup the app ui state
|
||||
{
|
||||
ui_startup( & app_ui.base, cache_allocator = persistent_slab_allocator() )
|
||||
ui_startup( & screen_ui.base, cache_allocator = persistent_slab_allocator() )
|
||||
|
||||
using app_ui
|
||||
using screen_ui
|
||||
menu_bar.pos = Vec2(app_window.extent) * { -1, 1 }
|
||||
menu_bar.size = {200, 40}
|
||||
|
||||
|
@ -177,7 +177,7 @@ State :: struct {
|
||||
|
||||
config : AppConfig,
|
||||
app_window : AppWindow,
|
||||
app_ui : App_UI_State,
|
||||
screen_ui : UI_ScreenState,
|
||||
|
||||
monitor_id : i32,
|
||||
monitor_refresh_hz : i32,
|
||||
|
@ -348,7 +348,7 @@ poll_input :: proc( old, new : ^ InputState )
|
||||
}
|
||||
|
||||
new.mouse.raw_pos = rl.GetMousePosition()
|
||||
new.mouse.pos = render_to_surface_pos(new.mouse.raw_pos)
|
||||
new.mouse.pos = render_to_screen_pos(new.mouse.raw_pos)
|
||||
new.mouse.delta = rl.GetMouseDelta() * {1, -1}
|
||||
new.mouse.vertical_wheel = rl.GetMouseWheelMove()
|
||||
}
|
||||
|
@ -140,9 +140,9 @@ screen_size :: proc "contextless" () -> AreaSize {
|
||||
|
||||
screen_get_bounds :: #force_inline proc "contextless" () -> Range2 {
|
||||
state := get_state(); using state
|
||||
surface_extent := state.app_window.extent
|
||||
bottom_left := Vec2 { -surface_extent.x, -surface_extent.y}
|
||||
top_right := Vec2 { surface_extent.x, surface_extent.y}
|
||||
screen_extent := state.app_window.extent
|
||||
bottom_left := Vec2 { -screen_extent.x, -screen_extent.y}
|
||||
top_right := Vec2 { screen_extent.x, screen_extent.y}
|
||||
return range2( bottom_left, top_right )
|
||||
}
|
||||
|
||||
@ -180,7 +180,7 @@ view_get_corners :: #force_inline proc "contextless"() -> BoundsCorners2 {
|
||||
return { top_left, top_right, bottom_left, bottom_right }
|
||||
}
|
||||
|
||||
render_to_surface_pos :: #force_inline proc "contextless" (pos : Vec2) -> Vec2 {
|
||||
render_to_screen_pos :: #force_inline proc "contextless" (pos : Vec2) -> Vec2 {
|
||||
extent := & get_state().app_window.extent
|
||||
result := Vec2 {
|
||||
pos.x - extent.x,
|
||||
@ -193,15 +193,15 @@ render_to_ws_view_pos :: #force_inline proc "contextless" (pos : Vec2) -> Vec2 {
|
||||
return {}
|
||||
}
|
||||
|
||||
surface_to_ws_view_pos :: #force_inline proc "contextless" (pos: Vec2) -> Vec2 {
|
||||
screen_to_ws_view_pos :: #force_inline proc "contextless" (pos: Vec2) -> Vec2 {
|
||||
state := get_state(); using state
|
||||
cam := & project.workspace.cam
|
||||
result := Vec2 { cam.target.x, -cam.target.y} + Vec2 { pos.x, pos.y } * (1 / cam.zoom)
|
||||
return result
|
||||
}
|
||||
|
||||
// (Surface) Centered screen space to conventional screen space used for rendering
|
||||
surface_to_render_pos :: #force_inline proc "contextless" (pos : Vec2) -> Vec2 {
|
||||
// Centered screen space to conventional screen space used for rendering
|
||||
screen_to_render_pos :: #force_inline proc "contextless" (pos : Vec2) -> Vec2 {
|
||||
screen_extent := transmute(Vec2) get_state().app_window.extent
|
||||
return pos * {1, -1} + { screen_extent.x, screen_extent.y }
|
||||
}
|
||||
@ -216,9 +216,9 @@ ws_view_extent :: #force_inline proc "contextless"() -> Extents2 {
|
||||
return app_window.extent * cam_zoom_ratio
|
||||
}
|
||||
|
||||
// Workspace view to surface space position
|
||||
// Workspace view to screen space position
|
||||
// TODO(Ed): Support a position which would not be centered on the screen if in a viewport
|
||||
ws_view_to_surface_pos :: #force_inline proc "contextless"(position: Vec2) -> Vec2 {
|
||||
ws_view_to_screen_pos :: #force_inline proc "contextless"(position: Vec2) -> Vec2 {
|
||||
return position
|
||||
}
|
||||
|
||||
@ -226,9 +226,9 @@ ws_view_to_render_pos :: #force_inline proc "contextless"(position: Vec2) -> Vec
|
||||
return { position.x, position.y * -1 }
|
||||
}
|
||||
|
||||
// Workspace view to surface space position (zoom agnostic)
|
||||
// Workspace view to screen space position (zoom agnostic)
|
||||
// TODO(Ed): Support a position which would not be centered on the screen if in a viewport
|
||||
ws_view_to_surface_pos_no_zoom :: #force_inline proc "contextless"(position: Vec2) -> Vec2 {
|
||||
ws_view_to_screen_pos_no_zoom :: #force_inline proc "contextless"(position: Vec2) -> Vec2 {
|
||||
state := get_state(); using state
|
||||
cam_zoom_ratio := 1.0 / state.project.workspace.cam.zoom
|
||||
return { position.x, position.y } * cam_zoom_ratio
|
||||
|
@ -21,7 +21,7 @@ debug_draw_text :: proc( content : string, pos : Vec2, size : f32, color : rl.Co
|
||||
// if ( len(font) == 0 ) {
|
||||
font = default_font
|
||||
}
|
||||
pos := surface_to_render_pos(pos)
|
||||
pos := screen_to_render_pos(pos)
|
||||
|
||||
px_size := size
|
||||
|
||||
|
@ -203,7 +203,7 @@ render_mode_2d_workspace :: proc()
|
||||
|
||||
|
||||
if debug.mouse_vis {
|
||||
cursor_world_pos := surface_to_ws_view_pos(input.mouse.pos)
|
||||
cursor_world_pos := screen_to_ws_view_pos(input.mouse.pos)
|
||||
rl.DrawCircleV( ws_view_to_render_pos(cursor_world_pos), 5, Color_GreyRed )
|
||||
}
|
||||
|
||||
@ -271,10 +271,10 @@ render_mode_screenspace :: proc ()
|
||||
debug_text("Mouse Vertical Wheel: %v", input.mouse.vertical_wheel )
|
||||
debug_text("Mouse Delta : %v", input.mouse.delta )
|
||||
debug_text("Mouse Position (Render) : %v", input.mouse.raw_pos )
|
||||
debug_text("Mouse Position (Surface) : %v", input.mouse.pos )
|
||||
debug_text("Mouse Position (Workspace View): %v", surface_to_ws_view_pos(input.mouse.pos) )
|
||||
debug_text("Mouse Position (Screen) : %v", input.mouse.pos )
|
||||
debug_text("Mouse Position (Workspace View): %v", screen_to_ws_view_pos(input.mouse.pos) )
|
||||
rl.DrawCircleV( input.mouse.raw_pos, 10, Color_White_A125 )
|
||||
rl.DrawCircleV( surface_to_render_pos(input.mouse.pos), 2, Color_BG )
|
||||
rl.DrawCircleV( screen_to_render_pos(input.mouse.pos), 2, Color_BG )
|
||||
}
|
||||
|
||||
ui := & project.workspace.ui
|
||||
@ -291,7 +291,7 @@ render_mode_screenspace :: proc ()
|
||||
debug_text("Workspace Active Box: %v", active_box.label.str )
|
||||
}
|
||||
|
||||
ui = & app_ui
|
||||
ui = & screen_ui
|
||||
|
||||
debug_text("Box Count: %v", ui.built_box_count )
|
||||
|
||||
@ -324,7 +324,7 @@ render_app_ui :: proc()
|
||||
Render_App_UI:
|
||||
{
|
||||
profile("App UI")
|
||||
ui := & state.app_ui
|
||||
ui := & state.screen_ui
|
||||
state.ui_context = ui
|
||||
root := ui.root
|
||||
if root.num_children == 0 {
|
||||
@ -343,24 +343,24 @@ render_app_ui :: proc()
|
||||
computed_size := computed.bounds.p1 - computed.bounds.p0
|
||||
|
||||
render_anchors := range2(
|
||||
surface_to_render_pos(computed.anchors.min),
|
||||
surface_to_render_pos(computed.anchors.max),
|
||||
screen_to_render_pos(computed.anchors.min),
|
||||
screen_to_render_pos(computed.anchors.max),
|
||||
)
|
||||
render_margins := range2(
|
||||
surface_to_render_pos(computed.margins.min),
|
||||
surface_to_render_pos(computed.margins.max),
|
||||
screen_to_render_pos(computed.margins.min),
|
||||
screen_to_render_pos(computed.margins.max),
|
||||
)
|
||||
render_bounds := range2(
|
||||
surface_to_render_pos(computed.bounds.min),
|
||||
surface_to_render_pos(computed.bounds.max),
|
||||
screen_to_render_pos(computed.bounds.min),
|
||||
screen_to_render_pos(computed.bounds.max),
|
||||
)
|
||||
render_padding := range2(
|
||||
surface_to_render_pos(computed.padding.min),
|
||||
surface_to_render_pos(computed.padding.max),
|
||||
screen_to_render_pos(computed.padding.min),
|
||||
screen_to_render_pos(computed.padding.max),
|
||||
)
|
||||
render_content := range2(
|
||||
surface_to_render_pos(computed.content.min),
|
||||
surface_to_render_pos(computed.content.max),
|
||||
screen_to_render_pos(computed.content.min),
|
||||
screen_to_render_pos(computed.content.max),
|
||||
)
|
||||
rect_anchors := range2_to_rl_rect( render_anchors )
|
||||
rect_margins := range2_to_rl_rect( render_margins )
|
||||
@ -426,7 +426,7 @@ render_app_ui :: proc()
|
||||
// profile_end()
|
||||
|
||||
if len(current.text.str) > 0 && style.font.key != 0 {
|
||||
draw_text_screenspace( current.text, surface_to_render_pos(computed.text_pos), style.layout.font_size, style.text_color )
|
||||
draw_text_screenspace( current.text, screen_to_render_pos(computed.text_pos), style.layout.font_size, style.text_color )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -193,16 +193,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
|
||||
|
||||
//region App UI Tick
|
||||
{
|
||||
profile("App Screenspace Imgui")
|
||||
|
||||
ui_graph_build( & state.app_ui )
|
||||
ui := ui_context
|
||||
|
||||
ui_app_menu_bar()
|
||||
}
|
||||
//endregion App UI Tick
|
||||
ui_screen_tick()
|
||||
|
||||
//region WorkspaceImgui Tick
|
||||
{
|
||||
|
@ -294,7 +294,7 @@ ui_box_tranverse_next :: proc "contextless" ( box : ^ UI_Box ) -> (^ UI_Box)
|
||||
using state := get_state()
|
||||
if box.first != nil
|
||||
{
|
||||
is_app_ui := ui_context == & app_ui
|
||||
is_app_ui := ui_context == & screen_ui
|
||||
if is_app_ui || intersects_range2( view_get_bounds(), box.computed.bounds)
|
||||
{
|
||||
return box.first
|
||||
@ -316,7 +316,7 @@ ui_box_tranverse_next :: proc "contextless" ( box : ^ UI_Box ) -> (^ UI_Box)
|
||||
ui_cursor_pos :: #force_inline proc "contextless" () -> Vec2 {
|
||||
using state := get_state()
|
||||
if ui_context == & state.project.workspace.ui {
|
||||
return surface_to_ws_view_pos( input.mouse.pos )
|
||||
return screen_to_ws_view_pos( input.mouse.pos )
|
||||
}
|
||||
else {
|
||||
return input.mouse.pos
|
||||
@ -325,7 +325,7 @@ ui_cursor_pos :: #force_inline proc "contextless" () -> Vec2 {
|
||||
|
||||
ui_ws_drag_delta :: #force_inline proc "contextless" () -> Vec2 {
|
||||
using state := get_state()
|
||||
return surface_to_ws_view_pos(input.mouse.pos) - state.ui_context.active_start_signal.cursor_pos
|
||||
return screen_to_ws_view_pos(input.mouse.pos) - state.ui_context.active_start_signal.cursor_pos
|
||||
}
|
||||
|
||||
ui_graph_build_begin :: proc( ui : ^ UI_State, bounds : Vec2 = {} )
|
||||
|
@ -1,6 +1,6 @@
|
||||
package sectr
|
||||
|
||||
App_UI_State :: struct
|
||||
UI_ScreenState :: struct
|
||||
{
|
||||
using base : UI_State,
|
||||
menu_bar : struct
|
||||
@ -20,13 +20,24 @@ App_UI_State :: struct
|
||||
},
|
||||
}
|
||||
|
||||
ui_screen_tick :: proc() {
|
||||
profile("Screenspace Imgui")
|
||||
|
||||
using state := get_state()
|
||||
ui_graph_build( & screen_ui )
|
||||
ui := ui_context
|
||||
|
||||
ui_app_menu_bar()
|
||||
ui_app_settings_menu()
|
||||
}
|
||||
|
||||
ui_app_menu_bar :: proc()
|
||||
{
|
||||
profile("App Menu Bar")
|
||||
fmt :: str_fmt_alloc
|
||||
|
||||
using state := get_state()
|
||||
using app_ui
|
||||
using screen_ui
|
||||
{
|
||||
using menu_bar
|
||||
ui_theme_via_style({
|
||||
@ -91,26 +102,19 @@ ui_app_menu_bar :: proc()
|
||||
spacer.style.anchor.ratio.x = 1.0
|
||||
// spacer.style.bg_color = Color_Red
|
||||
}
|
||||
|
||||
ui_app_settings_menu()
|
||||
}
|
||||
|
||||
ui_app_settings_menu :: proc()
|
||||
{
|
||||
profile("Settings Menu")
|
||||
using state := get_state()
|
||||
using state.app_ui
|
||||
if menu_bar.settings_btn.pressed || ! menu_bar.settings_btn.is_open {
|
||||
return
|
||||
}
|
||||
using state.screen_ui
|
||||
if menu_bar.settings_btn.pressed || ! menu_bar.settings_btn.is_open do return
|
||||
|
||||
using settings_menu
|
||||
if size.x < min_size.x {
|
||||
size.x = min_size.x
|
||||
}
|
||||
if size.y < min_size.y {
|
||||
size.y = min_size.y
|
||||
}
|
||||
if size.x < min_size.x do size.x = min_size.x
|
||||
if size.y < min_size.y do size.y = min_size.y
|
||||
|
||||
container = ui_vbox_begin( .Top_To_Bottom, "Settings Menu", {.Mouse_Clickable})
|
||||
{
|
||||
using container
|
||||
@ -133,11 +137,10 @@ ui_app_settings_menu :: proc()
|
||||
ui_style_theme_ref().hot.bg_color = Color_Blue
|
||||
frame_bar := ui_hbox_begin(.Left_To_Right, "Settings Menu: Frame Bar", { .Mouse_Clickable, .Focusable, .Click_To_Focus })
|
||||
{
|
||||
frame_bar.style.bg_color = Color_BG_Panel
|
||||
frame_bar.style.flags = {.Fixed_Height}
|
||||
frame_bar.style.alignment = { 0, 0 }
|
||||
// frame_bar.style.anchor.ratio.y = 0.25
|
||||
frame_bar.style.size.min.y = 50
|
||||
frame_bar.style.bg_color = Color_BG_Panel
|
||||
frame_bar.style.flags = {.Fixed_Height}
|
||||
frame_bar.style.alignment = { 0, 0 }
|
||||
frame_bar.style.size.min.y = 50
|
||||
if frame_bar.active {
|
||||
pos += input.mouse.delta
|
||||
}
|
||||
@ -146,7 +149,6 @@ ui_app_settings_menu :: proc()
|
||||
title := ui_text("Settings Menu: Title", str_intern("Settings Menu"), {.Disabled})
|
||||
{
|
||||
using title
|
||||
// style.alignment = {0, 1}
|
||||
style.margins = { 0, 0, 15, 0}
|
||||
style.text_alignment = {0 , 0.5}
|
||||
style.anchor.ratio.x = 1.0
|
||||
@ -160,11 +162,8 @@ ui_app_settings_menu :: proc()
|
||||
{
|
||||
using close_btn
|
||||
text = str_intern("close")
|
||||
style.flags = {.Fixed_Width}
|
||||
// style.bg_color = Color_GreyRed
|
||||
style.flags = {.Fixed_Width}
|
||||
style.size.min = {50, 0}
|
||||
// style.anchor = range2( {1.0, 0}, {})
|
||||
// style.alignment = {0, 0}
|
||||
style.text_alignment = {0.5, 0.5}
|
||||
style.anchor.ratio.x = 1.0
|
||||
if close_btn.pressed {
|
Loading…
Reference in New Issue
Block a user