Float fields working
This commit is contained in:
@@ -195,18 +195,69 @@ ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location)
|
||||
|
||||
ui_push_parent(outer, alignment=.LEFT, axis=.HORIZONTAL);
|
||||
{
|
||||
//text.count > 0 {
|
||||
ui_set_next_text(tprint("%", <<value));
|
||||
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));
|
||||
//}
|
||||
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;
|
||||
}
|
||||
|
||||
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 "."; {
|
||||
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 {
|
||||
outer.interaction.editing = true;
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user