From: Brendan Hansen Date: Mon, 14 Jun 2021 19:54:00 +0000 (-0500) Subject: small code cleanup X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=494acf3e704ee85e0b23733bb05b4cbef8726973;p=onyx.git small code cleanup --- diff --git a/bin/onyx b/bin/onyx index 4ca266c4..6a272f27 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/alloc/arena.onyx b/core/alloc/arena.onyx index 46665d6a..074317a5 100644 --- a/core/alloc/arena.onyx +++ b/core/alloc/arena.onyx @@ -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; diff --git a/modules/ui/components/textbox.onyx b/modules/ui/components/textbox.onyx index c4a60f23..044c217c 100644 --- a/modules/ui/components/textbox.onyx +++ b/modules/ui/components/textbox.onyx @@ -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 diff --git a/modules/ui/module.onyx b/modules/ui/module.onyx index 90a178eb..2233f5ce 100644 --- a/modules/ui/module.onyx +++ b/modules/ui/module.onyx @@ -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 */ diff --git a/src/onyxparser.c b/src/onyxparser.c index 0616cbce..91991152 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -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);