Changed input field to rawptr
This commit is contained in:
parent
20fe936017
commit
55d122de0c
2 changed files with 35 additions and 44 deletions
|
|
@ -99,22 +99,43 @@ main :: proc() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_slider_2d :: proc(width, height: ui.Size_Percentage, config: ui.ElementConfiguration, value: ^v2, min: f32, max: f32) -> ^ui.Element {
|
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 {
|
||||||
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)}
|
||||||
ui.slider(dimensions, {margin = config.margin}, {value = &value.x, min = min, max = max})
|
data: ^ElementData_Slider
|
||||||
|
data = new(ElementData_Slider, allocator)
|
||||||
|
data^ = {value = &value.x, min = min, max = max}
|
||||||
|
ui.slider(dimensions, {margin = config.margin}, data)
|
||||||
ui.same_line()
|
ui.same_line()
|
||||||
ui.slider(dimensions, {margin = config.margin}, {value = &value.y, min = min, max = max})
|
data = new(ElementData_Slider, allocator)
|
||||||
|
data^ = {value = &value.y, min = min, max = max}
|
||||||
|
ui.slider(dimensions, {margin = config.margin}, data)
|
||||||
ui.container_end()
|
ui.container_end()
|
||||||
return container
|
return container
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_input_float_2d :: proc(width, height: ui.Size_Percentage, config: ui.ElementConfiguration, value: ^v2, value_string_x, value_string_y: cstring) -> ^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)}
|
||||||
ui.input_float(dimensions, {margin = config.margin}, {value_string = value_string_x, value = &value.x})
|
data: ^ElementData_FloatInput
|
||||||
|
data = new(ElementData_FloatInput, allocator)
|
||||||
|
data^ = {value_string = value_string_x, value = &value.x}
|
||||||
|
ui.input_float(dimensions, {margin = config.margin}, data)
|
||||||
ui.same_line()
|
ui.same_line()
|
||||||
ui.input_float(dimensions, {margin = config.margin}, {value_string = value_string_y, value = &value.y})
|
|
||||||
|
data = new(ElementData_FloatInput, allocator)
|
||||||
|
data^ = {value_string = value_string_x, value = &value.x}
|
||||||
|
ui.input_float(dimensions, {margin = config.margin}, data)
|
||||||
ui.container_end()
|
ui.container_end()
|
||||||
return container
|
return container
|
||||||
}
|
}
|
||||||
|
|
@ -129,10 +150,10 @@ render_ui_elements :: proc(ctx: ^ui.Context, elements: []ui.Element) {
|
||||||
case .Button:
|
case .Button:
|
||||||
rl.GuiButton(area, element.label)
|
rl.GuiButton(area, element.label)
|
||||||
case .Slider:
|
case .Slider:
|
||||||
data := element.data
|
data := cast(^ElementData_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 := element.data
|
data := cast(^ElementData_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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
42
ui.odin
42
ui.odin
|
|
@ -30,7 +30,7 @@ Element :: struct {
|
||||||
area: rect2,
|
area: rect2,
|
||||||
id: int,
|
id: int,
|
||||||
using config: ElementConfiguration,
|
using config: ElementConfiguration,
|
||||||
data: ElementData,
|
data: rawptr,
|
||||||
type: ElementType,
|
type: ElementType,
|
||||||
dimensions: Dimensions,
|
dimensions: Dimensions,
|
||||||
}
|
}
|
||||||
|
|
@ -41,22 +41,6 @@ ElementConfiguration :: struct {
|
||||||
margin, padding: v2,
|
margin, padding: v2,
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementData :: struct {
|
|
||||||
min, max: f32,
|
|
||||||
value: ^f32,
|
|
||||||
value_string: cstring,
|
|
||||||
}
|
|
||||||
|
|
||||||
ElementData_Slider :: struct {
|
|
||||||
min, max: f32,
|
|
||||||
value: ^f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
ElementData_FloatInput :: struct {
|
|
||||||
value: ^f32,
|
|
||||||
value_string: cstring,
|
|
||||||
}
|
|
||||||
|
|
||||||
ElementType :: enum {
|
ElementType :: enum {
|
||||||
Container,
|
Container,
|
||||||
Button,
|
Button,
|
||||||
|
|
@ -190,33 +174,19 @@ assert_no_dimensions_percentage_in_auto_container :: proc(dimensions: Dimensions
|
||||||
button :: proc(dimensions: Dimensions, config: ElementConfiguration) -> ^Element {
|
button :: proc(dimensions: Dimensions, config: ElementConfiguration) -> ^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({
|
return _append_element({area = area, config = config, type = .Button, dimensions = dimensions})
|
||||||
area = area,
|
|
||||||
config = config,
|
|
||||||
type = .Button,
|
|
||||||
dimensions = dimensions})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
slider :: proc(dimensions: Dimensions, config: ElementConfiguration, data: ElementData_Slider) -> ^Element {
|
slider :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr) -> ^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({
|
return _append_element({area = area, config = config, type = .Slider, data = data, dimensions = dimensions})
|
||||||
area = area,
|
|
||||||
config = config,
|
|
||||||
type = .Slider,
|
|
||||||
data = {max = data.max, min = data.min, value = data.value},
|
|
||||||
dimensions = dimensions})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input_float :: proc(dimensions: Dimensions, config: ElementConfiguration, data: ElementData_FloatInput) -> ^Element {
|
input_float :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr) -> ^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({
|
return _append_element({area = area, config = config, type = .InputFloat, data = data, dimensions = dimensions})
|
||||||
area = area,
|
|
||||||
config = config,
|
|
||||||
type = .InputFloat,
|
|
||||||
data = {value = data.value, value_string = data.value_string},
|
|
||||||
dimensions = dimensions})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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