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 {
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 {
tallest_height = math.max(tallest_height, glyph.h * size * em);
}
- return tallest_height;
+ return tallest_height + lines_height;
}
}
opacity := 1.0f;
counter := 0;
+test_button_count := 1;
draw :: () {
gl.clearColor(0, 0, 0, 1);
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 });