Files
coven/ui/widgets.jai
2025-01-03 16:15:48 +01:00

633 lines
24 KiB
Plaintext

ui_full_size_background :: (color: Color = .{0,0,0,1}, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_size_x(.PIXELS, xx engine.renderer.render_target_width);
ui_set_next_size_y(.PIXELS, xx engine.renderer.render_target_height);
ui_set_next_background_color(color);
background := ui_box_make(.DRAW_BACKGROUND, hash=get_hash(loc, identifier));
}
ui_container_layout :: (color: Color = .{0,0,0,0}, identifier: s64 = 0, loc := #caller_location) -> *UI_Box {
ui_set_next_size_x(.CHILDREN_SUM);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_background_color(color);
container := ui_box_make(.DRAW_BACKGROUND, hash=get_hash(loc, identifier));
return container;
}
ui_button :: (text: string, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_text_alignment(CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .DRAW_BACKGROUND | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_checkbox :: (checked: *bool, identifier: s64 = 0, loc := #caller_location) -> bool {
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.PIXELS, 12);
ui_set_next_size_y(.PIXELS, 12);
//ui_set_next_padding(5);
//ui_set_next_text_alignment(CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .DRAW_BACKGROUND, get_hash(loc, identifier));
ui_push_parent(box, .LEFT, .HORIZONTAL);
{
if checked.* {
ui_set_next_size_x(.PCT, 1);
ui_set_next_size_y(.PCT, 1);
ui_set_next_background_color(.{0.4,0.4,0.4,1});
inner_box := ui_box_make(.DRAW_TEXT | .DRAW_BACKGROUND | .ANIMATE_ON_HOVER, get_hash(loc, 1));
}
}
ui_pop_parent();
if box.interaction.clicked {
checked.* = !checked.*;
}
return checked.*;
}
ui_checkbox_field :: (label: string, value: *bool, identifier: s64 = 0, loc := #caller_location) -> bool {
changed := false;
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(DEFAULT_PADDING);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(container, .LEFT, .HORIZONTAL);
{
ui_label_half_parent_x(label);
ui_checkbox(value, identifier);
}
ui_pop_parent();
return value.*;
}
ui_button_with_texture :: (texture_handle: Texture_Handle, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_texture(texture_handle);
ui_set_next_size_x(.PIXELS, 20);
ui_set_next_size_y(.PIXELS, 20);
box := ui_box_make(.CLICKABLE | .DRAW_BACKGROUND | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_button_no_bg :: (text: string, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_button_no_border :: (text: string, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_BACKGROUND | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_toolbar_button :: (text: string, background_color: Color = .{0.1,0.1,0.1,1}, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
ui_set_next_border_width(1);
ui_set_next_border_color(.{0.5,0.5,0.5,1});
ui_set_next_background_color(background_color);
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding_left(20);
ui_set_next_padding_right(20);
ui_set_next_padding_top(5);
ui_set_next_padding_bottom(5);
//ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_BACKGROUND | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_label_animated :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_text(text);
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_text_color(text_color);
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(DEFAULT_PADDING);
box := ui_box_make(.DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
}
ui_label :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_text(text);
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_text_color(text_color);
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
//ui_set_next_padding(5);
ui_set_next_text_alignment(.CENTER_VERTICALLY);
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
}
ui_label_half_parent_x :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_text(text);
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_text_color(text_color);
ui_set_next_size_x(.PCT, 0.5);
ui_set_next_size_y(.TEXT_DIM);
//ui_set_next_padding(5);
ui_set_next_text_alignment(.CENTER_VERTICALLY);
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
}
ui_field_label :: (label: string, value: Any, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(DEFAULT_PADDING);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
{
ui_set_next_size_x(.PCT, 0.5);
ui_set_next_size_y(.CHILDREN_SUM);
left := ui_box_make(0, hash=get_hash(loc, 2));
{
ui_push_parent(left, .LEFT, .HORIZONTAL);
defer ui_pop_parent();
ui_label(label);
}
ui_set_next_size_x(.PCT, 0.5);
ui_set_next_size_y(.CHILDREN_SUM);
right := ui_box_make(0, hash=get_hash(loc, 2));
{
ui_push_parent(right, .LEFT, .HORIZONTAL);
defer ui_pop_parent();
ui_label(tprint("%", value));
}
}
ui_pop_parent();
}
ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_background_color(.{1,1,1,1});
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(ui_state.last_box, .CENTERED_VERTICALLY, .HORIZONTAL);
{
ui_label_half_parent_x(label);
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_border_color(.{0.3,0.3,0.3,1.0});
text_size := get_text_size(engine.renderer, "E", ui_state.fonts.button);
ui_set_next_size_x(.PCT, 0.5);
ui_set_next_size_y(.PIXELS, text_size.y); // TODO
ui_set_next_padding(5);
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
outer := ui_box_make(.ANIMATE_ON_HOVER | .CLICKABLE | .DRAW_BORDER, get_hash(loc, identifier));
if outer.interaction.editing {
outer.style.border_color = .{0.3,0.3,1.0,1.0};
}
ui_push_parent(outer, alignment=.LEFT, axis=.HORIZONTAL);
{
if text.count > 0 {
ui_set_next_text(<<text);
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_text_alignment(.CENTER_VERTICALLY);
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.TEXT_DIM);
text_widget := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
}
if outer.interaction.clicked {
outer.interaction.editing = true;
if engine.editor.focused_widget != null {
engine.editor.focused_widget.interaction.editing = false;
}
engine.editor.focused_widget = container;
}
if outer.interaction.editing {
if key_down(.BACKSPACE) {
if text.count > 0 {
text.count -= 1;
}
}
if key_down(.RETURN) {
outer.interaction.editing = false;
engine.editor.focused_widget = null;
}
if engine.input.has_char {
new_str := alloc_string(text.count + 1);
memcpy(new_str.data, text.data, text.count);
new_str[new_str.count-1] = xx engine.input.current_char;
free(<<text);
<<text = new_str;
}
// Cursor
ui_set_next_background_color(.{0.0,0.5,0.5,1.0});
ui_set_next_size_x(.PIXELS, 3);
ui_set_next_size_y(.PCT, 1);
cursor := ui_box_make(.DRAW_BACKGROUND, get_hash(loc, identifier));
}
}
ui_pop_parent();
}
ui_pop_parent();
}
ui_int_field :: (label: string, value: *int, identifier: s64 = 0, loc := #caller_location) {
ui_container_layout(identifier=identifier, loc=loc);
ui_set_next_size_x(.PCT, 1.0);
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
{
ui_label(label);
text_size := get_text_size(engine.renderer, tprint("%", <<value), ui_state.fonts.button);
ui_set_next_size_y(.PIXELS, text_size.y); // TODO
ui_set_next_size_x(.PCT, 0.5);
//ui_set_next_padding(5);
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
outer := ui_box_make(.ANIMATE_ON_HOVER | .CLICKABLE | .DRAW_BORDER, get_hash(loc, identifier));
if outer.interaction.editing {
outer.style.border_color = .{0.3,0.3,1.0,1.0};
}
ui_push_parent(outer, alignment=.LEFT, axis=.HORIZONTAL);
{
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_text_alignment(.CENTER_VERTICALLY);
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
text_widget := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
if outer.interaction.editing {
text_widget.text = alloc_string(text_widget._number_text.count,, allocator=temp);
memcpy(text_widget.text.data, text_widget._number_text.data.data, text_widget._number_text.count);
// Cursor
ui_set_next_background_color(.{1.0,1.0,1.0,1.0});
ui_set_next_size_x(.PIXELS, 2);
ui_set_next_size_y(.PCT, 1);
cursor := ui_box_make(.DRAW_BACKGROUND, get_hash(loc, identifier));
if key_down(.BACKSPACE) && text_widget._number_text.count > 0 {
text_widget._number_text.count -= 1;
}
if key_down(.RETURN) {
// FORMAT IT BACK!
temp_str : string;
temp_str.data = text_widget._number_text.data.data;
temp_str.count = text_widget._number_text.count;
<<value = parse_int(*temp_str);
outer.interaction.editing = false;
engine.editor.focused_widget = null;
}
if engine.input.has_char {
text_str := alloc_string(1,, allocator=temp);
text_str[0] = xx engine.input.current_char;
if text_str == {
case "0";#through;
case "1";#through;
case "2";#through;
case "3";#through;
case "4";#through;
case "5";#through;
case "6";#through;
case "7";#through;
case "8";#through;
case "9";
{
if !(text_str == "." && (array_contains(text_widget._number_text, #char ".") || text_widget._number_text.count == 0)) {
text_widget._number_text.data[text_widget._number_text.count] = text_str[0];
text_widget._number_text.count += 1;
}
}
}
}
// Ignore non-numeric characters
} else {
text_widget.text = copy_temporary_string(tprint("%", <<value));
}
if outer.interaction.clicked {
if engine.editor.focused_widget != null {
engine.editor.focused_widget.interaction.editing = false;
}
outer.interaction.editing = true;
engine.editor.focused_widget = outer;
formatted_text := copy_temporary_string(tprint("%", <<value));
memcpy(text_widget._number_text.data.data, formatted_text.data, formatted_text.count);
text_widget._number_text.count = formatted_text.count;
}
}
ui_pop_parent();
}
ui_pop_parent();
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_border_color(.{0.3,0.3,0.3,1.0});
ui_set_next_size_x(.CHILDREN_SUM, 1);
}
ui_float_field :: (label: string, value: *float, identifier: s64 = 0, loc := #caller_location) -> bool {
changed := false;
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(DEFAULT_PADDING);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(container, .CENTERED_VERTICALLY, .HORIZONTAL);
{
ui_label_half_parent_x(label);
changed |= ui_float_field(value, identifier);
}
ui_pop_parent();
return changed;
}
ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location) -> bool {
changed := false;
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_border_color(.{0.3,0.3,0.3,1.0});
ui_set_next_size_x(.CHILDREN_SUM, 1);
text_size := get_text_size(engine.renderer, "0.00", ui_state.fonts.button);
ui_set_next_size_y(.PIXELS, text_size.y); // TODO
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
outer := ui_box_make(.ANIMATE_ON_HOVER | .CLICKABLE | .DRAW_BORDER, get_hash(loc, identifier));
if outer.interaction.editing {
outer.style.border_color = .{0.3,0.3,1.0,1.0};
}
ui_push_parent(outer, alignment=.LEFT, axis=.HORIZONTAL);
{
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_text_alignment(.CENTER_VERTICALLY);
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
text_widget := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
if outer.interaction.editing {
text_widget.text = alloc_string(text_widget._number_text.count,, allocator=temp);
memcpy(text_widget.text.data, text_widget._number_text.data.data, text_widget._number_text.count);
// Cursor
ui_set_next_background_color(.{1.0,1.0,1.0,1.0});
ui_set_next_size_x(.PIXELS, 2);
ui_set_next_size_y(.PCT, 1);
cursor := ui_box_make(.DRAW_BACKGROUND, get_hash(loc, identifier));
if key_down(.BACKSPACE) && text_widget._number_text.count > 0 {
text_widget._number_text.count -= 1;
}
if key_down(.RETURN) {
// FORMAT IT BACK!
temp_str : string;
temp_str.data = text_widget._number_text.data.data;
temp_str.count = text_widget._number_text.count;
<<value = parse_float(*temp_str);
outer.interaction.editing = false;
engine.editor.focused_widget = null;
changed = true;
}
if engine.input.has_char {
text_str := alloc_string(1,, allocator=temp);
text_str[0] = xx engine.input.current_char;
if text_str == {
case "0";#through;
case "1";#through;
case "2";#through;
case "3";#through;
case "4";#through;
case "5";#through;
case "6";#through;
case "7";#through;
case "8";#through;
case "9";#through;
case "-";#through;
case "."; {
if !(text_str == "." && (array_contains(text_widget._number_text, #char ".") || text_widget._number_text.count == 0)) {
text_widget._number_text.data[text_widget._number_text.count] = text_str[0];
text_widget._number_text.count += 1;
}
}
}
}
// Ignore non-numeric characters
} else {
text_widget.text = copy_temporary_string(tprint("%", formatFloat(<<value, trailing_width=2, zero_removal=.NO)));
}
if outer.interaction.clicked {
if engine.editor.focused_widget != null {
engine.editor.focused_widget.interaction.editing = false;
}
outer.interaction.editing = true;
engine.editor.focused_widget = outer;
formatted_text := copy_temporary_string(tprint("%", formatFloat(<<value, trailing_width = 2, zero_removal=.NO)));
memcpy(text_widget._number_text.data.data, formatted_text.data, formatted_text.count);
text_widget._number_text.count = formatted_text.count;
}
//if outer.interaction.editing {
// if key_down(.BACKSPACE) {
// if text.count > 0 {
// text.count -= 1;
// }
// }
// if key_down(.RETURN) {
// outer.interaction.editing = false;
// }
// if engine.input.has_char {
// new_str := alloc_string(text.count + 1);
// memcpy(new_str.data, text.data, text.count);
// new_str[new_str.count-1] = xx engine.input.current_char;
// free(<<text);
// <<text = new_str;
// }
// // Cursor
// ui_set_next_background_color(.{0.0,0.5,0.5,1.0});
// ui_set_next_size_x(.PIXELS, 3);
// ui_set_next_size_y(.PCT, 1);
// cursor := ui_box_make(.DRAW_BACKGROUND, get_hash(loc, identifier));
//
}
ui_pop_parent();
return changed;
}
ui_vector_field :: (label: string, value: *Vector3, identifier: s64 = 0, loc := #caller_location) -> bool {
changed := false;
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(DEFAULT_PADDING);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(container, .CENTERED_VERTICALLY, .HORIZONTAL);
{
ui_label_half_parent_x(label);
//ui_set_next_size_x(.PCT, 0.5);
//ui_set_next_size_y(.CHILDREN_SUM);
//container := ui_box_make(0, get_hash(loc, 123));
//ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
ui_label("X");
ui_space(5,0);
changed |= ui_float_field(*value.x);
ui_space(5,0);
ui_label("Y");
ui_space(5,0);
changed |= ui_float_field(*value.y);
ui_space(5,0);
ui_label("Z");
ui_space(5,0);
changed |= ui_float_field(*value.z);
//ui_pop_parent();
}
ui_pop_parent();
return changed;
}
ui_clickable_label :: (text: string, selected: bool = false, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
if selected {
ui_set_next_background_color(.{0.5,0.5,0.5,1.0});
} else {
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
}
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.PCT, 1);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
box := ui_box_make(.DRAW_BACKGROUND | .DRAW_TEXT | .ANIMATE_ON_HOVER | .CLICKABLE, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_toolbar :: (identifier: s64 = 0, loc := #caller_location) {
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_size_x(.PIXELS, xx engine.renderer.render_target_width);
ui_set_next_size_y(.CHILDREN_SUM);
box := ui_box_make(.DRAW_BACKGROUND | .DRAW_BORDER, get_hash(loc, identifier));
}
ui_tab_title_bar :: (title: string, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_background_color(.{0.03, 0.03, 0.03, 1.0});
ui_set_next_padding(DEFAULT_PADDING);
ui_set_next_size_y(.CHILDREN_SUM);
parent := ui_box_make(.DRAW_BACKGROUND | .DRAW_BORDER, get_hash(loc, identifier));
ui_push_parent(parent, alignment=.LEFT, axis=.VERTICAL);
{
ui_set_next_text_alignment(.CENTER_VERTICALLY);
ui_set_next_text(title);
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
text := ui_box(.DRAW_TEXT);
}
ui_pop_parent();
}
ui_texture :: (texture: Texture_Handle, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_texture(texture);
ui_set_next_background_color(.{0.1,0.1,0.1,1});
box := ui_box_make(.DRAW_BACKGROUND | .DRAW_BORDER, get_hash(loc, identifier));
}
ui_interactable_texture :: (texture: Texture_Handle, identifier: s64 = 0, loc := #caller_location) -> Interaction_State {
ui_set_next_texture(texture);
ui_set_next_background_color(.{0.1,0.1,0.1,1});
box := ui_box_make(.DRAW_BACKGROUND | .CLICKABLE | .PLAY_MODE_FOCUSABLE, get_hash(loc, identifier));
return box.interaction;
}
ui_space :: (width: float, height: float, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_background_color(.{0,0,0,0});
ui_set_next_size_x(.PIXELS, width);
ui_set_next_size_y(.PIXELS, height);
box := ui_box_make(.NONE, get_hash(loc, identifier));
}
ui_slider :: (value: *float, min: float = 0.0, max: float = 1.0, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.PIXELS, 15);
ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
ui_set_next_text(tprint("%", <<value));
box := ui_box_make(.DRAW_BACKGROUND | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
ui_push_parent(box, alignment=.LEFT, axis=.HORIZONTAL);
{
percentage := (<<value - min) / (max - min);
ui_set_next_size_x(.PCT, percentage * 0.95);
ui_set_next_size_y(.PCT, 1.0);
ui_box(.NONE);
ui_set_next_size_x(.PCT, 0.05);
ui_set_next_size_y(.PCT, 1.0);
ui_set_next_background_color(.{0.5,0.5,0.5,1});
draggable := ui_box(.DRAW_BACKGROUND | .CLICKABLE | .ANIMATE_ON_HOVER);
mouse_delta_x := engine.input.mouse.delta_x;
if draggable.interaction.left_mouse_pressed {
increment := (max - min) / box.rect.w;
<<value = clamp(<<value + mouse_delta_x * increment, min, max);
}
}
ui_pop_parent();
}
#load "ui.jai";