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