Hopefully last design change to auto-layout algorithim
I'm sticking with not supporting the top-left alignment for default and instead going with bottom left. This allows for 0,0 alignment to the "bottom left pivot" for a box and 1,1 to the "top-right pivot" of a box. These naturally coincide with where the actual min-max points that define the box are for the coodrindate convention I decided to go with. I'll write docs to migitate confusion. Now I just need to fix the layout presets I have for the currently existing constructions...
This commit is contained in:
@ -4,4 +4,7 @@ Eventually want to generalize this core UI as its own library.
|
||||
This will keep track of here whats needed for it to work wihtout the rest of this codebase.
|
||||
|
||||
* Provide UI input state or "events" in its own data stucture at the beginning of `ui_build_graph`:
|
||||
*
|
||||
*
|
||||
|
||||
|
||||
TODO(Ed): I'm not sure what to make the default coordinate space for this widget
|
@ -88,7 +88,7 @@ UI_LayoutFlag :: enum u32 {
|
||||
Scale_Height_By_Width_Ratio,
|
||||
|
||||
// Sets the (0, 0) position of the child box to the parents anchor's center (post-margins bounds)
|
||||
// By Default, the origin is at the top left of the anchor's bounds
|
||||
// By Default, the origin is at the top left of the anchor's bounds (traditional)
|
||||
Origin_At_Anchor_Center,
|
||||
|
||||
// TODO(Ed): Implement this!
|
||||
|
@ -106,11 +106,11 @@ ui_box_compute_layout :: proc( box : ^UI_Box,
|
||||
|
||||
// 5. Determine relative position
|
||||
|
||||
origin_center := margined_bounds_origin
|
||||
origin_top_left := Vec2 { margined_bounds.min.x, margined_bounds.max.y }
|
||||
|
||||
origin := .Origin_At_Anchor_Center in layout.flags ? origin_center : origin_top_left
|
||||
origin_center := margined_bounds_origin
|
||||
origin_top_left := Vec2 { margined_bounds.min.x, margined_bounds.max.y }
|
||||
origin_bottom_left := Vec2 { margined_bounds.min.x, margined_bounds.min.y }
|
||||
|
||||
origin := .Origin_At_Anchor_Center in layout.flags ? origin_center : origin_bottom_left
|
||||
rel_pos := origin + layout.pos
|
||||
|
||||
if .Fixed_Position_X in layout.flags {
|
||||
@ -127,11 +127,10 @@ ui_box_compute_layout :: proc( box : ^UI_Box,
|
||||
alignment := layout.alignment
|
||||
bounds : Range2
|
||||
if ! (.Origin_At_Anchor_Center in layout.flags) {
|
||||
// The convention offset adjust the box so that the top-left point is at the top left of the anchor's bounds
|
||||
tl_convention_offset := adjusted_size * {0, -1}
|
||||
// alignment *= -1 // Inversing so that it goes toward top-right.
|
||||
bounds = range2(
|
||||
rel_pos - adjusted_size * alignment + tl_convention_offset,
|
||||
rel_pos + adjusted_size * (vec2_one - alignment) + tl_convention_offset,
|
||||
rel_pos - adjusted_size * alignment ,
|
||||
rel_pos + adjusted_size * (vec2_one - alignment),
|
||||
)
|
||||
}
|
||||
else {
|
||||
@ -184,4 +183,3 @@ ui_box_compute_layout_children :: proc( box : ^UI_Box )
|
||||
ui_box_compute_layout( current )
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ test_parenting :: proc( default_layout : ^UI_Layout, frame_style_default : ^UI_S
|
||||
parent_layout.size = range2( { 300, 300 }, {} )
|
||||
parent_layout.alignment = { 0.0, 0.0 }
|
||||
// parent_layout.margins = { 100, 100, 100, 100 }
|
||||
parent_layout.padding = { 5, 10, 5, 5 }
|
||||
// parent_layout.padding = { 5, 10, 5, 5 }
|
||||
parent_layout.pos = { 0, 0 }
|
||||
parent_layout.flags = {
|
||||
.Fixed_Position_X, .Fixed_Position_Y,
|
||||
@ -108,7 +108,7 @@ test_parenting :: proc( default_layout : ^UI_Layout, frame_style_default : ^UI_S
|
||||
|
||||
child_layout := default_layout ^
|
||||
child_layout.size = range2({ 100, 100 }, { 0, 0 })
|
||||
child_layout.alignment = { 1.0, 0.0 }
|
||||
child_layout.alignment = { 1.0, 1.0 }
|
||||
// child_layout.margins = { 20, 20, 20, 20 }
|
||||
child_layout.padding = { 5, 5, 5, 5 }
|
||||
// child_layout.anchor = range2({ 0.2, 0.1 }, { 0.1, 0.15 })
|
||||
|
Reference in New Issue
Block a user