entity_ui_proc generation
This commit is contained in:
101
ui/widgets.jai
101
ui/widgets.jai
@@ -184,6 +184,107 @@ ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #call
|
||||
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(.CHILDREN_SUM);
|
||||
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(.CHILDREN_SUM);
|
||||
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 :: (value: *float, identifier: s64 = 0, loc := #caller_location) {
|
||||
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});
|
||||
|
||||
Reference in New Issue
Block a user