UI fun
This commit is contained in:
@@ -55,7 +55,7 @@ MAX_CHILDREN :: 16;
|
|||||||
Entity :: struct {
|
Entity :: struct {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
id: Entity_Id; @Hide @DontSerialize
|
id: Entity_Id; @ReadOnly @DontSerialize
|
||||||
type : Type;
|
type : Type;
|
||||||
|
|
||||||
enabled: bool = true;
|
enabled: bool = true;
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ editor_ui :: () {
|
|||||||
entity := engine.editor.selected_entities[0];
|
entity := engine.editor.selected_entities[0];
|
||||||
//ui_slider(*slider_value, 0.0, 1.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);
|
//updated := ui_vector_field("Position", *entity.transform.position);
|
||||||
//euler_rotation := quaternion_to_euler_v3(entity.transform.orientation);
|
//euler_rotation := quaternion_to_euler_v3(entity.transform.orientation);
|
||||||
|
|||||||
@@ -119,9 +119,18 @@ should_make_ui :: (type: *Type_Info_Struct, member: Type_Info_Struct_Member) ->
|
|||||||
return true;
|
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 = "") {
|
generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path: string = "") {
|
||||||
for type.members {
|
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;
|
new_path : string;
|
||||||
if it.name != "entity" {
|
if it.name != "entity" {
|
||||||
if path.count == 0 {
|
if path.count == 0 {
|
||||||
@@ -131,15 +140,18 @@ generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type : Type_Info_Tag;
|
tag : Type_Info_Tag;
|
||||||
if it.type.type == .VARIANT {
|
if it.type.type == .VARIANT {
|
||||||
info_variant := cast(*Type_Info_Variant)it.type;
|
info_variant := cast(*Type_Info_Variant)it.type;
|
||||||
type = info_variant.variant_of.type;
|
tag = info_variant.variant_of.type;
|
||||||
} else {
|
} else {
|
||||||
type = it.type.type;
|
tag = it.type.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
if type == {
|
if readonly {
|
||||||
|
print_to_builder(builder, "\tui_field_label(\"%\", e.%);\n", new_path, new_path);
|
||||||
|
} else {
|
||||||
|
if tag == {
|
||||||
case .STRUCT; {
|
case .STRUCT; {
|
||||||
info_struct := cast(*Type_Info_Struct) it.type;
|
info_struct := cast(*Type_Info_Struct) it.type;
|
||||||
if info_struct.name == "Quaternion" {
|
if info_struct.name == "Quaternion" {
|
||||||
@@ -169,6 +181,7 @@ generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
generate_member_serialization :: (type: *Type_Info_Struct, builder: *String_Builder, path: string = "") {
|
generate_member_serialization :: (type: *Type_Info_Struct, builder: *String_Builder, path: string = "") {
|
||||||
for type.members {
|
for type.members {
|
||||||
|
|||||||
13
ui/ui.jai
13
ui/ui.jai
@@ -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
|
// Find final positions
|
||||||
for *box : ui_state.boxes {
|
for *box : ui_state.boxes {
|
||||||
@@ -656,8 +664,13 @@ ui_set_rect_recursively :: (parent: *UI_Box) {
|
|||||||
while child != null {
|
while child != null {
|
||||||
defer child = child.next;
|
defer child = child.next;
|
||||||
|
|
||||||
|
if parent.layout.alignment == .CENTERED {
|
||||||
|
|
||||||
|
} else {
|
||||||
child.rect.x = starting_offset_x;
|
child.rect.x = starting_offset_x;
|
||||||
child.rect.y = starting_offset_y;
|
child.rect.y = starting_offset_y;
|
||||||
|
}
|
||||||
|
|
||||||
child.rect.w = child.size.x;
|
child.rect.w = child.size.x;
|
||||||
child.rect.h = child.size.y;
|
child.rect.h = child.size.y;
|
||||||
|
|
||||||
|
|||||||
@@ -61,11 +61,11 @@ ui_checkbox_field :: (label: string, value: *bool, identifier: s64 = 0, loc := #
|
|||||||
changed := false;
|
changed := false;
|
||||||
ui_set_next_size_x(.PCT, 1.0);
|
ui_set_next_size_x(.PCT, 1.0);
|
||||||
ui_set_next_size_y(.CHILDREN_SUM);
|
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));
|
container := ui_box_make(0, hash=get_hash(loc, identifier));
|
||||||
ui_push_parent(container, .LEFT, .HORIZONTAL);
|
ui_push_parent(container, .LEFT, .HORIZONTAL);
|
||||||
{
|
{
|
||||||
ui_label_half_parent(label);
|
ui_label(label);
|
||||||
ui_checkbox(value, identifier);
|
ui_checkbox(value, identifier);
|
||||||
}
|
}
|
||||||
ui_pop_parent();
|
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_text_color(text_color);
|
||||||
ui_set_next_size_x(.TEXT_DIM);
|
ui_set_next_size_x(.TEXT_DIM);
|
||||||
ui_set_next_size_y(.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));
|
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_field_label :: (label: string, value: Any, identifier: s64 = 0, loc := #caller_location) {
|
||||||
ui_set_next_text(text);
|
ui_set_next_size_x(.PCT, 1.0);
|
||||||
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
|
|
||||||
ui_set_next_text_color(text_color);
|
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_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
|
||||||
|
{
|
||||||
ui_set_next_size_x(.PCT, 0.5);
|
ui_set_next_size_x(.PCT, 0.5);
|
||||||
ui_set_next_size_y(.TEXT_DIM);
|
ui_set_next_size_y(.CHILDREN_SUM);
|
||||||
ui_set_next_padding(5);
|
left := ui_box_make(0, hash=get_hash(loc, 2));
|
||||||
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
{
|
||||||
|
ui_push_parent(left, .LEFT, .HORIZONTAL);
|
||||||
|
defer ui_pop_parent();
|
||||||
|
ui_label(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
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_x(.PCT, 0.5);
|
||||||
ui_set_next_size_y(.TEXT_DIM);
|
ui_set_next_size_y(.CHILDREN_SUM);
|
||||||
ui_set_next_padding(5);
|
right := ui_box_make(0, hash=get_hash(loc, 2));
|
||||||
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
{
|
||||||
|
ui_push_parent(right, .LEFT, .HORIZONTAL);
|
||||||
|
defer ui_pop_parent();
|
||||||
|
ui_label(tprint("%", value));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ui_label_fill_parent_x :: (text: string, identifier: s64 = 0, loc := #caller_location) {
|
ui_pop_parent();
|
||||||
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_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #caller_location) {
|
ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #caller_location) {
|
||||||
ui_set_next_size_x(.PCT, 1.0);
|
ui_set_next_size_x(.PCT, 1.0);
|
||||||
ui_set_next_size_y(.CHILDREN_SUM);
|
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));
|
container := ui_box_make(0, hash=get_hash(loc, identifier));
|
||||||
|
|
||||||
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
|
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_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_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_set_next_size_x(.PCT, 1.0);
|
||||||
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
|
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);
|
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 {
|
ui_float_field :: (label: string, value: *float, identifier: s64 = 0, loc := #caller_location) -> bool {
|
||||||
changed := false;
|
changed := false;
|
||||||
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_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);
|
ui_label(label);
|
||||||
changed |= ui_float_field(value, identifier);
|
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 {
|
ui_vector_field :: (label: string, value: *Vector3, identifier: s64 = 0, loc := #caller_location) -> bool {
|
||||||
changed := false;
|
changed := false;
|
||||||
ui_set_next_size_x(.PCT, 1.0);
|
ui_set_next_size_x(.PCT, 1.0);
|
||||||
ui_set_next_size_y(.TEXT_DIM);
|
ui_set_next_size_y(.CHILDREN_SUM);
|
||||||
ui_container_layout(identifier=identifier, loc=loc);
|
ui_set_next_padding(2.0);
|
||||||
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
|
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_x(.PCT, 0.5);
|
||||||
//ui_set_next_size_y(.CHILDREN_SUM);
|
//ui_set_next_size_y(.CHILDREN_SUM);
|
||||||
|
|||||||
Reference in New Issue
Block a user