From 7c3dd3a2652aca54fd08a3c9ee6197aae947c6b1 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 8 Jun 2021 19:53:37 -0500 Subject: [PATCH] pushing update to desktop --- site/index.html | 1 + src/build.onyx | 1 + src/font/bitmap_font.onyx | 20 +++++++++++++++++++- src/tower.onyx | 34 +++++++++++++++++++++------------- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/site/index.html b/site/index.html index 1211287..2ede2ca 100644 --- a/site/index.html +++ b/site/index.html @@ -9,6 +9,7 @@ width: 100%; height: 100%; overflow: hidden; + background-color: black; } diff --git a/src/build.onyx b/src/build.onyx index 950a7b8..b435f55 100644 --- a/src/build.onyx +++ b/src/build.onyx @@ -8,6 +8,7 @@ #load "modules/js_events/module" #load "modules/immediate_mode/module" #load "modules/ui/module" +#load "modules/bmfont/module" #load "src/config" #load "src/font/bitmap_font" diff --git a/src/font/bitmap_font.onyx b/src/font/bitmap_font.onyx index 7feba42..ec82872 100644 --- a/src/font/bitmap_font.onyx +++ b/src/font/bitmap_font.onyx @@ -44,7 +44,16 @@ Bitmap_Font :: struct { get_width :: (use bmp: ^Bitmap_Font, text: str, size: f32) -> f32 { width: f32 = 0; + max_line_width := 0.0f; + for char: text { + if char == #char "\n" { + glyph := map.get_ptr(^glyphs, #char "M"); + max_line_width = math.max(max_line_width, glyph.h * size * em); + width = 0; + continue; + } + glyph := map.get_ptr(^glyphs, ~~char); if glyph == null { @@ -60,7 +69,16 @@ Bitmap_Font :: struct { get_height :: (use bmp: ^Bitmap_Font, text: str, size: f32) -> f32 { tallest_height: f32 = 0; + lines_height: f32 = 0; + for char: text { + if char == #char "\n" { + glyph := map.get_ptr(^glyphs, #char "M"); + lines_height += glyph.h * size * em; + tallest_height = 0; + continue; + } + glyph := map.get_ptr(^glyphs, ~~char); if glyph == null { @@ -71,7 +89,7 @@ Bitmap_Font :: struct { tallest_height = math.max(tallest_height, glyph.h * size * em); } - return tallest_height; + return tallest_height + lines_height; } } diff --git a/src/tower.onyx b/src/tower.onyx index aa27e79..a9e97b9 100644 --- a/src/tower.onyx +++ b/src/tower.onyx @@ -88,6 +88,7 @@ update :: (dt: f32) { opacity := 1.0f; counter := 0; +test_button_count := 1; draw :: () { gl.clearColor(0, 0, 0, 1); @@ -95,40 +96,47 @@ draw :: () { master_rectangle := ui.Rectangle.{ x1 = ~~window_width, y1 = ~~window_height }; - left, right := ui.Flow.split_vertical(master_rectangle, left_width=400); + left, right := ui.Flow.split_vertical(master_rectangle, left_width=300); right_top, right_bottom := ui.Flow.split_horizontal(right, top_percent=.6); - ui.draw_rect(left, .{ 0.2, 0.15, 0.15 }); - ui.draw_rect(right, .{ 0, 0.25, 0.5 }); - ui.draw_rect(right_top, .{ 1, 0, 0 }); + ui.draw_rect(right_bottom, .{ 0, 0.25, 0.5 }); { text_theme := ui.default_text_theme; - text_theme.font_size = .2; + text_theme.font_size = 24; text_theme.text_color = .{ 0.6, 0.6, 1.0 }; - ui.draw_text(right_bottom, "Something here", ^text_theme); + ui.draw_text(right_bottom, "Something here\nSomething else here.\nAlso here.", ^text_theme); } { button_rect: ui.Rectangle; sidebar := left; - button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=75); - ui.draw_button(button_rect, "Test Button"); + 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); + } red_theme := ui.default_button_theme; red_theme.text_color = .{ 1, 0, 0 }; - button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=75); - if ui.draw_button(button_rect, "Red", ^red_theme) { + red_theme.click_color = .{ 1, 0, 0 }; + button_rect, sidebar = ui.Flow.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; - red_theme.font_size = .3; - button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=75); - ui.draw_button(button_rect, "Another Button", ^red_theme); + button_rect, sidebar = ui.Flow.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); + 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); + if ui.button(button_rect, "Decrease Buttons", ^red_theme) do test_button_count -= 1; + + test_button_count = math.clamp(test_button_count, 0, 10); } if opacity > 0 do ui.draw_rect(master_rectangle, .{ 0, 0, 0, opacity }); -- 2.25.1