rawptr for everything
This commit is contained in:
parent
55d122de0c
commit
f923e07fbf
2 changed files with 69 additions and 29 deletions
|
|
@ -13,6 +13,30 @@ INPUT_FLOAT_CHARACTERS :: 32
|
||||||
|
|
||||||
v2 :: [2]f32
|
v2 :: [2]f32
|
||||||
V2_ONE :: v2{1.0, 1.0}
|
V2_ONE :: v2{1.0, 1.0}
|
||||||
|
V2_LEFT :: v2{-1.0, 0.0}
|
||||||
|
V2_RIGHT :: v2{1.0, 0.0}
|
||||||
|
V2_UP :: v2{-1.0, 0.0}
|
||||||
|
V2_DOWN :: v2{1.0, 0.0}
|
||||||
|
|
||||||
|
UiContainerType :: enum {
|
||||||
|
Normal,
|
||||||
|
Matrix,
|
||||||
|
}
|
||||||
|
|
||||||
|
UiElementData_Container :: struct {
|
||||||
|
type: UiContainerType,
|
||||||
|
thickness: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
UiElementData_Slider :: struct {
|
||||||
|
min, max: f32,
|
||||||
|
value: ^f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
UiElementData_FloatInput :: struct {
|
||||||
|
value: ^f32,
|
||||||
|
value_string: cstring,
|
||||||
|
}
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
rl.SetTraceLogLevel(.WARNING)
|
rl.SetTraceLogLevel(.WARNING)
|
||||||
|
|
@ -46,7 +70,9 @@ main :: proc() {
|
||||||
ui.container_end()
|
ui.container_end()
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.container_begin(dimensions = {ui.SIZE_AUTO, ui.Size_Percentage(0.2)}, config = inner_container_config)
|
container_data := new(UiElementData_Container, context.temp_allocator)
|
||||||
|
container_data^ = {type = .Matrix, thickness = 2.0}
|
||||||
|
ui.container_begin(dimensions = {ui.SIZE_AUTO, ui.Size_Percentage(0.2)}, config = inner_container_config, data = container_data)
|
||||||
for j in 0..<10 {
|
for j in 0..<10 {
|
||||||
config := button_config
|
config := button_config
|
||||||
config.label = fmt.ctprintf("%d", 70 + j)
|
config.label = fmt.ctprintf("%d", 70 + j)
|
||||||
|
|
@ -99,25 +125,15 @@ main :: proc() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementData_Slider :: struct {
|
|
||||||
min, max: f32,
|
|
||||||
value: ^f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
ElementData_FloatInput :: struct {
|
|
||||||
value: ^f32,
|
|
||||||
value_string: cstring,
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_slider_2d :: proc(width, height: ui.Size_Percentage, config: ui.ElementConfiguration, value: ^v2, min: f32, max: f32, allocator := context.temp_allocator) -> ^ui.Element {
|
ui_slider_2d :: proc(width, height: ui.Size_Percentage, config: ui.ElementConfiguration, value: ^v2, min: f32, max: f32, allocator := context.temp_allocator) -> ^ui.Element {
|
||||||
container := ui.container_begin(dimensions = {width, height}, config = config)
|
container := ui.container_begin(dimensions = {width, height}, config = config)
|
||||||
dimensions := ui.Dimensions {ui.Size_Percentage(0.5), ui.Size_Percentage(1.0)}
|
dimensions := ui.Dimensions {ui.Size_Percentage(0.5), ui.Size_Percentage(1.0)}
|
||||||
data: ^ElementData_Slider
|
data: ^UiElementData_Slider
|
||||||
data = new(ElementData_Slider, allocator)
|
data = new(UiElementData_Slider, allocator)
|
||||||
data^ = {value = &value.x, min = min, max = max}
|
data^ = {value = &value.x, min = min, max = max}
|
||||||
ui.slider(dimensions, {margin = config.margin}, data)
|
ui.slider(dimensions, {margin = config.margin}, data)
|
||||||
ui.same_line()
|
ui.same_line()
|
||||||
data = new(ElementData_Slider, allocator)
|
data = new(UiElementData_Slider, allocator)
|
||||||
data^ = {value = &value.y, min = min, max = max}
|
data^ = {value = &value.y, min = min, max = max}
|
||||||
ui.slider(dimensions, {margin = config.margin}, data)
|
ui.slider(dimensions, {margin = config.margin}, data)
|
||||||
ui.container_end()
|
ui.container_end()
|
||||||
|
|
@ -127,13 +143,13 @@ ui_slider_2d :: proc(width, height: ui.Size_Percentage, config: ui.ElementConfig
|
||||||
ui_input_float_2d :: proc(width, height: ui.Size_Percentage, config: ui.ElementConfiguration, value: ^v2, value_string_x, value_string_y: cstring, allocator := context.temp_allocator) -> ^ui.Element {
|
ui_input_float_2d :: proc(width, height: ui.Size_Percentage, config: ui.ElementConfiguration, value: ^v2, value_string_x, value_string_y: cstring, allocator := context.temp_allocator) -> ^ui.Element {
|
||||||
container := ui.container_begin(dimensions = {width, height}, config = config)
|
container := ui.container_begin(dimensions = {width, height}, config = config)
|
||||||
dimensions := ui.Dimensions {ui.Size_Percentage(0.5), ui.Size_Percentage(1.0)}
|
dimensions := ui.Dimensions {ui.Size_Percentage(0.5), ui.Size_Percentage(1.0)}
|
||||||
data: ^ElementData_FloatInput
|
data: ^UiElementData_FloatInput
|
||||||
data = new(ElementData_FloatInput, allocator)
|
data = new(UiElementData_FloatInput, allocator)
|
||||||
data^ = {value_string = value_string_x, value = &value.x}
|
data^ = {value_string = value_string_x, value = &value.x}
|
||||||
ui.input_float(dimensions, {margin = config.margin}, data)
|
ui.input_float(dimensions, {margin = config.margin}, data)
|
||||||
ui.same_line()
|
ui.same_line()
|
||||||
|
|
||||||
data = new(ElementData_FloatInput, allocator)
|
data = new(UiElementData_FloatInput, allocator)
|
||||||
data^ = {value_string = value_string_x, value = &value.x}
|
data^ = {value_string = value_string_x, value = &value.x}
|
||||||
ui.input_float(dimensions, {margin = config.margin}, data)
|
ui.input_float(dimensions, {margin = config.margin}, data)
|
||||||
ui.container_end()
|
ui.container_end()
|
||||||
|
|
@ -145,15 +161,36 @@ render_ui_elements :: proc(ctx: ^ui.Context, elements: []ui.Element) {
|
||||||
area := rl.Rectangle(element.area)
|
area := rl.Rectangle(element.area)
|
||||||
switch element.type {
|
switch element.type {
|
||||||
case .Container:
|
case .Container:
|
||||||
rl.DrawRectangleRounded(area, 0.1, 4.0, {0, 0, 0, 192})
|
dim := rl.Color {0, 0, 0, 192}
|
||||||
|
if element.data != nil {
|
||||||
|
data := cast(^UiElementData_Container)element.data
|
||||||
|
switch data.type {
|
||||||
|
case .Normal:
|
||||||
|
rl.DrawRectangleRounded(area, 0.1, 4.0, dim)
|
||||||
rl.GuiGroupBox(area, element.label)
|
rl.GuiGroupBox(area, element.label)
|
||||||
|
case .Matrix:
|
||||||
|
matrix_area := ui.rect_grow(ui.get_element_outer_area(element), -data.thickness * 2.0)
|
||||||
|
tl, tr, br, bl := ui.rect_get_corners(matrix_area)
|
||||||
|
col := rl.WHITE
|
||||||
|
hook_length: f32 = 4.0
|
||||||
|
rl.DrawLineEx(tl, bl, data.thickness, col)
|
||||||
|
rl.DrawLineEx(tl, tl + V2_RIGHT * hook_length, data.thickness, col)
|
||||||
|
rl.DrawLineEx(bl, bl + V2_RIGHT * hook_length, data.thickness, col)
|
||||||
|
rl.DrawLineEx(tr, br, data.thickness, col)
|
||||||
|
rl.DrawLineEx(tr, tr + V2_LEFT * hook_length, data.thickness, col)
|
||||||
|
rl.DrawLineEx(br, br + V2_LEFT * hook_length, data.thickness, col)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rl.DrawRectangleRounded(area, 0.1, 4.0, dim)
|
||||||
|
rl.GuiGroupBox(area, element.label)
|
||||||
|
}
|
||||||
case .Button:
|
case .Button:
|
||||||
rl.GuiButton(area, element.label)
|
rl.GuiButton(area, element.label)
|
||||||
case .Slider:
|
case .Slider:
|
||||||
data := cast(^ElementData_Slider)element.data
|
data := cast(^UiElementData_Slider)element.data
|
||||||
rl.GuiSlider(area, "", "", data.value, data.min, data.max)
|
rl.GuiSlider(area, "", "", data.value, data.min, data.max)
|
||||||
case .InputFloat:
|
case .InputFloat:
|
||||||
data := cast(^ElementData_FloatInput)element.data
|
data := cast(^UiElementData_FloatInput)element.data
|
||||||
if rl.GuiValueBoxFloat(area, element.label, data.value_string, data.value, ui.is_element_focused(ctx, element)) == 1 {
|
if rl.GuiValueBoxFloat(area, element.label, data.value_string, data.value, ui.is_element_focused(ctx, element)) == 1 {
|
||||||
ui.focus_element(ctx, element)
|
ui.focus_element(ctx, element)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
ui.odin
19
ui.odin
|
|
@ -11,6 +11,9 @@ rect_get_tr :: #force_inline proc(rect: rect2) -> v2 {return {rect.x + rect.widt
|
||||||
rect_get_br :: #force_inline proc(rect: rect2) -> v2 {return {rect.x + rect.width, rect.y + rect.height}}
|
rect_get_br :: #force_inline proc(rect: rect2) -> v2 {return {rect.x + rect.width, rect.y + rect.height}}
|
||||||
rect_get_bl :: #force_inline proc(rect: rect2) -> v2 {return {rect.x, rect.y + rect.height}}
|
rect_get_bl :: #force_inline proc(rect: rect2) -> v2 {return {rect.x, rect.y + rect.height}}
|
||||||
rect_get_size :: #force_inline proc(rect: rect2) -> v2 {return {rect.width, rect.height}}
|
rect_get_size :: #force_inline proc(rect: rect2) -> v2 {return {rect.width, rect.height}}
|
||||||
|
rect_get_corners :: #force_inline proc(rect: rect2) -> (tl, tr, br, bl: v2) {
|
||||||
|
return rect_get_tl(rect), rect_get_tr(rect), rect_get_br(rect), rect_get_bl(rect)
|
||||||
|
}
|
||||||
rect_grow :: proc(rect: rect2, amount: v2) -> rect2 {return {rect.x - amount.x / 2.0, rect.y - amount.y / 2.0, rect.width + amount.x, rect.height + amount.y}}
|
rect_grow :: proc(rect: rect2, amount: v2) -> rect2 {return {rect.x - amount.x / 2.0, rect.y - amount.y / 2.0, rect.width + amount.x, rect.height + amount.y}}
|
||||||
|
|
||||||
ctx: ^Context
|
ctx: ^Context
|
||||||
|
|
@ -127,9 +130,9 @@ focus_next_element :: proc(ctx: ^Context, allowed_focus := element_type_input) {
|
||||||
ctx.element_focus_id = -1
|
ctx.element_focus_id = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
container_begin :: proc(dimensions: Dimensions, config: ElementConfiguration) -> ^Element {
|
container_begin :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr = nil) -> ^Element {
|
||||||
area := _resolve_element_area(dimensions, config.margin)
|
area := _resolve_element_area(dimensions, config.margin)
|
||||||
element := _append_element({area = area, config = config, type = .Container, dimensions = dimensions})
|
element := _append_element({area = area, config = config, type = .Container, dimensions = dimensions, data = data})
|
||||||
container_index := len(ctx.elements) - 1
|
container_index := len(ctx.elements) - 1
|
||||||
append(&ctx.containers, container_index)
|
append(&ctx.containers, container_index)
|
||||||
append(&ctx.container_last_element, -1)
|
append(&ctx.container_last_element, -1)
|
||||||
|
|
@ -171,22 +174,22 @@ assert_no_dimensions_percentage_in_auto_container :: proc(dimensions: Dimensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
button :: proc(dimensions: Dimensions, config: ElementConfiguration) -> ^Element {
|
button :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr = nil) -> ^Element {
|
||||||
assert_no_dimensions_percentage_in_auto_container(dimensions)
|
assert_no_dimensions_percentage_in_auto_container(dimensions)
|
||||||
area := _resolve_element_area(dimensions, config.margin)
|
area := _resolve_element_area(dimensions, config.margin)
|
||||||
return _append_element({area = area, config = config, type = .Button, dimensions = dimensions})
|
return _append_element({area = area, config = config, type = .Button, dimensions = dimensions, data = data})
|
||||||
}
|
}
|
||||||
|
|
||||||
slider :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr) -> ^Element {
|
slider :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr = nil) -> ^Element {
|
||||||
assert_no_dimensions_percentage_in_auto_container(dimensions)
|
assert_no_dimensions_percentage_in_auto_container(dimensions)
|
||||||
area := _resolve_element_area(dimensions, config.margin)
|
area := _resolve_element_area(dimensions, config.margin)
|
||||||
return _append_element({area = area, config = config, type = .Slider, data = data, dimensions = dimensions})
|
return _append_element({area = area, config = config, type = .Slider, dimensions = dimensions, data = data})
|
||||||
}
|
}
|
||||||
|
|
||||||
input_float :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr) -> ^Element {
|
input_float :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr = nil) -> ^Element {
|
||||||
assert_no_dimensions_percentage_in_auto_container(dimensions)
|
assert_no_dimensions_percentage_in_auto_container(dimensions)
|
||||||
area := _resolve_element_area(dimensions, config.margin)
|
area := _resolve_element_area(dimensions, config.margin)
|
||||||
return _append_element({area = area, config = config, type = .InputFloat, data = data, dimensions = dimensions})
|
return _append_element({area = area, config = config, type = .InputFloat, dimensions = dimensions, data = data})
|
||||||
}
|
}
|
||||||
|
|
||||||
get_element_outer_area :: proc(element: Element) -> rect2 {
|
get_element_outer_area :: proc(element: Element) -> rect2 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue