small code cleanup
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 14 Jun 2021 19:54:00 +0000 (14:54 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 14 Jun 2021 19:54:00 +0000 (14:54 -0500)
bin/onyx
core/alloc/arena.onyx
modules/ui/components/textbox.onyx
modules/ui/module.onyx
src/onyxparser.c

index 4ca266c4f8696b50f8fea097d1a67da146048885..6a272f27c86fe72d5a9b90f1b0453b939db09380 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 46665d6a934009e061a3cf39d05cbc209bd8e5ef..074317a5bef0b981bfce9a1ae630be2319ef37de 100644 (file)
@@ -29,7 +29,7 @@ Arena :: struct { next : ^Arena; }
 arena_alloc_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr {
     alloc_arena := cast(^ArenaState) data;
 
-    if aa == AllocationAction.Alloc {
+    if aa == .Alloc {
         // An allocation of this size does not fit into a single arena.
         if size > alloc_arena.arena_size - sizeof rawptr {
             return null;
index c4a60f23badd1615b5c8c2e913a18ccd91ce2982..044c217c7a9d650c625c614f7f62fe99b17aa643 100644 (file)
@@ -18,7 +18,9 @@ Textbox_Theme :: struct {
     border_color := gfx.Color4.{ 0.2, 0.2, 0.2 };
     border_width := 6.0f;   @InPixels
 
-    cursor_color     := gfx.Color4.{ 0.5, 0.5, 0.5 };
+    cursor_color := gfx.Color4.{ 0.5, 0.5, 0.5 };
+    cursor_width := 4.0f;   @InPixels
+    cursor_blink_speed := 0.04f;   // Bigger is faster
 }
 
 default_textbox_theme := Textbox_Theme.{};
@@ -34,6 +36,7 @@ Textbox_Editing_State :: struct {
 }
 
 #private
+// There is only one 'Textbox_Editing_State', not a map of them because there can only be one textbox being edited at once.
 textbox_editing_state := Textbox_Editing_State.{};
 
 textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, theme := ^default_textbox_theme, site := #callsite, increment := 0) -> bool {
@@ -56,6 +59,7 @@ textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, theme := ^defa
         if mouse_state.left_button_down && Rectangle.contains(r, mouse_state.x, mouse_state.y) {
             set_active_item(hash);
             textbox_editing_state.hash = hash;
+            textbox_editing_state.cursor_animation_speed = theme.cursor_blink_speed;
 
             // animation_state.click_time = 1.0f;
         }
@@ -87,6 +91,7 @@ textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, theme := ^defa
             for key_index: keyboard_state.keys_down_this_frame {
                 key := keyboard_state.keycodes_down_this_frame[key_index];
 
+                @KeycodeIsWrong
                 switch key.code {
                     case 0x25 do textbox_editing_state.cursor_position -= 1;
                     case 0x27 do textbox_editing_state.cursor_position += 1;
@@ -143,14 +148,15 @@ textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, theme := ^defa
     if textbox_editing_state.hash == hash {
         cursor_x := get_cursor_location(text_buffer, text_x, text_y, theme.font_size, textbox_editing_state.cursor_position);
         cursor_y := y0 + theme.border_width;
+        cursor_w := theme.cursor_width;
         cursor_h := height - theme.border_width * 2;
 
         cursor_color := theme.cursor_color;
         cursor_color.a = textbox_editing_state.cursor_animation;
 
         draw_rect(
-            .{ cursor_x, cursor_y, cursor_x + 4, cursor_y + cursor_h },
-            color=cursor_color); @ThemeConfiguration
+            .{ cursor_x, cursor_y, cursor_x + cursor_w, cursor_y + cursor_h },
+            color=cursor_color);
     }
 
     move_towards(^animation_state.click_time, 0.0f, 0.08f);     @ThemeConfiguration
index 90a178ebac7e6b040c2fda6830b2ce8bd3a844e4..2233f5ce9f8e6f68a1e47d153374c7030c69ae76 100644 (file)
@@ -5,8 +5,6 @@ Document this module better
 Add a font cache and more preloaded fonts
 
 Add proper font texture decoding to make the WebGL texture depending on how the BMFont was encoded into the image.
-
-Add textboxes
 */
 
 
index 0616cbce643085371ea9cb780ce44003affe0668..9199115205bfbff19049d8563a5acaffe1ea7d92 100644 (file)
@@ -2255,7 +2255,7 @@ static void parse_top_level_statement(OnyxParser* parser) {
 
             if (parser->curr->type == ':') {
                 binding = parse_top_level_binding(parser, symbol);
-                if (binding != NULL) binding->node->flags |= private_kind;
+                if (binding != NULL) binding->flags |= private_kind;
 
                 goto submit_binding_to_entities;
             }
@@ -2269,12 +2269,12 @@ static void parse_top_level_statement(OnyxParser* parser) {
             if (consume_token_if_next(parser, '='))
                 memres->initial_value = parse_expression(parser, 1);
             
-            memres->flags |= private_kind;
             
             ENTITY_SUBMIT(memres);
             
             binding = make_node(AstBinding, Ast_Kind_Binding);
             binding->token = symbol;
+            binding->flags |= private_kind;
             binding->node = (AstNode *) memres;
 
             goto submit_binding_to_entities;
@@ -2385,9 +2385,9 @@ submit_binding_to_entities:
 
         Scope* target_scope = parser->package->scope;
 
-        if (binding->node->flags & Ast_Flag_Private_Package)
+        if (binding->flags & Ast_Flag_Private_Package)
             target_scope = parser->package->private_scope;
-        if (binding->node->flags & Ast_Flag_Private_File)
+        if (binding->flags & Ast_Flag_Private_File)
             target_scope = parser->file_scope;
         
         ENTITY_SUBMIT_IN_SCOPE(binding, target_scope);