2024-02-12 17:52:56 -08:00
|
|
|
package sectr
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
import "base:runtime"
|
|
|
|
|
2024-02-12 17:52:56 -08:00
|
|
|
// TODO(Ed) : This is in Raddbg base_types.h, consider moving outside of UI.
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
Corner :: enum i32 {
|
|
|
|
Invalid = -1,
|
|
|
|
_00,
|
|
|
|
_01,
|
|
|
|
_10,
|
|
|
|
_11,
|
|
|
|
TopLeft = _00,
|
|
|
|
TopRight = _01,
|
|
|
|
BottomLeft = _10,
|
|
|
|
BottomRight = _11,
|
|
|
|
Count = 4,
|
2024-02-13 23:27:40 -08:00
|
|
|
}
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
Side :: enum i32 {
|
|
|
|
Invalid = -1,
|
|
|
|
Min = 0,
|
|
|
|
Max = 1,
|
|
|
|
Count
|
|
|
|
}
|
|
|
|
|
|
|
|
// Side2 :: enum u32 {
|
|
|
|
// Top,
|
|
|
|
// Bottom,
|
|
|
|
// Left,
|
|
|
|
// Right,
|
|
|
|
// Count,
|
|
|
|
// }
|
|
|
|
|
|
|
|
UI_AnchorPresets :: enum u32 {
|
|
|
|
Top_Left,
|
|
|
|
Top_Right,
|
|
|
|
Bottom_Right,
|
|
|
|
Bottom_Left,
|
|
|
|
Center_Left,
|
|
|
|
Center_Top,
|
|
|
|
Center_Right,
|
|
|
|
Center_Bottom,
|
|
|
|
Center,
|
|
|
|
Left_Wide,
|
|
|
|
Top_Wide,
|
|
|
|
Right_Wide,
|
|
|
|
Bottom_Wide,
|
|
|
|
VCenter_Wide,
|
|
|
|
HCenter_Wide,
|
|
|
|
Full,
|
2024-02-13 23:27:40 -08:00
|
|
|
Count,
|
|
|
|
}
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
UI_BoxFlag :: enum u64 {
|
2024-03-02 07:24:09 -08:00
|
|
|
Disabled,
|
2024-03-13 21:00:22 -07:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
Focusable,
|
2024-03-09 10:55:47 -08:00
|
|
|
Click_To_Focus,
|
2024-02-13 23:27:40 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
Mouse_Clickable,
|
2024-03-09 10:55:47 -08:00
|
|
|
Mouse_Resizable,
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
Keyboard_Clickable,
|
2024-02-13 23:27:40 -08:00
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
Scroll_X,
|
|
|
|
Scroll_Y,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
Pan_X,
|
|
|
|
Pan_Y,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
Count,
|
2024-02-12 17:52:56 -08:00
|
|
|
}
|
2024-02-22 18:19:29 -08:00
|
|
|
UI_BoxFlags :: bit_set[UI_BoxFlag; u64]
|
2024-03-02 07:24:09 -08:00
|
|
|
UI_BoxFlag_Scroll :: UI_BoxFlags { .Scroll_X, .Scroll_Y }
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
// The UI_Box's actual positioning and sizing
|
|
|
|
// There is an excess of rectangles here for debug puproses.
|
|
|
|
UI_Computed :: struct {
|
2024-03-09 07:21:48 -08:00
|
|
|
bounds : Range2,
|
|
|
|
padding : Range2,
|
|
|
|
content : Range2,
|
|
|
|
text_pos : Vec2,
|
|
|
|
text_size : Vec2,
|
2024-02-12 17:52:56 -08:00
|
|
|
}
|
|
|
|
|
2024-03-09 07:21:48 -08:00
|
|
|
UI_LayoutSide :: struct {
|
|
|
|
// using _ : struct {
|
2024-03-02 07:24:09 -08:00
|
|
|
top, bottom : UI_Scalar,
|
|
|
|
left, right : UI_Scalar,
|
2024-03-09 07:21:48 -08:00
|
|
|
// }
|
2024-02-12 17:52:56 -08:00
|
|
|
}
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
UI_Cursor :: struct {
|
|
|
|
placeholder : int,
|
2024-02-12 17:52:56 -08:00
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
UI_FramePassKind :: enum {
|
|
|
|
Generate,
|
|
|
|
Compute,
|
|
|
|
Logical,
|
|
|
|
}
|
|
|
|
|
|
|
|
UI_InteractState :: struct {
|
|
|
|
hot_time : f32,
|
|
|
|
active_time : f32,
|
|
|
|
disabled_time : f32,
|
|
|
|
}
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
UI_Key :: distinct u64
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
UI_Scalar :: f32
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
// TODO(Ed): I'm not sure if Percentage is needed or if this would over complicate things...
|
|
|
|
// UI_Scalar :: struct {
|
|
|
|
// VPixels : f32,
|
|
|
|
// Percentage : f32,
|
|
|
|
// }
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
UI_ScalarConstraint :: struct {
|
|
|
|
min, max : UI_Scalar,
|
|
|
|
}
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
UI_Scalar2 :: [Axis2.Count]UI_Scalar
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
// Desiered constraints on the UI_Box.
|
|
|
|
UI_Layout :: struct {
|
2024-03-02 07:24:09 -08:00
|
|
|
// TODO(Ed) : Should layout have its own flags (separate from the style flags)
|
|
|
|
// flags : UI_LayoutFlags
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
// TODO(Ed) : Make sure this is all we need to represent an anchor.
|
2024-03-09 07:21:48 -08:00
|
|
|
anchor : Range2,
|
|
|
|
alignment : Vec2,
|
|
|
|
text_alignment : Vec2,
|
2024-02-13 14:16:39 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
border_width : UI_Scalar,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
margins : UI_LayoutSide,
|
|
|
|
padding : UI_LayoutSide,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-03-13 21:00:22 -07:00
|
|
|
// TODO(Ed): We cannot support individual corners unless we add it to raylib (or finally change the rendering backend)
|
2024-02-22 18:19:29 -08:00
|
|
|
corner_radii : [Corner.Count]f32,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
// Position in relative coordinate space.
|
|
|
|
// If the box's flags has Fixed_Position, then this will be its aboslute position in the relative coordinate space
|
|
|
|
pos : Vec2,
|
|
|
|
|
2024-03-12 17:55:29 -07:00
|
|
|
// TODO(Ed): Support a min/max range for the size of a box
|
2024-03-13 21:00:22 -07:00
|
|
|
size : Range2,
|
2024-03-10 23:05:18 -07:00
|
|
|
|
2024-03-13 21:00:22 -07:00
|
|
|
// TODO(Ed) : Should thsi just always be WS_Pos for workspace UI?
|
|
|
|
// (We can union either varient and just know based on checking if its the screenspace UI)
|
2024-03-02 07:24:09 -08:00
|
|
|
// If the box is a child of the root parent, its automatically in world space and thus will use the tile_pos.
|
2024-03-13 21:00:22 -07:00
|
|
|
// tile_pos : WS_Pos,
|
2024-02-27 04:50:57 -08:00
|
|
|
}
|
2024-02-22 20:15:29 -08:00
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
UI_Signal :: struct {
|
|
|
|
cursor_pos : Vec2,
|
|
|
|
drag_delta : Vec2,
|
|
|
|
scroll : Vec2,
|
|
|
|
|
|
|
|
left_clicked : b8,
|
|
|
|
right_clicked : b8,
|
|
|
|
double_clicked : b8,
|
|
|
|
keyboard_clicked : b8,
|
|
|
|
|
|
|
|
pressed : b8,
|
|
|
|
released : b8,
|
|
|
|
dragging : b8,
|
2024-03-08 00:34:21 -08:00
|
|
|
resizing : b8,
|
2024-03-02 07:24:09 -08:00
|
|
|
cursor_over : b8,
|
|
|
|
commit : b8,
|
|
|
|
}
|
|
|
|
|
|
|
|
UI_StyleFlag :: enum u32 {
|
2024-03-13 21:00:22 -07:00
|
|
|
|
|
|
|
// Will perform scissor pass on children to their parent's bounds
|
|
|
|
// (Specified in the parent)
|
|
|
|
Clip_Children_To_Bounds,
|
|
|
|
|
|
|
|
// Enforces the widget will always remain in a specific position relative to the parent.
|
|
|
|
// Overriding the anchors and margins.
|
2024-03-02 07:24:09 -08:00
|
|
|
Fixed_Position_X,
|
|
|
|
Fixed_Position_Y,
|
2024-03-13 21:00:22 -07:00
|
|
|
|
|
|
|
// Enroces the widget will maintain its size reguardless of any constraints
|
|
|
|
// Will override parent constraints
|
2024-03-02 07:24:09 -08:00
|
|
|
Fixed_Width,
|
|
|
|
Fixed_Height,
|
|
|
|
|
2024-03-13 21:00:22 -07:00
|
|
|
Size_To_Text,
|
2024-03-02 07:24:09 -08:00
|
|
|
Text_Wrap,
|
|
|
|
|
|
|
|
Count,
|
|
|
|
}
|
|
|
|
UI_StyleFlags :: bit_set[UI_StyleFlag; u32]
|
|
|
|
|
|
|
|
UI_StylePreset :: enum u32 {
|
2024-02-27 04:50:57 -08:00
|
|
|
Default,
|
2024-03-02 07:24:09 -08:00
|
|
|
Disabled,
|
2024-03-12 17:55:29 -07:00
|
|
|
Hot,
|
|
|
|
Active,
|
2024-03-02 07:24:09 -08:00
|
|
|
Count,
|
2024-02-12 17:52:56 -08:00
|
|
|
}
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
UI_Style :: struct {
|
2024-03-02 07:24:09 -08:00
|
|
|
flags : UI_StyleFlags,
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
bg_color : Color,
|
|
|
|
border_color : Color,
|
|
|
|
|
2024-03-13 21:00:22 -07:00
|
|
|
// TODO(Ed) : Add support for this eventually
|
2024-02-27 04:50:57 -08:00
|
|
|
blur_size : f32,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
font : FontID,
|
2024-03-13 21:00:22 -07:00
|
|
|
// TODO(Ed): Should this get moved to the layout struct? Techncially font-size is mainly
|
2024-02-27 04:50:57 -08:00
|
|
|
font_size : f32,
|
|
|
|
text_color : Color,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
cursor : UI_Cursor,
|
|
|
|
|
2024-03-08 00:34:21 -08:00
|
|
|
using layout : UI_Layout,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-03-13 21:00:22 -07:00
|
|
|
// Used with style, prev_style, and style_delta to produce a simple interpolated animation
|
|
|
|
// Applied in the layout pass & the rendering pass for their associated fields.
|
2024-02-27 04:50:57 -08:00
|
|
|
transition_time : f32,
|
2024-02-12 17:52:56 -08:00
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
UI_StyleTheme :: struct #raw_union {
|
|
|
|
array : [UI_StylePreset.Count] UI_Style,
|
|
|
|
using styles : struct {
|
2024-03-12 17:55:29 -07:00
|
|
|
default, disabled, hot, active : UI_Style,
|
2024-03-02 07:24:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
UI_TextAlign :: enum u32 {
|
|
|
|
Left,
|
|
|
|
Center,
|
|
|
|
Right,
|
|
|
|
Count
|
2024-02-12 17:52:56 -08:00
|
|
|
}
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
UI_Box :: struct {
|
|
|
|
// Cache ID
|
2024-02-22 18:19:29 -08:00
|
|
|
key : UI_Key,
|
2024-03-08 20:20:49 -08:00
|
|
|
// label : string,
|
|
|
|
label : StringCached,
|
|
|
|
text : StringCached,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
// Regenerated per frame.
|
2024-03-02 07:24:09 -08:00
|
|
|
using links : DLL_NodeFull( UI_Box ), // first, last, prev, next
|
2024-03-08 00:34:21 -08:00
|
|
|
parent : ^UI_Box,
|
2024-02-27 04:50:57 -08:00
|
|
|
num_children : i32,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-03-08 15:45:27 -08:00
|
|
|
flags : UI_BoxFlags,
|
|
|
|
computed : UI_Computed,
|
|
|
|
prev_style : UI_Style,
|
|
|
|
style : UI_Style,
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
// Persistent Data
|
2024-03-08 15:45:27 -08:00
|
|
|
first_frame : b8,
|
|
|
|
hot_delta : f32,
|
|
|
|
active_delta : f32,
|
|
|
|
disabled_delta : f32,
|
|
|
|
style_delta : f32,
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
// prev_computed : UI_Computed,
|
2024-02-29 16:37:37 -08:00
|
|
|
// prev_style : UI_Style,v
|
2024-02-27 04:50:57 -08:00
|
|
|
mouse : UI_InteractState,
|
|
|
|
keyboard : UI_InteractState,
|
2024-02-12 17:52:56 -08:00
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
// UI_BoxFlags_Stack_Size :: 512
|
2024-02-27 04:50:57 -08:00
|
|
|
UI_Layout_Stack_Size :: 512
|
|
|
|
UI_Style_Stack_Size :: 512
|
2024-03-12 17:55:29 -07:00
|
|
|
UI_Parent_Stack_Size :: 512
|
|
|
|
UI_Built_Boxes_Array_Size :: Kilobyte * 5
|
2024-02-27 04:50:57 -08:00
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
UI_State :: struct {
|
2024-02-27 04:50:57 -08:00
|
|
|
// TODO(Ed) : Use these
|
|
|
|
build_arenas : [2]Arena,
|
|
|
|
build_arena : ^ Arena,
|
|
|
|
|
|
|
|
built_box_count : i32,
|
|
|
|
|
|
|
|
caches : [2] HMapZPL( UI_Box ),
|
2024-03-08 00:34:21 -08:00
|
|
|
prev_cache : ^HMapZPL( UI_Box ),
|
|
|
|
curr_cache : ^HMapZPL( UI_Box ),
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-03-08 00:34:21 -08:00
|
|
|
null_box : ^UI_Box, // Ryan had this, I don't know why yet.
|
|
|
|
root : ^UI_Box,
|
2024-02-22 20:15:29 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
// Do we need to recompute the layout?
|
2024-02-22 20:15:29 -08:00
|
|
|
layout_dirty : b32,
|
2024-02-22 18:19:29 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
// TODO(Ed) : Look into using a build arena like Ryan does for these possibly (and thus have a linked-list stack)
|
2024-03-08 16:51:46 -08:00
|
|
|
theme_stack : StackFixed( UI_StyleTheme, UI_Style_Stack_Size ),
|
|
|
|
parent_stack : StackFixed( ^UI_Box, UI_Parent_Stack_Size ),
|
2024-03-02 07:24:09 -08:00
|
|
|
// flag_stack : Stack( UI_BoxFlags, UI_BoxFlags_Stack_Size ),
|
2024-02-27 04:50:57 -08:00
|
|
|
|
2024-03-08 00:34:21 -08:00
|
|
|
hot : UI_Key,
|
|
|
|
hot_resizable : b32,
|
2024-03-09 10:55:47 -08:00
|
|
|
hot_start_style : UI_Style,
|
|
|
|
|
|
|
|
active_mouse : [MouseBtn.count] UI_Key,
|
|
|
|
active : UI_Key,
|
|
|
|
active_start_signal : UI_Signal,
|
2024-03-08 00:34:21 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
clipboard_copy : UI_Key,
|
|
|
|
last_clicked : UI_Key,
|
2024-02-22 18:19:29 -08:00
|
|
|
|
2024-03-08 15:45:27 -08:00
|
|
|
active_start_style : UI_Style,
|
2024-02-27 04:50:57 -08:00
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
last_pressed_key : [MouseBtn.count] UI_Key,
|
|
|
|
last_pressed_key_us : [MouseBtn.count] f32,
|
2024-02-22 20:15:29 -08:00
|
|
|
}
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
ui_startup :: proc( ui : ^ UI_State, cache_allocator : Allocator )
|
|
|
|
{
|
2024-02-22 20:15:29 -08:00
|
|
|
ui := ui
|
|
|
|
ui^ = {}
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
for cache in (& ui.caches) {
|
|
|
|
box_cache, allocation_error := zpl_hmap_init_reserve( UI_Box, cache_allocator, UI_Built_Boxes_Array_Size )
|
|
|
|
verify( allocation_error == AllocatorError.None, "Failed to allocate box cache" )
|
|
|
|
cache = box_cache
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.curr_cache = & ui.caches[1]
|
|
|
|
ui.prev_cache = & ui.caches[0]
|
2024-03-12 17:55:29 -07:00
|
|
|
log("ui_startup completed")
|
2024-02-22 20:15:29 -08:00
|
|
|
}
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
ui_reload :: proc( ui : ^ UI_State, cache_allocator : Allocator )
|
|
|
|
{
|
2024-02-22 20:15:29 -08:00
|
|
|
// We need to repopulate Allocator references
|
2024-02-27 04:50:57 -08:00
|
|
|
for cache in & ui.caches {
|
2024-03-11 23:32:16 -07:00
|
|
|
cache.entries.backing = cache_allocator
|
|
|
|
cache.hashes.backing = cache_allocator
|
2024-02-27 04:50:57 -08:00
|
|
|
}
|
2024-02-22 20:15:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(Ed) : Is this even needed?
|
2024-02-27 04:50:57 -08:00
|
|
|
ui_shutdown :: proc() {
|
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
ui_box_equal :: proc( a, b : ^ UI_Box ) -> b32 {
|
|
|
|
BoxSize :: size_of(UI_Box)
|
|
|
|
|
|
|
|
result : b32 = true
|
|
|
|
result &= a.key == b.key // We assume for now the label is the same as the key, if not something is terribly wrong.
|
|
|
|
result &= a.flags == b.flags
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2024-03-10 17:09:04 -07:00
|
|
|
ui_box_from_key :: proc( cache : ^HMapZPL(UI_Box), key : UI_Key ) -> (^UI_Box) {
|
|
|
|
return zpl_hmap_get( cache, cast(u64) key )
|
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
ui_box_make :: proc( flags : UI_BoxFlags, label : string ) -> (^ UI_Box)
|
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
// profile(#procedure)
|
|
|
|
|
2024-03-07 00:10:21 -08:00
|
|
|
using ui := get_state().ui_context
|
2024-03-02 07:24:09 -08:00
|
|
|
|
|
|
|
key := ui_key_from_string( label )
|
|
|
|
|
|
|
|
curr_box : (^ UI_Box)
|
|
|
|
prev_box := zpl_hmap_get( prev_cache, cast(u64) key )
|
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
// profile("Assigning current box")
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
set_result : ^ UI_Box
|
|
|
|
set_error : AllocatorError
|
|
|
|
if prev_box != nil {
|
|
|
|
// Previous history was found, copy over previous state.
|
|
|
|
set_result, set_error = zpl_hmap_set( curr_cache, cast(u64) key, (prev_box ^) )
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
box : UI_Box
|
|
|
|
box.key = key
|
2024-03-08 20:20:49 -08:00
|
|
|
box.label = str_intern( label )
|
2024-03-02 07:24:09 -08:00
|
|
|
set_result, set_error = zpl_hmap_set( curr_cache, cast(u64) key, box )
|
|
|
|
}
|
|
|
|
|
|
|
|
verify( set_error == AllocatorError.None, "Failed to set zpl_hmap due to allocator error" )
|
|
|
|
curr_box = set_result
|
2024-03-08 00:34:21 -08:00
|
|
|
|
|
|
|
curr_box.first_frame = prev_box == nil
|
2024-03-02 07:24:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
curr_box.flags = flags
|
|
|
|
|
|
|
|
// Clear old links
|
|
|
|
curr_box.parent = nil
|
|
|
|
curr_box.links = {}
|
|
|
|
curr_box.num_children = 0
|
|
|
|
|
|
|
|
// If there is a parent, setup the relevant references
|
|
|
|
parent := stack_peek( & parent_stack )
|
|
|
|
if parent != nil
|
|
|
|
{
|
|
|
|
dll_full_push_back( null_box, parent, curr_box )
|
|
|
|
parent.num_children += 1
|
|
|
|
curr_box.parent = parent
|
|
|
|
}
|
|
|
|
|
2024-03-10 17:09:04 -07:00
|
|
|
ui.built_box_count += 1
|
2024-03-02 07:24:09 -08:00
|
|
|
return curr_box
|
|
|
|
}
|
|
|
|
|
2024-03-12 17:55:29 -07:00
|
|
|
ui_box_tranverse_next :: proc "contextless" ( box : ^ UI_Box ) -> (^ UI_Box)
|
2024-03-10 23:05:18 -07:00
|
|
|
{
|
2024-03-02 07:24:09 -08:00
|
|
|
// If current has children, do them first
|
|
|
|
if box.first != nil {
|
|
|
|
return box.first
|
|
|
|
}
|
|
|
|
|
|
|
|
if box.next == nil
|
|
|
|
{
|
|
|
|
// There is no more adjacent nodes
|
|
|
|
if box.parent != nil {
|
|
|
|
// Lift back up to parent, and set it to its next.
|
|
|
|
return box.parent.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return box.next
|
|
|
|
}
|
|
|
|
|
2024-03-08 00:34:21 -08:00
|
|
|
ui_cursor_pos :: #force_inline proc "contextless" () -> Vec2 {
|
|
|
|
using state := get_state()
|
|
|
|
if ui_context == & state.project.workspace.ui {
|
|
|
|
return screen_to_world( input.mouse.pos )
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return input.mouse.pos
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_drag_delta :: #force_inline proc "contextless" () -> Vec2 {
|
|
|
|
using state := get_state()
|
2024-03-09 10:55:47 -08:00
|
|
|
return ui_cursor_pos() - state.ui_context.active_start_signal.cursor_pos
|
2024-03-08 00:34:21 -08:00
|
|
|
}
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
ui_graph_build_begin :: proc( ui : ^ UI_State, bounds : Vec2 = {} )
|
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
profile(#procedure)
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
get_state().ui_context = ui
|
|
|
|
using get_state().ui_context
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
curr_cache, prev_cache = swap( curr_cache, prev_cache )
|
|
|
|
|
|
|
|
if ui.active == UI_Key(0) {
|
2024-03-09 10:55:47 -08:00
|
|
|
//ui.hot = UI_Key(0)
|
|
|
|
ui.active_start_signal = {}
|
|
|
|
}
|
|
|
|
if ui.hot == UI_Key(0) {
|
|
|
|
ui.hot_resizable = false
|
2024-03-02 07:24:09 -08:00
|
|
|
}
|
2024-02-27 04:50:57 -08:00
|
|
|
|
2024-03-10 17:09:04 -07:00
|
|
|
ui.built_box_count = 0
|
2024-02-27 04:50:57 -08:00
|
|
|
root = ui_box_make( {}, "root#001" )
|
|
|
|
ui_parent_push(root)
|
2024-02-22 20:15:29 -08:00
|
|
|
}
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
// TODO(Ed) :: Is this even needed?
|
|
|
|
ui_graph_build_end :: proc()
|
2024-02-22 20:15:29 -08:00
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
profile(#procedure)
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
ui_parent_pop() // Should be ui_context.root
|
2024-02-27 04:50:57 -08:00
|
|
|
|
|
|
|
// Regenerate the computed layout if dirty
|
2024-03-02 07:24:09 -08:00
|
|
|
ui_compute_layout()
|
2024-02-27 04:50:57 -08:00
|
|
|
|
|
|
|
get_state().ui_context = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
@(deferred_none = ui_graph_build_end)
|
|
|
|
ui_graph_build :: proc( ui : ^ UI_State ) {
|
|
|
|
ui_graph_build_begin( ui )
|
|
|
|
}
|
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
ui_key_from_string :: proc( value : string ) -> UI_Key
|
|
|
|
{
|
|
|
|
// profile(#procedure)
|
|
|
|
USE_RAD_DEBUGGERS_METHOD :: true
|
|
|
|
|
|
|
|
key : UI_Key
|
|
|
|
|
|
|
|
when USE_RAD_DEBUGGERS_METHOD {
|
|
|
|
hash : u64
|
|
|
|
for str_byte in transmute([]byte) value {
|
|
|
|
hash = ((hash << 5) + hash) + u64(str_byte)
|
|
|
|
}
|
|
|
|
key = cast(UI_Key) hash
|
|
|
|
}
|
|
|
|
|
|
|
|
when ! USE_RAD_DEBUGGERS_METHOD {
|
|
|
|
key = cast(UI_Key) crc32( transmute([]byte) value )
|
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
return key
|
|
|
|
}
|
|
|
|
|
2024-03-09 07:21:48 -08:00
|
|
|
ui_layout_padding :: proc( pixels : f32 ) -> UI_LayoutSide {
|
|
|
|
return { pixels, pixels, pixels, pixels }
|
|
|
|
}
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
ui_parent_push :: proc( ui : ^ UI_Box ) {
|
|
|
|
stack := & get_state().ui_context.parent_stack
|
|
|
|
stack_push( & get_state().ui_context.parent_stack, ui )
|
|
|
|
}
|
2024-02-22 20:15:29 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
ui_parent_pop :: proc() {
|
|
|
|
// If size_to_content is set, we need to compute the layout now.
|
2024-02-22 20:15:29 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
// Check to make sure that the parent's children are the same for this frame,
|
|
|
|
// if its not we need to mark the layout as dirty.
|
2024-02-22 20:15:29 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
stack_pop( & get_state().ui_context.parent_stack )
|
|
|
|
}
|
|
|
|
|
|
|
|
@(deferred_none = ui_parent_pop)
|
2024-03-12 17:55:29 -07:00
|
|
|
ui_parent :: proc( ui : ^UI_Box) {
|
2024-02-27 04:50:57 -08:00
|
|
|
ui_parent_push( ui )
|
|
|
|
}
|
|
|
|
|
2024-03-09 10:55:47 -08:00
|
|
|
ui_style_peek :: proc( box_state : UI_StylePreset ) -> UI_Style {
|
|
|
|
return stack_peek_ref( & get_state().ui_context.theme_stack ).array[box_state]
|
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
ui_style_ref :: proc( box_state : UI_StylePreset ) -> (^ UI_Style) {
|
|
|
|
return & stack_peek_ref( & get_state().ui_context.theme_stack ).array[box_state]
|
2024-02-12 17:52:56 -08:00
|
|
|
}
|
2024-02-22 20:15:29 -08:00
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
ui_style_set :: proc ( style : UI_Style, box_state : UI_StylePreset ) {
|
|
|
|
stack_peek_ref( & get_state().ui_context.theme_stack ).array[box_state] = style
|
2024-02-22 20:15:29 -08:00
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
ui_style_set_layout :: proc ( layout : UI_Layout, preset : UI_StylePreset ) {
|
|
|
|
stack_peek_ref( & get_state().ui_context.theme_stack ).array[preset].layout = layout
|
2024-02-27 04:50:57 -08:00
|
|
|
}
|
2024-02-22 20:15:29 -08:00
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
ui_style_theme_push :: proc( preset : UI_StyleTheme ) {
|
2024-03-05 07:40:28 -08:00
|
|
|
push( & get_state().ui_context.theme_stack, preset )
|
2024-02-22 20:15:29 -08:00
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
ui_style_theme_pop :: proc() {
|
2024-03-05 07:40:28 -08:00
|
|
|
pop( & get_state().ui_context.theme_stack )
|
2024-02-27 04:50:57 -08:00
|
|
|
}
|
2024-02-22 20:15:29 -08:00
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
@(deferred_none = ui_style_theme_pop)
|
|
|
|
ui_style_theme :: proc( preset : UI_StyleTheme ) {
|
|
|
|
ui_style_theme_push( preset )
|
|
|
|
}
|
|
|
|
|
2024-03-12 17:55:29 -07:00
|
|
|
@(deferred_none = ui_style_theme_pop)
|
|
|
|
ui_theme_via_style :: proc ( style : UI_Style ) {
|
|
|
|
ui_style_theme_push( UI_StyleTheme { styles = { style, style, style, style } })
|
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
ui_style_theme_set_layout :: proc ( layout : UI_Layout ) {
|
|
|
|
for & preset in stack_peek_ref( & get_state().ui_context.theme_stack ).array {
|
|
|
|
preset.layout = layout
|
|
|
|
}
|
2024-02-22 20:15:29 -08:00
|
|
|
}
|