From 4249090d927d77f232ca29b84b49fd8b51774eb6 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Wed, 9 Jun 2021 21:57:34 -0500 Subject: [PATCH] added checkbox test --- site/js/game.js | 8 +++++++ src/tower.onyx | 55 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/site/js/game.js b/site/js/game.js index b5f89e8..c884a43 100644 --- a/site/js/game.js +++ b/site/js/game.js @@ -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); + } }); diff --git a/src/tower.onyx b/src/tower.onyx index 3294807..97f688d 100644 --- a/src/tower.onyx +++ b/src/tower.onyx @@ -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); } } -- 2.25.1