Beginning to review progress on prototype codebase bootstrapping.
This commit is contained in:
@ -216,9 +216,10 @@ State :: struct {
|
||||
|
||||
input_data : [2]InputState,
|
||||
input_prev : ^InputState,
|
||||
input : ^InputState,
|
||||
input : ^InputState, // TODO(Ed): Rename to indicate its the device's signal state for the frame?
|
||||
|
||||
input_events : InputEvents,
|
||||
input_events: InputEvents,
|
||||
input_binds_stack: Array(InputContext),
|
||||
|
||||
// Note(Ed): Do not modify directly, use its interface in app/event.odin
|
||||
staged_input_events : Array(InputEvent),
|
||||
@ -292,4 +293,7 @@ get_screen_extent :: #force_inline proc "contextless" () -> Extents2 { retu
|
||||
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 }
|
||||
|
||||
get_input_binds :: #force_inline proc "contextless" () -> InputContext { return array_back(get_state().input_binds_stack) }
|
||||
get_input_binds_stack :: #force_inline proc "contextless" () -> []InputContext { return array_to_slice(get_state().input_binds_stack) }
|
||||
|
||||
//endregion State
|
||||
|
@ -536,7 +536,7 @@ tick_work_frame :: #force_inline proc( host_delta_time_ms : f64 ) -> b32
|
||||
|
||||
debug.draw_ui_box_bounds_points = false
|
||||
debug.draw_ui_padding_bounds = false
|
||||
debug.draw_ui_content_bounds = false
|
||||
debug.draw_ui_content_bounds = true
|
||||
|
||||
// config.engine_refresh_hz = 165
|
||||
|
||||
|
@ -454,6 +454,13 @@ render_ui_via_box_list :: proc( box_list : []UI_RenderBoxInfo, text_list : []UI_
|
||||
shape_enqueued = true
|
||||
}
|
||||
|
||||
if debug.draw_ui_content_bounds
|
||||
{
|
||||
render_set_color(RGBA8_Debug_UI_Content_Bounds)
|
||||
draw_rect_border(entry.bounds, 1.0)
|
||||
shape_enqueued = true
|
||||
}
|
||||
|
||||
box_id += 1
|
||||
}
|
||||
|
||||
@ -890,4 +897,4 @@ render_set_view_space :: #force_inline proc( extent : Extents2 )
|
||||
gp.project( -extent.x, extent.x, extent.y, -extent.y )
|
||||
}
|
||||
|
||||
//endregion Helpers
|
||||
//endregion Helper
|
@ -124,6 +124,8 @@ import "core:os"
|
||||
import "core:path/filepath"
|
||||
file_name_from_path :: filepath.short_stem
|
||||
|
||||
import "core:slice"
|
||||
|
||||
import "core:strconv"
|
||||
parse_f32 :: strconv.parse_f32
|
||||
parse_u64 :: strconv.parse_u64
|
||||
@ -194,6 +196,7 @@ import "codebase:grime"
|
||||
array_append_value :: grime.array_append_value
|
||||
array_append_array :: grime.array_append_array
|
||||
array_append_at :: grime.array_append_at
|
||||
array_back :: grime.array_back
|
||||
array_clear :: grime.array_clear
|
||||
array_free :: grime.array_free
|
||||
array_grow_formula :: grime.array_grow_formula
|
||||
@ -366,6 +369,10 @@ append_at :: proc {
|
||||
grime.array_append_at_slice,
|
||||
}
|
||||
|
||||
back :: proc {
|
||||
grime.array_back,
|
||||
}
|
||||
|
||||
bivec3 :: proc {
|
||||
bivec3_via_f32s,
|
||||
vec3_to_bivec3,
|
||||
@ -426,7 +433,7 @@ floor :: proc {
|
||||
math.floor_f64le,
|
||||
math.floor_f64be,
|
||||
|
||||
linalg.floor
|
||||
linalg.floor,
|
||||
}
|
||||
|
||||
from_bytes :: proc {
|
||||
@ -717,4 +724,8 @@ wedge :: proc {
|
||||
wedge_bivec3,
|
||||
}
|
||||
|
||||
zero :: proc {
|
||||
slice.zero,
|
||||
}
|
||||
|
||||
//endregion Proc overload mappings
|
||||
|
@ -48,6 +48,7 @@ UI_InteractState :: struct {
|
||||
disabled_time : f32,
|
||||
}
|
||||
|
||||
// TODO(Ed): Make the key 128-bit?
|
||||
UI_Key :: distinct u64
|
||||
|
||||
UI_Scalar :: f32
|
||||
|
@ -1,5 +1,163 @@
|
||||
package sectr
|
||||
|
||||
ui_layout_children_horizontally :: proc( container : ^UI_Box, direction : UI_LayoutDirection_X, width_ref : ^f32 = nil )
|
||||
{
|
||||
container_width : f32
|
||||
if width_ref != nil {
|
||||
container_width = width_ref ^
|
||||
}
|
||||
else {
|
||||
container_width = container.computed.content.max.x - container.computed.content.min.x
|
||||
}
|
||||
container_height := container.computed.content.max.y - container.computed.content.min.y
|
||||
|
||||
// do layout calculations for the children
|
||||
total_stretch_ratio : f32 = 0.0
|
||||
size_req_children : f32 = 0
|
||||
for child := container.first; child != nil; child = child.next
|
||||
{
|
||||
using child.layout
|
||||
scaled_width_by_height : b32 = b32(.Scale_Width_By_Height_Ratio in flags)
|
||||
if .Scale_Width_By_Height_Ratio in flags
|
||||
{
|
||||
size_req_children += size.min.x * container_height
|
||||
continue
|
||||
}
|
||||
if .Fixed_Width in flags
|
||||
{
|
||||
size_req_children += size.min.x
|
||||
continue
|
||||
}
|
||||
|
||||
size_req_children += size.min.x
|
||||
total_stretch_ratio += anchor.ratio.x
|
||||
}
|
||||
|
||||
avail_flex_space := container_width - size_req_children
|
||||
|
||||
allocate_space :: proc( child : ^UI_Box, total_stretch_ratio, avail_flex_space, container_height : f32 ) -> (space_allocated : f32)
|
||||
{
|
||||
using child.layout
|
||||
if .Scale_Width_By_Height_Ratio in flags {
|
||||
size.min.y = container_height
|
||||
space_allocated = size.min.x * container_height
|
||||
}
|
||||
else if ! (.Fixed_Width in flags) {
|
||||
potential_size := anchor.ratio.x * (1 / total_stretch_ratio) * avail_flex_space
|
||||
space_allocated = max(potential_size, size.min.x)
|
||||
size.min.x = space_allocated
|
||||
}
|
||||
else {
|
||||
space_allocated = size.min.x
|
||||
}
|
||||
space_allocated -= margins.left - margins.right
|
||||
size.min.x -= margins.left - margins.right
|
||||
flags |= {.Fixed_Width}
|
||||
return
|
||||
}
|
||||
|
||||
space_used : f32 = 0.0
|
||||
switch direction{
|
||||
case .Left_To_Right:
|
||||
for child := container.first; child != nil; child = child.next {
|
||||
using child.layout
|
||||
child_width := allocate_space(child, total_stretch_ratio, avail_flex_space, container_height)
|
||||
anchor = range2({0, anchor.bottom}, {0, anchor.top})
|
||||
alignment = {0, alignment.y}
|
||||
pos.x = space_used
|
||||
space_used += child_width + child.layout.margins.left + child.layout.margins.right
|
||||
}
|
||||
case .Right_To_Left:
|
||||
for child := container.first; child != nil; child = child.next {
|
||||
using child.layout
|
||||
child_width := allocate_space(child, total_stretch_ratio, avail_flex_space, container_height)
|
||||
anchor = range2({1, anchor.bottom}, {0, anchor.top})
|
||||
alignment = {1, alignment.y}
|
||||
pos.x = space_used
|
||||
space_used -= child_width + child.layout.margins.left + child.layout.margins.right
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui_layout_children_vertically :: proc( container : ^UI_Box, direction : UI_LayoutDirection_Y, height_ref : ^f32 = nil )
|
||||
{
|
||||
container_height : f32
|
||||
if height_ref != nil {
|
||||
container_height = height_ref ^
|
||||
}
|
||||
else {
|
||||
container_height = container.computed.content.max.y - container.computed.content.min.y
|
||||
}
|
||||
container_width := container.computed.content.max.x - container.computed.content.min.x
|
||||
|
||||
// do layout calculations for the children
|
||||
total_stretch_ratio : f32 = 0.0
|
||||
size_req_children : f32 = 0
|
||||
for child := container.first; child != nil; child = child.next
|
||||
{
|
||||
using child.layout
|
||||
scaled_height_by_width : b32 = b32(.Scale_Height_By_Width_Ratio in flags)
|
||||
if scaled_height_by_width {
|
||||
size_req_children += size.min.y * container_width
|
||||
continue
|
||||
}
|
||||
if .Fixed_Height in flags
|
||||
{
|
||||
size_req_children += size.min.y
|
||||
continue
|
||||
}
|
||||
|
||||
size_req_children += size.min.y
|
||||
total_stretch_ratio += anchor.ratio.y
|
||||
}
|
||||
|
||||
avail_flex_space := container_height - size_req_children
|
||||
|
||||
allocate_space :: proc( child : ^UI_Box, total_stretch_ratio, avail_flex_space, container_width : f32 ) -> (space_allocated : f32)
|
||||
{
|
||||
using child.layout
|
||||
if .Scale_Height_By_Width_Ratio in flags {
|
||||
size.min.x = container_width
|
||||
space_allocated = size.min.y * container_width
|
||||
}
|
||||
if ! (.Fixed_Height in flags) {
|
||||
potential_size := (anchor.ratio.y * (1 / total_stretch_ratio) * avail_flex_space)
|
||||
space_allocated = max(potential_size, size.min.y)
|
||||
size.min.y = space_allocated
|
||||
}
|
||||
else {
|
||||
space_allocated = size.min.y
|
||||
}
|
||||
space_allocated -= margins.top - margins.bottom
|
||||
size.min.y -= margins.top - margins.bottom
|
||||
flags |= {.Fixed_Height}
|
||||
return
|
||||
}
|
||||
|
||||
space_used : f32 = 0
|
||||
switch direction
|
||||
{
|
||||
case .Top_To_Bottom:
|
||||
for child := container.first; child != nil; child = child.next {
|
||||
using child.layout
|
||||
child_height := allocate_space(child, total_stretch_ratio, avail_flex_space, container_width)
|
||||
anchor = range2({anchor.left, 1}, {anchor.right, 0})
|
||||
alignment = {alignment.x, 1}
|
||||
pos.y = space_used
|
||||
space_used -= child_height - child.layout.margins.top - child.layout.margins.bottom
|
||||
}
|
||||
case .Bottom_To_Top:
|
||||
for child := container.first; child != nil; child = child.next {
|
||||
using child.layout
|
||||
child_height := allocate_space(child, total_stretch_ratio, avail_flex_space, container_width)
|
||||
anchor = range2({anchor.left,0}, {anchor.right, 0})
|
||||
alignment = {alignment.x, 0}
|
||||
pos.y = space_used
|
||||
space_used += child_height - child.layout.margins.top - child.layout.margins.bottom
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui_box_compute_layout :: proc( box : ^UI_Box,
|
||||
dont_mark_fresh : b32 = false,
|
||||
ancestors_layout_required : b32 = false,
|
||||
|
@ -8,161 +8,3 @@ Widget Layout Ops
|
||||
|
||||
TODO(Ed): Review this file, these are can now be done with ui_box_compute_layout
|
||||
*/
|
||||
|
||||
ui_layout_children_horizontally :: proc( container : ^UI_Box, direction : UI_LayoutDirection_X, width_ref : ^f32 = nil )
|
||||
{
|
||||
container_width : f32
|
||||
if width_ref != nil {
|
||||
container_width = width_ref ^
|
||||
}
|
||||
else {
|
||||
container_width = container.computed.content.max.x - container.computed.content.min.x
|
||||
}
|
||||
container_height := container.computed.content.max.y - container.computed.content.min.y
|
||||
|
||||
// do layout calculations for the children
|
||||
total_stretch_ratio : f32 = 0.0
|
||||
size_req_children : f32 = 0
|
||||
for child := container.first; child != nil; child = child.next
|
||||
{
|
||||
using child.layout
|
||||
scaled_width_by_height : b32 = b32(.Scale_Width_By_Height_Ratio in flags)
|
||||
if .Scale_Width_By_Height_Ratio in flags
|
||||
{
|
||||
size_req_children += size.min.x * container_height
|
||||
continue
|
||||
}
|
||||
if .Fixed_Width in flags
|
||||
{
|
||||
size_req_children += size.min.x
|
||||
continue
|
||||
}
|
||||
|
||||
size_req_children += size.min.x
|
||||
total_stretch_ratio += anchor.ratio.x
|
||||
}
|
||||
|
||||
avail_flex_space := container_width - size_req_children
|
||||
|
||||
allocate_space :: proc( child : ^UI_Box, total_stretch_ratio, avail_flex_space, container_height : f32 ) -> (space_allocated : f32)
|
||||
{
|
||||
using child.layout
|
||||
if .Scale_Width_By_Height_Ratio in flags {
|
||||
size.min.y = container_height
|
||||
space_allocated = size.min.x * container_height
|
||||
}
|
||||
else if ! (.Fixed_Width in flags) {
|
||||
potential_size := anchor.ratio.x * (1 / total_stretch_ratio) * avail_flex_space
|
||||
space_allocated = lalg.max(potential_size, size.min.x)
|
||||
size.min.x = space_allocated
|
||||
}
|
||||
else {
|
||||
space_allocated = size.min.x
|
||||
}
|
||||
space_allocated -= margins.left - margins.right
|
||||
size.min.x -= margins.left - margins.right
|
||||
flags |= {.Fixed_Width}
|
||||
return
|
||||
}
|
||||
|
||||
space_used : f32 = 0.0
|
||||
switch direction{
|
||||
case .Left_To_Right:
|
||||
for child := container.first; child != nil; child = child.next {
|
||||
using child.layout
|
||||
child_width := allocate_space(child, total_stretch_ratio, avail_flex_space, container_height)
|
||||
anchor = range2({0, anchor.bottom}, {0, anchor.top})
|
||||
alignment = {0, alignment.y}
|
||||
pos.x = space_used
|
||||
space_used += child_width + child.layout.margins.left + child.layout.margins.right
|
||||
}
|
||||
case .Right_To_Left:
|
||||
for child := container.first; child != nil; child = child.next {
|
||||
using child.layout
|
||||
child_width := allocate_space(child, total_stretch_ratio, avail_flex_space, container_height)
|
||||
anchor = range2({1, anchor.bottom}, {0, anchor.top})
|
||||
alignment = {1, alignment.y}
|
||||
pos.x = space_used
|
||||
space_used -= child_width + child.layout.margins.left + child.layout.margins.right
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui_layout_children_vertically :: proc( container : ^UI_Box, direction : UI_LayoutDirection_Y, height_ref : ^f32 = nil )
|
||||
{
|
||||
container_height : f32
|
||||
if height_ref != nil {
|
||||
container_height = height_ref ^
|
||||
}
|
||||
else {
|
||||
container_height = container.computed.content.max.y - container.computed.content.min.y
|
||||
}
|
||||
container_width := container.computed.content.max.x - container.computed.content.min.x
|
||||
|
||||
// do layout calculations for the children
|
||||
total_stretch_ratio : f32 = 0.0
|
||||
size_req_children : f32 = 0
|
||||
for child := container.first; child != nil; child = child.next
|
||||
{
|
||||
using child.layout
|
||||
scaled_height_by_width : b32 = b32(.Scale_Height_By_Width_Ratio in flags)
|
||||
if scaled_height_by_width {
|
||||
size_req_children += size.min.y * container_width
|
||||
continue
|
||||
}
|
||||
if .Fixed_Height in flags
|
||||
{
|
||||
size_req_children += size.min.y
|
||||
continue
|
||||
}
|
||||
|
||||
size_req_children += size.min.y
|
||||
total_stretch_ratio += anchor.ratio.y
|
||||
}
|
||||
|
||||
avail_flex_space := container_height - size_req_children
|
||||
|
||||
allocate_space :: proc( child : ^UI_Box, total_stretch_ratio, avail_flex_space, container_width : f32 ) -> (space_allocated : f32)
|
||||
{
|
||||
using child.layout
|
||||
if .Scale_Height_By_Width_Ratio in flags {
|
||||
size.min.x = container_width
|
||||
space_allocated = size.min.y * container_width
|
||||
}
|
||||
if ! (.Fixed_Height in flags) {
|
||||
potential_size := (anchor.ratio.y * (1 / total_stretch_ratio) * avail_flex_space)
|
||||
space_allocated = lalg.max(potential_size, size.min.y)
|
||||
size.min.y = space_allocated
|
||||
}
|
||||
else {
|
||||
space_allocated = size.min.y
|
||||
}
|
||||
space_allocated -= margins.top - margins.bottom
|
||||
size.min.y -= margins.top - margins.bottom
|
||||
flags |= {.Fixed_Height}
|
||||
return
|
||||
}
|
||||
|
||||
space_used : f32 = 0
|
||||
switch direction
|
||||
{
|
||||
case .Top_To_Bottom:
|
||||
for child := container.first; child != nil; child = child.next {
|
||||
using child.layout
|
||||
child_height := allocate_space(child, total_stretch_ratio, avail_flex_space, container_width)
|
||||
anchor = range2({anchor.left, 1}, {anchor.right, 0})
|
||||
alignment = {alignment.x, 1}
|
||||
pos.y = space_used
|
||||
space_used -= child_height - child.layout.margins.top - child.layout.margins.bottom
|
||||
}
|
||||
case .Bottom_To_Top:
|
||||
for child := container.first; child != nil; child = child.next {
|
||||
using child.layout
|
||||
child_height := allocate_space(child, total_stretch_ratio, avail_flex_space, container_width)
|
||||
anchor = range2({anchor.left,0}, {anchor.right, 0})
|
||||
alignment = {alignment.x, 0}
|
||||
pos.y = space_used
|
||||
space_used += child_height - child.layout.margins.top - child.layout.margins.bottom
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user