added checkbox test
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 10 Jun 2021 02:57:34 +0000 (21:57 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 10 Jun 2021 02:57:34 +0000 (21:57 -0500)
site/js/game.js
src/tower.onyx

index b5f89e82c16303bf15b65fda04356be14b205576..c884a43b38e1cae64f31431e4600a847a3df015f 100644 (file)
@@ -16,4 +16,12 @@ window.ONYX_MODULES.push({
     time_now: function() {
         return Date.now();
     },
+
+    alert: function(strptr, strlen) {
+        const decoder = new TextDecoder();
+        const data = new Uint8Array(window.ONYX_MEMORY.buffer, strptr, strlen);
+        const str = decoder.decode(data);
+
+        window.alert(str);
+    }
 });
index 3294807e8afde5aa15010f70f009067c50bb2b6a..97f688d196e98e627db215a568750809bffe2777 100644 (file)
@@ -89,20 +89,49 @@ opacity := 1.0f;
 counter := 0;
 test_button_count := 1;
 
+check_buttons : [10] bool
+
 draw :: () {
     gl.clearColor(0, 0, 0, 1);
     gl.clear(gl.COLOR_BUFFER_BIT);
 
     master_rectangle := ui.Rectangle.{ x1 = ~~window_width, y1 = ~~window_height };
 
-    left, right := ui.Flow.split_vertical(master_rectangle, left_width=400);
-    right_top, right_bottom := ui.Flow.split_horizontal(right, top_percent=.6);
+    use ui.Flow;
+
+    left, right := split_vertical(master_rectangle, left_width=400);
+    right_top, right_bottom := split_horizontal(right, top_percent=.6);
 
     ui.draw_rect(right_bottom, .{ 0, 0.25, 0.5 });
     ui.draw_rect(right_top, .{ 0.5, 0.4, 0.4 });
 
     {
-        top, bottom := ui.Flow.split_horizontal(right_bottom, top_percent=.5);
+        panel, _ := split_vertical(right_top, left_width=300);
+        checkbox : ui.Rectangle;
+
+        ui.draw_rect(panel, .{ 0, 0, 0, 0.3 });
+        
+        str_buffer : [32] u8;
+
+        i := 1;
+        for ^button_value: check_buttons {
+            checkbox, panel = split_horizontal(panel, top_height=48);
+            
+            text := conv.str_format("Check me! %i", ~~ str_buffer, i);
+            ui.checkbox(checkbox, button_value, text, increment=i);
+
+            i += 1;
+        }
+
+        button_rect, _ := split_horizontal(panel, top_height=72);
+        button_rect = padding(button_rect, left=12, right=12, top=24);
+        if ui.button(button_rect, "Clear all") {
+            for ^value: check_buttons do *value = false;
+        }
+    }
+
+    {
+        top, bottom := split_horizontal(right_bottom, top_percent=.5);
         text_theme := ui.default_text_theme;
         text_theme.font_size = 1.0f;
         ui.draw_text(bottom, "Something here\nSomething else here.\nAlso here.", ^text_theme);
@@ -118,27 +147,35 @@ draw :: () {
         red_theme := ui.default_button_theme;
         red_theme.text_color = .{ 1, 0, 0 };
         red_theme.click_color = .{ 1, 0, 0 };
-        button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=200, padding=10);
+        button_rect, sidebar = split_horizontal(sidebar, top_height=200, padding=10);
         if ui.button(button_rect, "Red\nWow this is cool", ^red_theme) {
             counter += 1;
         }
 
         if counter % 2 == 0 {
             red_theme = ui.default_button_theme;
-            button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=75, padding=10);
+            button_rect, sidebar = split_horizontal(sidebar, top_height=75, padding=10);
             ui.button(button_rect, "Another Button", ^red_theme);
         }
 
-        button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=75, padding = 10);
+        button_rect, sidebar = split_horizontal(sidebar, top_height=75, padding = 10);
         if ui.button(button_rect, "Increase Buttons", ^red_theme) do test_button_count += 1;
-        button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=75, padding = 10);
+        button_rect, sidebar = split_horizontal(sidebar, top_height=75, padding = 10);
         if ui.button(button_rect, "Decrease Buttons", ^red_theme) do test_button_count -= 1;
 
         test_button_count = math.clamp(test_button_count, 0, 10);
 
+        red_theme = ui.default_button_theme;
+        red_theme.font_size = 0.7f;
         for i: test_button_count {
-            button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=75, padding=10);
-            ui.button(button_rect, "Test Button", increment=i);
+            button_rect, sidebar = split_horizontal(sidebar, top_height=75, padding=10);
+
+            left_button, right_button := split_vertical(button_rect, left_percent=.5, padding=10);
+            if ui.button(left_button, "Left Button", increment=i, theme=^red_theme) && i == 3 {
+                alert :: (message: str) -> void #foreign "game" "alert" ---
+                alert("Clicked the 4th left button!");
+            }
+            ui.button(right_button, "Right Button", increment=i, theme=^red_theme);
         }
     }