bugfixes and added animation theme to ui module
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 20 Jun 2021 18:26:38 +0000 (13:26 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 20 Jun 2021 18:26:38 +0000 (13:26 -0500)
bin/onyx
modules/ui/components/button.onyx
modules/ui/components/checkbox.onyx
modules/ui/components/radio.onyx
modules/ui/components/slider.onyx
modules/ui/components/textbox.onyx
modules/ui/ui.onyx
src/onyxwasm.c
tests/better_field_accesses.onyx

index b1ce16726ffed35a915b720812578387b2208bf3..3cdf33078f221ccec0230eb62cbeabdf107a06a3 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index c647b2e3a41cb50bba436958c002a2ffd28aeac8..0ba70b53df4165510e10aa674f50134d8d2b4770 100644 (file)
@@ -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);
index 6b84e1ad02258cf27ca3508f5befece88850c6ad..d844a507bacc462278e60d46576af22d3ad07a3e 100644 (file)
@@ -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);
index 3f27952c3a45f5bac440d51eda50764eb9911305..3ca62cf19fcf50863cbd907f434ba267b20c82d6 100644 (file)
@@ -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);
index 04859b4858e43065b554636f076734818cad8010..d8a4262223743c60509fe34a84ee0c8fa87ceccf 100644 (file)
@@ -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;
index 044c217c7a9d650c625c614f7f62fe99b17aa643..52d26a7e7d593af263ffed864bf2a87688e81c61 100644 (file)
@@ -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);
index c99047e7ae9c38a6fd3dc0f49b99b8e23cd62ffa..39f67518e802add718fcdde0976706575600fcfd 100644 (file)
@@ -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
+}
index 0fa7eb946138074d5e165a5903a70de94641bcaa..55c8b280220307571a8a82de6b832d0f11444354 100644 (file)
@@ -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;
 
index 124b72b69a0b9a0487eea44fd311d5673f527c2f..3485f315fbb40b11f9a865fd8d7bf834d6f6392c 100644 (file)
@@ -24,4 +24,4 @@ main :: (args: [] cstr) {
     println(get_foo().age);
 
     println((Foo.{ 0, 0, "Worked!", 0 }).name);
-}
\ No newline at end of file
+}