pushing update to desktop
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 9 Jun 2021 00:53:37 +0000 (19:53 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 9 Jun 2021 00:53:37 +0000 (19:53 -0500)
site/index.html
src/build.onyx
src/font/bitmap_font.onyx
src/tower.onyx

index 1211287728a9184ece0ccb8a3b38abc68a4abcaa..2ede2cac58788b161bf4bf782380b043d92beeef 100644 (file)
@@ -9,6 +9,7 @@
             width: 100%;
             height: 100%;
             overflow: hidden;
+            background-color: black;
         }
         </style>
 
index 950a7b8c45b25e176a86600f637a1b31f6a16d9f..b435f55b3cafe5013a90a811a8b177543a022d66 100644 (file)
@@ -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"
index 7feba429218e6ff2e568ed3694183ee317fd31db..ec82872e1b9f9234b874b5aedee384650fe34493 100644 (file)
@@ -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;
     }
 }
 
index aa27e79743d134d642e038d3f9cdfde4c3a9fde8..a9e97b9f8a6933a48fb4903cf91fcbee40dd5dd8 100644 (file)
@@ -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 });