UI clean-up
This commit is contained in:
@@ -79,7 +79,7 @@ Entity :: struct {
|
||||
animator: Animator; @DontSerialize
|
||||
|
||||
// Physics
|
||||
body : Physics_Body; @DontSerialize
|
||||
body : Physics_Body;
|
||||
collider : Collider;
|
||||
// End physics
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ pick_scene_view_at :: (camera: Camera, coordinates: Vector2) {
|
||||
}
|
||||
}
|
||||
|
||||
test := false;
|
||||
|
||||
editor_ui :: () {
|
||||
// Scene picking
|
||||
if !ui_mouse_over_window() {
|
||||
@@ -57,7 +55,6 @@ editor_ui :: () {
|
||||
}
|
||||
|
||||
ui_window_begin("Entities", 1, 5, 200, 600);
|
||||
ui_checkbox(*test);
|
||||
if engine.current_scene != null {
|
||||
for engine.current_scene.entities {
|
||||
if it.flags & .DELETED continue;
|
||||
@@ -122,10 +119,6 @@ editor_ui :: () {
|
||||
|
||||
if engine.editor.selected_entities.count == 1 {
|
||||
entity := engine.editor.selected_entities[0];
|
||||
//ui_slider(*slider_value, 0.0, 1.0);
|
||||
|
||||
//ui_label(tprint("Id: %", entity.id));
|
||||
|
||||
//updated := ui_vector_field("Position", *entity.transform.position);
|
||||
//euler_rotation := quaternion_to_euler_v3(entity.transform.orientation);
|
||||
//euler_rotation *= RADIANS_TO_DEGREES;
|
||||
@@ -137,7 +130,6 @@ editor_ui :: () {
|
||||
//if updated {
|
||||
// update_matrix(*entity.transform);
|
||||
//}
|
||||
|
||||
entity_ui(entity);
|
||||
}
|
||||
ui_window_end();
|
||||
|
||||
@@ -71,6 +71,11 @@ should_serialize :: (type: *Type_Info_Struct, member: Type_Info_Struct_Member) -
|
||||
case; return false;
|
||||
}
|
||||
}
|
||||
case "Static_Array"; #through;
|
||||
case "PArray"; #through;
|
||||
case "Stack"; #through;
|
||||
case "Queue";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,8 +159,8 @@ generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path:
|
||||
if tag == {
|
||||
case .STRUCT; {
|
||||
info_struct := cast(*Type_Info_Struct) it.type;
|
||||
if info_struct.name == "Quaternion" {
|
||||
|
||||
if info_struct.name == "Transform" {
|
||||
print_to_builder(builder, TRANSFORM_UI);
|
||||
}
|
||||
else if info_struct.name == "Vector3" {
|
||||
print_to_builder(builder, "\tui_vector_field(tprint(\"%\"), *e.%);\n", new_path, new_path);
|
||||
@@ -183,6 +188,21 @@ generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TRANSFORM_UI :: #string DONE
|
||||
updated := ui_vector_field("Position", *e.transform.position);
|
||||
euler_rotation := quaternion_to_euler_v3(e.transform.orientation);
|
||||
euler_rotation *= RADIANS_TO_DEGREES;
|
||||
updated |= ui_vector_field("Rotation", *euler_rotation);
|
||||
euler_rotation *= DEGREES_TO_RADIANS;
|
||||
e.transform.orientation = euler_to_quaternion(euler_rotation);
|
||||
updated |= ui_vector_field("Scale", *e.transform.scale);
|
||||
|
||||
if updated {
|
||||
update_matrix(*e.transform);
|
||||
}
|
||||
DONE
|
||||
|
||||
generate_member_serialization :: (type: *Type_Info_Struct, builder: *String_Builder, path: string = "") {
|
||||
for type.members {
|
||||
if should_serialize(type, it) {
|
||||
|
||||
@@ -64,14 +64,14 @@ Collider :: struct {
|
||||
|
||||
Physics_Body :: struct {
|
||||
enabled: bool = true;
|
||||
velocity: Vector3;
|
||||
velocity: Vector3; @DontSerialize
|
||||
|
||||
friction : float = 0.0;
|
||||
bounciness : float = 0.0;
|
||||
linear_damping : float = 0.0;
|
||||
friction : float = 0.0; @DontSerialize
|
||||
bounciness : float = 0.0; @DontSerialize
|
||||
linear_damping : float = 0.0; @DontSerialize
|
||||
|
||||
check_for_grounded: bool;
|
||||
grounded: bool;
|
||||
check_for_grounded: bool; @DontSerialize
|
||||
grounded: bool; @DontSerialize
|
||||
}
|
||||
|
||||
update_mesh_collider :: (e: *Entity) {
|
||||
|
||||
13
ui/ui.jai
13
ui/ui.jai
@@ -3,6 +3,7 @@ MAX_BOXES :: 4096;
|
||||
MAX_WINDOWS :: 128;
|
||||
|
||||
SCROLL_SPEED :: 5;
|
||||
DEFAULT_PADDING :: 5;
|
||||
|
||||
WINDOW_TITLE_BAR_HEIGHT :: 20.0;
|
||||
WINDOW_BORDER_WIDTH :: 3;
|
||||
@@ -109,7 +110,7 @@ UI_Child_Axis :: enum {
|
||||
UI_Child_Alignment :: enum {
|
||||
LEFT;
|
||||
RIGHT;
|
||||
CENTERED;
|
||||
CENTERED_VERTICALLY;
|
||||
}
|
||||
|
||||
UI_Text_Alignment_Flags :: enum_flags u8 {
|
||||
@@ -664,8 +665,9 @@ ui_set_rect_recursively :: (parent: *UI_Box) {
|
||||
while child != null {
|
||||
defer child = child.next;
|
||||
|
||||
if parent.layout.alignment == .CENTERED {
|
||||
|
||||
if parent.layout.alignment == .CENTERED_VERTICALLY {
|
||||
child.rect.x = starting_offset_x;
|
||||
child.rect.y = parent.rect.y + parent.rect.h / 2 - child.rect.h / 2;
|
||||
} else {
|
||||
child.rect.x = starting_offset_x;
|
||||
child.rect.y = starting_offset_y;
|
||||
@@ -851,11 +853,12 @@ ui_render :: () {
|
||||
{
|
||||
if window.title.count > 0 {
|
||||
font_handle := ui_state.fonts.regular;
|
||||
x : float = cast(float)(xx window.actual_position.x + cast(u32)WINDOW_BORDER_WIDTH + 2);
|
||||
x : float = cast(float)(xx window.actual_position.x + cast(u32)WINDOW_BORDER_WIDTH + DEFAULT_PADDING);
|
||||
y : float = (cast(float)engine.renderer.render_target_height - (window.actual_position.y + WINDOW_BORDER_WIDTH + 2.0));
|
||||
|
||||
text_size := get_text_size(engine.renderer, window.title, font_handle);
|
||||
y -= text_size.y;
|
||||
y -= text_size.y / 2 + (WINDOW_TITLE_BAR_HEIGHT - WINDOW_BORDER_WIDTH) / 2;
|
||||
y = round(y);
|
||||
render_data := bake_text(engine.renderer, x, y, window.title, font_handle, .{1,1,1,1});
|
||||
font := *engine.renderer.fonts[font_handle - 1];
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ ui_button :: (text: string, identifier: s64 = 0, loc := #caller_location) -> cli
|
||||
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(5);
|
||||
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;
|
||||
@@ -34,7 +34,6 @@ ui_checkbox :: (checked: *bool, identifier: s64 = 0, loc := #caller_location) ->
|
||||
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_padding(5);
|
||||
//ui_set_next_text_alignment(CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
|
||||
|
||||
@@ -61,11 +60,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(2.0);
|
||||
ui_set_next_padding(DEFAULT_PADDING);
|
||||
container := ui_box_make(0, hash=get_hash(loc, identifier));
|
||||
ui_push_parent(container, .LEFT, .HORIZONTAL);
|
||||
{
|
||||
ui_label(label);
|
||||
ui_label_half_parent_x(label);
|
||||
ui_checkbox(value, identifier);
|
||||
}
|
||||
ui_pop_parent();
|
||||
@@ -87,7 +86,7 @@ ui_button_no_bg :: (text: string, identifier: s64 = 0, loc := #caller_location)
|
||||
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(5);
|
||||
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;
|
||||
@@ -99,7 +98,7 @@ ui_button_no_border :: (text: string, identifier: s64 = 0, loc := #caller_locati
|
||||
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(5);
|
||||
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;
|
||||
@@ -128,7 +127,7 @@ ui_label_animated :: (text: string, text_color: Color = .{1,1,1,1}, identifier:
|
||||
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(DEFAULT_PADDING);
|
||||
box := ui_box_make(.DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
|
||||
}
|
||||
|
||||
@@ -143,12 +142,22 @@ ui_label :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0,
|
||||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
@@ -176,13 +185,13 @@ ui_field_label :: (label: string, value: Any, identifier: s64 = 0, loc := #calle
|
||||
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_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, .LEFT, .HORIZONTAL);
|
||||
ui_push_parent(ui_state.last_box, .CENTERED_VERTICALLY, .HORIZONTAL);
|
||||
{
|
||||
ui_label(label);
|
||||
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});
|
||||
|
||||
@@ -358,11 +367,11 @@ ui_float_field :: (label: string, value: *float, identifier: s64 = 0, loc := #ca
|
||||
changed := false;
|
||||
ui_set_next_size_x(.PCT, 1.0);
|
||||
ui_set_next_size_y(.CHILDREN_SUM);
|
||||
ui_set_next_padding(2.0);
|
||||
ui_set_next_padding(DEFAULT_PADDING);
|
||||
container := ui_box_make(0, hash=get_hash(loc, identifier));
|
||||
ui_push_parent(container, .LEFT, .HORIZONTAL);
|
||||
ui_push_parent(container, .CENTERED_VERTICALLY, .HORIZONTAL);
|
||||
{
|
||||
ui_label(label);
|
||||
ui_label_half_parent_x(label);
|
||||
changed |= ui_float_field(value, identifier);
|
||||
}
|
||||
ui_pop_parent();
|
||||
@@ -379,7 +388,7 @@ ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location)
|
||||
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(5);
|
||||
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));
|
||||
@@ -498,11 +507,11 @@ ui_vector_field :: (label: string, value: *Vector3, 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(2.0);
|
||||
ui_set_next_padding(DEFAULT_PADDING);
|
||||
container := ui_box_make(0, hash=get_hash(loc, identifier));
|
||||
ui_push_parent(container, .LEFT, .HORIZONTAL);
|
||||
ui_push_parent(container, .CENTERED_VERTICALLY, .HORIZONTAL);
|
||||
{
|
||||
ui_label(label);
|
||||
ui_label_half_parent_x(label);
|
||||
|
||||
//ui_set_next_size_x(.PCT, 0.5);
|
||||
//ui_set_next_size_y(.CHILDREN_SUM);
|
||||
@@ -511,10 +520,15 @@ ui_vector_field :: (label: string, value: *Vector3, identifier: s64 = 0, loc :=
|
||||
//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();
|
||||
@@ -534,7 +548,7 @@ ui_clickable_label :: (text: string, selected: bool = false, identifier: s64 = 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_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;
|
||||
@@ -549,7 +563,7 @@ ui_toolbar :: (identifier: s64 = 0, loc := #caller_location) {
|
||||
|
||||
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(5);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user