From: Brendan Hansen Date: Sun, 20 Jun 2021 18:26:38 +0000 (-0500) Subject: bugfixes and added animation theme to ui module X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=d6b9de081756751d19d93394aa90bdf28786d6f2;p=onyx.git bugfixes and added animation theme to ui module --- diff --git a/bin/onyx b/bin/onyx index b1ce1672..3cdf3307 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/modules/ui/components/button.onyx b/modules/ui/components/button.onyx index c647b2e3..0ba70b53 100644 --- a/modules/ui/components/button.onyx +++ b/modules/ui/components/button.onyx @@ -3,6 +3,7 @@ use package core Button_Theme :: struct { use text_theme := Text_Theme.{}; + use animation_theme := Animation_Theme.{}; background_color := gfx.Color4.{ 0.1, 0.1, 0.1 }; hover_color := gfx.Color4.{ 0.3, 0.3, 0.3 }; @@ -41,9 +42,9 @@ button :: (use r: Rectangle, text: str, theme := ^default_button_theme, site := } if is_hot_item(hash) { - move_towards(^animation_state.hover_time, 1.0f, 0.1f); @ThemeConfiguration + move_towards(^animation_state.hover_time, 1.0f, theme.hover_speed); } else { - move_towards(^animation_state.hover_time, 0.0f, 0.1f); @ThemeConfiguration + move_towards(^animation_state.hover_time, 0.0f, theme.hover_speed); } border_width := theme.border_width; @@ -65,7 +66,7 @@ button :: (use r: Rectangle, text: str, theme := ^default_button_theme, site := y0 + ~~ font.common.baseline * theme.font_size + (height - text_height) / 2, theme.font_size, theme.text_color); - move_towards(^animation_state.click_time, 0.0f, 0.08f); @ThemeConfiguration + move_towards(^animation_state.click_time, 0.0f, theme.click_decay_speed); if animation_state.click_time > 0 || animation_state.hover_time > 0 { map.put(^animation_states, hash, animation_state); diff --git a/modules/ui/components/checkbox.onyx b/modules/ui/components/checkbox.onyx index 6b84e1ad..d844a507 100644 --- a/modules/ui/components/checkbox.onyx +++ b/modules/ui/components/checkbox.onyx @@ -3,6 +3,7 @@ use package core Checkbox_Theme :: struct { use text_theme := Text_Theme.{}; + use animation_theme := Animation_Theme.{}; box_color := gfx.Color4.{ 0.2, 0.2, 0.2 }; box_border_width := 4.0f; @InPixels @@ -46,9 +47,9 @@ checkbox :: (use r: Rectangle, value: ^bool, text: str, theme := ^default_checkb } if is_hot_item(hash) { - move_towards(^animation_state.hover_time, 1.0f, 0.1f); @ThemeConfiguration + move_towards(^animation_state.hover_time, 1.0f, theme.hover_speed); } else { - move_towards(^animation_state.hover_time, 0.0f, 0.1f); @ThemeConfiguration + move_towards(^animation_state.hover_time, 0.0f, theme.hover_speed); } @@ -90,7 +91,7 @@ checkbox :: (use r: Rectangle, value: ^bool, text: str, theme := ^default_checkb y0 + ~~ font.common.baseline * theme.font_size + (height - text_height) / 2, theme.font_size, theme.text_color); - move_towards(^animation_state.click_time, 0.0f, 0.08f); @ThemeConfiguration + move_towards(^animation_state.click_time, 0.0f, theme.click_decay_speed); if animation_state.click_time > 0 || animation_state.hover_time > 0 { map.put(^animation_states, hash, animation_state); diff --git a/modules/ui/components/radio.onyx b/modules/ui/components/radio.onyx index 3f27952c..3ca62cf1 100644 --- a/modules/ui/components/radio.onyx +++ b/modules/ui/components/radio.onyx @@ -3,6 +3,7 @@ use package core Radio_Theme :: struct { use text_theme := Text_Theme.{}; + use animation_theme := Animation_Theme.{}; radio_color := gfx.Color4.{ 0.2, 0.2, 0.2 }; radio_border_radius := 4.0f; @InPixels @@ -46,9 +47,9 @@ radio :: (use r: Rectangle, selected: ^$T, value: T, text: str, theme := ^defaul } if is_hot_item(hash) { - move_towards(^animation_state.hover_time, 1.0f, 0.1f); @ThemeConfiguration + move_towards(^animation_state.hover_time, 1.0f, theme.hover_speed); } else { - move_towards(^animation_state.hover_time, 0.0f, 0.1f); @ThemeConfiguration + move_towards(^animation_state.hover_time, 0.0f, theme.hover_speed); } radius := theme.radio_radius; @@ -82,7 +83,7 @@ radio :: (use r: Rectangle, selected: ^$T, value: T, text: str, theme := ^defaul y0 + ~~ font.common.baseline * theme.font_size + (height - text_height) / 2, theme.font_size, theme.text_color); - move_towards(^animation_state.click_time, 0.0f, 0.08f); @ThemeConfiguration + move_towards(^animation_state.click_time, 0.0f, theme.click_decay_speed); if animation_state.click_time > 0 || animation_state.hover_time > 0 { map.put(^animation_states, hash, animation_state); diff --git a/modules/ui/components/slider.onyx b/modules/ui/components/slider.onyx index 04859b48..d8a42622 100644 --- a/modules/ui/components/slider.onyx +++ b/modules/ui/components/slider.onyx @@ -4,6 +4,7 @@ use package core Slider_Theme :: struct { use text_theme := Text_Theme.{}; + use animation_theme := Animation_Theme.{}; box_color := gfx.Color4.{ 0.1, 0.1, 0.1 }; box_border_color := gfx.Color4.{ 0.2, 0.2, 0.2 }; @@ -39,9 +40,9 @@ slider :: (use r: Rectangle, value: ^$T, min_value: T, max_value: T, text: str, } if is_hot_item(hash) { - move_towards(^animation_state.hover_time, 1.0f, 0.1f); @ThemeConfiguration + move_towards(^animation_state.hover_time, 1.0f, theme.hover_speed); } else { - move_towards(^animation_state.hover_time, 0.0f, 0.1f); @ThemeConfiguration + move_towards(^animation_state.hover_time, 0.0f, theme.hover_speed); } box_border_width := theme.box_border_width; diff --git a/modules/ui/components/textbox.onyx b/modules/ui/components/textbox.onyx index 044c217c..52d26a7e 100644 --- a/modules/ui/components/textbox.onyx +++ b/modules/ui/components/textbox.onyx @@ -7,6 +7,8 @@ Textbox_Theme :: struct { // text_color = .{1, 1, 1} }; + use animation_theme := Animation_Theme.{}; + // background_color := gfx.Color4.{ 0.1, 0.1, 0.1 }; // hover_color := gfx.Color4.{ 0.3, 0.3, 0.3 }; // click_color := gfx.Color4.{ 0.5, 0.5, 0.7 }; @@ -131,9 +133,9 @@ textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, theme := ^defa } if is_hot_item(hash) { - move_towards(^animation_state.hover_time, 1.0f, 0.1f); @ThemeConfiguration + move_towards(^animation_state.hover_time, 1.0f, theme.hover_speed); } else { - move_towards(^animation_state.hover_time, 0.0f, 0.1f); @ThemeConfiguration + move_towards(^animation_state.hover_time, 0.0f, theme.hover_speed); } gfx.set_texture(); @@ -159,7 +161,7 @@ textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, theme := ^defa color=cursor_color); } - move_towards(^animation_state.click_time, 0.0f, 0.08f); @ThemeConfiguration + move_towards(^animation_state.click_time, 0.0f, theme.click_decay_speed); if animation_state.click_time > 0 || animation_state.hover_time > 0 { map.put(^animation_states, hash, animation_state); diff --git a/modules/ui/ui.onyx b/modules/ui/ui.onyx index c99047e7..39f67518 100644 --- a/modules/ui/ui.onyx +++ b/modules/ui/ui.onyx @@ -235,9 +235,13 @@ Text_Theme :: struct { } default_text_theme := Text_Theme.{}; - +Animation_Theme :: struct { + hover_speed := 0.1f; + click_decay_speed := 0.08f; +} + // Animation states are stored globally as there is not much to the state of a button. @@ -309,4 +313,4 @@ get_text_width :: (text: str, size := DEFAULT_TEXT_SIZE) -> f32 { b = c1.b * (1 - t) + c2.b * t, a = c1.a * (1 - t) + c2.a * t, @Cleanup // should this be interpolating alphas? }; -} \ No newline at end of file +} diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 0fa7eb94..55c8b280 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -2410,7 +2410,7 @@ EMIT_FUNC(expression, AstTyped* expr) { } } - if (is_lval((AstNode *) field->expr)) { + if (is_lval((AstNode *) field->expr) || type_is_pointer(field->expr->type)) { u64 offset = 0; emit_field_access_location(mod, &code, field, &offset); emit_load_instruction(mod, &code, field->type, offset); @@ -3301,7 +3301,6 @@ OnyxWasmModule onyx_wasm_module_create(bh_allocator alloc) { bh_arr_new(alloc, module.data, 4); bh_arr_new(alloc, module.elems, 4); - // NOTE: 16 is probably needlessly large bh_arr_new(global_heap_allocator, module.structured_jump_target, 16); bh_arr_set_length(module.structured_jump_target, 0); @@ -3407,6 +3406,7 @@ void emit_entity(Entity* ent) { case Entity_Type_Global: emit_global(module, ent->global); break; // Cleanup: Maybe these should be printed elsewhere? + // Also, they should be sorted? Or have that ability? case Entity_Type_Note: { if (!context.options->print_notes) break; diff --git a/tests/better_field_accesses.onyx b/tests/better_field_accesses.onyx index 124b72b6..3485f315 100644 --- a/tests/better_field_accesses.onyx +++ b/tests/better_field_accesses.onyx @@ -24,4 +24,4 @@ main :: (args: [] cstr) { println(get_foo().age); println((Foo.{ 0, 0, "Worked!", 0 }).name); -} \ No newline at end of file +}