This commit is contained in:
2025-01-02 16:35:53 +01:00
parent 834de24444
commit 03b84515e7
5 changed files with 100 additions and 68 deletions

View File

@@ -55,7 +55,7 @@ MAX_CHILDREN :: 16;
Entity :: struct {
name: string;
id: Entity_Id; @Hide @DontSerialize
id: Entity_Id; @ReadOnly @DontSerialize
type : Type;
enabled: bool = true;

View File

@@ -124,7 +124,7 @@ editor_ui :: () {
entity := engine.editor.selected_entities[0];
//ui_slider(*slider_value, 0.0, 1.0);
ui_label(tprint("Id: %", entity.id));
//ui_label(tprint("Id: %", entity.id));
//updated := ui_vector_field("Position", *entity.transform.position);
//euler_rotation := quaternion_to_euler_v3(entity.transform.orientation);

View File

@@ -119,9 +119,18 @@ should_make_ui :: (type: *Type_Info_Struct, member: Type_Info_Struct_Member) ->
return true;
}
is_readonly :: (type: *Type_Info_Struct, member: Type_Info_Struct_Member) -> bool {
for member.notes {
if to_lower_copy(it,, allocator = temp) == "readonly" return true;
}
return false;
}
generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path: string = "") {
for type.members {
if should_make_ui(type, it) && should_serialize(type, it) {
readonly := is_readonly(type, it);
if should_make_ui(type, it) && (should_serialize(type, it) || readonly) {
new_path : string;
if it.name != "entity" {
if path.count == 0 {
@@ -131,39 +140,43 @@ generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path:
}
}
type : Type_Info_Tag;
tag : Type_Info_Tag;
if it.type.type == .VARIANT {
info_variant := cast(*Type_Info_Variant)it.type;
type = info_variant.variant_of.type;
tag = info_variant.variant_of.type;
} else {
type = it.type.type;
tag = it.type.type;
}
if type == {
case .STRUCT; {
info_struct := cast(*Type_Info_Struct) it.type;
if info_struct.name == "Quaternion" {
if readonly {
print_to_builder(builder, "\tui_field_label(\"%\", e.%);\n", new_path, new_path);
} else {
if tag == {
case .STRUCT; {
info_struct := cast(*Type_Info_Struct) it.type;
if info_struct.name == "Quaternion" {
}
else if info_struct.name == "Vector3" {
print_to_builder(builder, "\tui_vector_field(tprint(\"%\"), *e.%);\n", new_path, new_path);
} else {
generate_member_ui(info_struct, builder, new_path);
}
}
else if info_struct.name == "Vector3" {
print_to_builder(builder, "\tui_vector_field(tprint(\"%\"), *e.%);\n", new_path, new_path);
} else {
generate_member_ui(info_struct, builder, new_path);
case .BOOL; {
print_to_builder(builder, "\tui_checkbox_field(tprint(\"%\"), *e.%);\n", new_path, new_path);
}
case .STRING; {
print_to_builder(builder, "\tui_textfield(tprint(\"%\"), *e.%);\n", new_path, new_path);
//ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #caller_location) {
}
case .FLOAT; {
print_to_builder(builder, "\tui_float_field(tprint(\"%\"), *e.%);\n", new_path, new_path);
}
//case .ENUM; #through;
case .INTEGER; {
print_to_builder(builder, "\tui_int_field(tprint(\"%\"), cast(*int)*e.%);\n", new_path, new_path);
}
}
case .BOOL; {
print_to_builder(builder, "\tui_checkbox_field(tprint(\"%\"), *e.%);\n", new_path, new_path);
}
case .STRING; {
print_to_builder(builder, "\tui_textfield(tprint(\"%\"), *e.%);\n", new_path, new_path);
//ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #caller_location) {
}
case .FLOAT; {
print_to_builder(builder, "\tui_float_field(tprint(\"%\"), *e.%);\n", new_path, new_path);
}
//case .ENUM; #through;
case .INTEGER; {
print_to_builder(builder, "\tui_int_field(tprint(\"%\"), cast(*int)*e.%);\n", new_path, new_path);
}
}
}

View File

@@ -582,6 +582,14 @@ ui_figure_out_sizes :: () {
}
}
// Align children in parent
//for *box: ui_state.boxes {
// if box.parent != null {
// if box.parent.rect.h > box.rect.h && box.parent.layout.alignment == .CENTERED {
// box.rect.y = box.rect.y
// }
// }
//}
// Find final positions
for *box : ui_state.boxes {
@@ -656,8 +664,13 @@ ui_set_rect_recursively :: (parent: *UI_Box) {
while child != null {
defer child = child.next;
child.rect.x = starting_offset_x;
child.rect.y = starting_offset_y;
if parent.layout.alignment == .CENTERED {
} else {
child.rect.x = starting_offset_x;
child.rect.y = starting_offset_y;
}
child.rect.w = child.size.x;
child.rect.h = child.size.y;

View File

@@ -61,11 +61,11 @@ ui_checkbox_field :: (label: string, value: *bool, identifier: s64 = 0, loc := #
changed := false;
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(5.0);
ui_set_next_padding(2.0);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(container, .LEFT, .HORIZONTAL);
{
ui_label_half_parent(label);
ui_label(label);
ui_checkbox(value, identifier);
}
ui_pop_parent();
@@ -138,49 +138,51 @@ ui_label :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 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_padding(5);
ui_set_next_text_alignment(.CENTER_VERTICALLY);
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
}
ui_label_half_parent :: (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);
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_label_for_fields :: (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);
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
}
text_size := get_text_size(engine.renderer, label, ui_state.fonts.button);
ui_set_next_size_y(.PIXELS, text_size.y);
//ui_set_next_padding(2.0);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_label_fill_parent_x :: (text: string, 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(.{1,1,1,1});
ui_set_next_size_x(.PCT, 1);
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 | .ANIMATE_ON_HOVER, 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(2.0);
//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, .LEFT, .HORIZONTAL);
{
ui_label_half_parent(label);
ui_label(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});
@@ -256,7 +258,7 @@ ui_int_field :: (label: string, value: *int, identifier: s64 = 0, loc := #caller
ui_set_next_size_x(.PCT, 1.0);
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
{
ui_label_half_parent(label);
ui_label(label);
text_size := get_text_size(engine.renderer, tprint("%", <<value), ui_state.fonts.button);
@@ -354,8 +356,11 @@ ui_int_field :: (label: string, value: *int, identifier: s64 = 0, loc := #caller
ui_float_field :: (label: string, value: *float, identifier: s64 = 0, loc := #caller_location) -> bool {
changed := false;
ui_container_layout(identifier=identifier, loc=loc);
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(2.0);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(container, .LEFT, .HORIZONTAL);
{
ui_label(label);
changed |= ui_float_field(value, identifier);
@@ -492,11 +497,12 @@ ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location)
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(.TEXT_DIM);
ui_container_layout(identifier=identifier, loc=loc);
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(2.0);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(container, .LEFT, .HORIZONTAL);
{
ui_label_for_fields(label);
ui_label(label);
//ui_set_next_size_x(.PCT, 0.5);
//ui_set_next_size_y(.CHILDREN_SUM);