aboutsummaryrefslogtreecommitdiff
path: root/src/ui_panel.jai
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui_panel.jai')
-rw-r--r--src/ui_panel.jai24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/ui_panel.jai b/src/ui_panel.jai
index cc0a2e2..c27b40d 100644
--- a/src/ui_panel.jai
+++ b/src/ui_panel.jai
@@ -9,6 +9,7 @@ UI_Element :: struct {
x0, y0, x1, y1: float;
label: string;
input_buf: *[..] u8;
+ text_filter: (char: u32) -> bool = null;
action: (userdata: *void) = null;
}
@@ -32,6 +33,7 @@ UI_Panel :: struct {
#scope_file
active_panels: [..] *UI_Panel;
text_edit: *[..] u8;
+text_filter: (char: u32) -> bool;
#scope_export
ui_register_panel :: (panel: *UI_Panel) {
@@ -47,6 +49,15 @@ ui_bring_to_front :: (panel: *UI_Panel) {
array_add(*active_panels, panel);
}
+ui_filter_for_nums :: (value: u32) -> bool {
+ return value >= #char "0" && value <= #char "9";
+}
+
+ui_clear_focus :: () {
+ text_edit = null;
+ text_filter = null;
+}
+
ui_handle_input :: (active_app: *void) -> (occludes: bool) {
occludes := false;
mouse_x, mouse_y, success := get_mouse_pointer_position(window, true);
@@ -83,6 +94,11 @@ ui_handle_input :: (active_app: *void) -> (occludes: bool) {
if text_edit {
dirty_text = true;
value := it.utf32;
+ if text_filter {
+ if !text_filter(value) {
+ continue;
+ }
+ }
str := Unicode.character_utf32_to_utf8(value);
for 0..str.count-1 {
@@ -161,6 +177,7 @@ ui_handle_input :: (active_app: *void) -> (occludes: bool) {
} else if elem.type == .TEXT_INPUT {
panel.focus = elem.id;
text_edit = elem.input_buf;
+ text_filter = elem.text_filter;
} else if elem.type == .BUTTON && mouse_released {
if elem.action elem.action(panel.userdata);
}
@@ -173,10 +190,15 @@ ui_handle_input :: (active_app: *void) -> (occludes: bool) {
if !hit_element {
panel.focus = 0;
- text_edit = null;
+ ui_clear_focus();
}
}
return true;
+ } else {
+ if mouse_btn {
+ panel.focus = 0;
+ ui_clear_focus();
+ }
}
}
return false;