UI windows
This commit is contained in:
@@ -231,14 +231,14 @@ smooth_damp :: (current: float, target: float, current_velocity: *float, smooth_
|
||||
change = clamp(change, -max_change, max_change);
|
||||
target = current - change;
|
||||
|
||||
temp := (<<current_velocity + omega * change) * delta_time;
|
||||
<<current_velocity = (<<current_velocity - omega * temp) * exp;
|
||||
temp := (current_velocity.* + omega * change) * delta_time;
|
||||
current_velocity.* = (current_velocity.* - omega * temp) * exp;
|
||||
output := target + (change + temp) * exp;
|
||||
|
||||
// Prevent overshooting
|
||||
if (original_to - current > 0.0) == (output > original_to) {
|
||||
output = original_to;
|
||||
<<current_velocity = (output - original_to) / delta_time;
|
||||
current_velocity.* = (output - original_to) / delta_time;
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
@@ -39,8 +39,8 @@ parray_add :: (using parray: *PArray, value: parray.Data_Type) -> parray.Handle_
|
||||
|
||||
// find the next empty index
|
||||
for *val, i: indices {
|
||||
if <<val == 0 {
|
||||
<<val = index;
|
||||
if val.* == 0 {
|
||||
val.* = index;
|
||||
handle = cast(Handle_Type)i + 1;
|
||||
break;
|
||||
}
|
||||
@@ -66,8 +66,8 @@ parray_remove :: (using parray: *PArray, handle: parray.Handle_Type) {
|
||||
data[index] = data[data.count-1];
|
||||
|
||||
for * indices {
|
||||
if <<it == data.count {
|
||||
<<it = index + 1;
|
||||
if it.* == data.count {
|
||||
it.* = index + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ for_expansion :: (parray: *PArray, body: Code, flags: For_Flags) #expand {
|
||||
#if flags & .POINTER {
|
||||
`it := value;
|
||||
} else {
|
||||
`it := <<value;
|
||||
`it := value.*;
|
||||
}
|
||||
#insert body;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ pick_scene_view_at :: (camera: Camera, coordinates: Vector2) {
|
||||
}
|
||||
|
||||
editor_ui :: () {
|
||||
ui_window_begin("Entities");
|
||||
ui_label("TESTING ONE TWO", .{0,0.7,0,1});
|
||||
ui_window_end();
|
||||
|
||||
ui_full_size_background();
|
||||
ui_push_parent(ui_state.last_box, alignment=.LEFT, axis=.VERTICAL);
|
||||
{
|
||||
|
||||
57
ui/ui.jai
57
ui/ui.jai
@@ -1,5 +1,6 @@
|
||||
MAX_VERT_BUFFERS :: 64;
|
||||
MAX_BOXES :: 4096;
|
||||
MAX_WINDOWS :: 128;
|
||||
|
||||
UI_Box_Flags :: enum_flags u32 {
|
||||
NONE :: 0;
|
||||
@@ -49,6 +50,7 @@ UI_Box :: struct {
|
||||
hash: u32;
|
||||
last_used_frame_index: u64;
|
||||
|
||||
root_for_window: *UI_Window;
|
||||
parent: *UI_Box;
|
||||
first_child: *UI_Box;
|
||||
last_child: *UI_Box;
|
||||
@@ -129,12 +131,25 @@ Textured_Vert_Buffer :: struct {
|
||||
verts: [6] Textured_Vert;
|
||||
}
|
||||
|
||||
UI_Window :: struct {
|
||||
hash: u32;
|
||||
root: *UI_Box;
|
||||
|
||||
title: string;
|
||||
position: Vector2;
|
||||
size: Vector2;
|
||||
|
||||
last_used_frame_index: u64;
|
||||
}
|
||||
|
||||
UI_State :: struct {
|
||||
begun: bool;
|
||||
frame_index: u64;
|
||||
|
||||
root: *UI_Box;
|
||||
boxes: Table(u32, UI_Box);
|
||||
windows: Table(u32, UI_Window);
|
||||
current_window: *UI_Window;
|
||||
|
||||
last_box: *UI_Box;
|
||||
|
||||
@@ -171,6 +186,22 @@ UI_State :: struct {
|
||||
|
||||
ui_state : UI_State;
|
||||
|
||||
ui_window_make :: (title: string, hash: u32) -> *UI_Window {
|
||||
window := get_ui_window_or_create_new(hash);
|
||||
return window;
|
||||
}
|
||||
|
||||
ui_window_begin :: (title: string, identifier: s64 = 0, loc := #caller_location) {
|
||||
assert(ui_state.current_window == null);
|
||||
|
||||
ui_state.current_window = ui_window_make(title, hash=get_hash(loc, identifier));
|
||||
ui_state.current_window.last_used_frame_index = ui_state.frame_index;
|
||||
}
|
||||
|
||||
ui_window_end :: () {
|
||||
ui_state.current_window = null;
|
||||
}
|
||||
|
||||
ui_box :: (flags: UI_Box_Flags, identifier: s64 = 0, loc := #caller_location) -> *UI_Box {
|
||||
return ui_box_make(flags, hash=get_hash(loc, identifier));
|
||||
}
|
||||
@@ -194,6 +225,15 @@ ui_box_make :: (flags: UI_Box_Flags, hash: u32) -> *UI_Box {
|
||||
box.num_children = 0;
|
||||
box.flags = flags;
|
||||
box.parent = null;
|
||||
box.root_for_window = null;
|
||||
|
||||
if ui_state.current_window {
|
||||
if ui_state.current_window.root == null {
|
||||
ui_state.current_window.root = box;
|
||||
box.root_for_window = ui_state.current_window;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set the links
|
||||
box.parent = parent;
|
||||
@@ -728,9 +768,24 @@ get_ui_box_or_create_new :: (hash: u32) -> *UI_Box, bool {
|
||||
|
||||
ptr.hash = hash;
|
||||
|
||||
return ptr, false;
|
||||
|
||||
|
||||
return ptr, false;
|
||||
}
|
||||
|
||||
get_ui_window_or_create_new :: (hash: u32) -> *UI_Window, bool {
|
||||
ptr := table_find_pointer(*ui_state.windows, hash);
|
||||
|
||||
if ptr == null {
|
||||
assert(ui_state.windows.count < MAX_WINDOWS);
|
||||
table_add(*ui_state.windows, hash, .{});
|
||||
ptr = table_find_pointer(*ui_state.windows, hash);
|
||||
}
|
||||
|
||||
ptr.hash = hash;
|
||||
|
||||
return ptr, false;
|
||||
}
|
||||
// #### RENDERING
|
||||
make_vert :: (x: float, y: float, color: Color) -> Colored_Vert {
|
||||
vert : Colored_Vert;
|
||||
|
||||
Reference in New Issue
Block a user