add more styles

master
Patrick Cleavelin 2023-06-23 21:08:23 -05:00
parent 08b03d4266
commit b747c4e6ad
2 changed files with 15 additions and 7 deletions

View File

@ -32,9 +32,14 @@ pub const UI_Direction = enum {
bottomToTop, bottomToTop,
}; };
// TODO: don't couple to raylib
pub const UI_Style = struct { pub const UI_Style = struct {
// TODO: don't couple to raylib color: raylib.Color = raylib.LIGHTGRAY,
hover_color: raylib.Color, hover_color: raylib.Color = raylib.WHITE,
border_color: raylib.Color = raylib.DARKGRAY,
text_color: raylib.Color = raylib.BLACK,
text_size: i32 = 20,
}; };
pub const Vec2 = struct { pub const Vec2 = struct {
@ -422,15 +427,15 @@ pub fn DrawUI(box: *UI_Box, parent: ?*UI_Box, my_index: u32, num_siblings: u32,
} }
if (box.flags.drawBackground) { if (box.flags.drawBackground) {
const color = if (TestBoxHover(box)) box.style.hover_color else raylib.DARKGRAY; const color = if (TestBoxHover(box)) box.style.hover_color else box.style.color;
raylib.DrawRectangle(@floatToInt(i32, box.computed_pos.x), @floatToInt(i32, box.computed_pos.y), @floatToInt(i32, box.computed_size.x), @floatToInt(i32, box.computed_size.y), color); raylib.DrawRectangle(@floatToInt(i32, box.computed_pos.x), @floatToInt(i32, box.computed_pos.y), @floatToInt(i32, box.computed_size.x), @floatToInt(i32, box.computed_size.y), color);
} }
if (box.flags.drawBorder) { if (box.flags.drawBorder) {
raylib.DrawRectangleLines(@floatToInt(i32, box.computed_pos.x), @floatToInt(i32, box.computed_pos.y), @floatToInt(i32, box.computed_size.x), @floatToInt(i32, box.computed_size.y), raylib.BLUE); raylib.DrawRectangleLines(@floatToInt(i32, box.computed_pos.x), @floatToInt(i32, box.computed_pos.y), @floatToInt(i32, box.computed_size.x), @floatToInt(i32, box.computed_size.y), box.style.border_color);
} }
if (box.flags.drawText) { if (box.flags.drawText) {
raylib.DrawText(box.label, @floatToInt(i32, box.computed_pos.x), @floatToInt(i32, box.computed_pos.y), 10, raylib.RED); raylib.DrawText(box.label, @floatToInt(i32, box.computed_pos.x), @floatToInt(i32, box.computed_pos.y), box.style.text_size, box.style.text_color);
} }
// draw children // draw children

View File

@ -39,7 +39,7 @@ pub fn main() !void {
raylib.ClearBackground(raylib.BLACK); raylib.ClearBackground(raylib.BLACK);
if (show_buttons) { if (show_buttons) {
_ = try ui.PushBox("ButtonArray", .{}, dir); _ = try ui.PushBox("ButtonArray", .{}, .topToBottom);
defer ui.PopBox(); defer ui.PopBox();
if (try ui.MakeButton("Show Labels")) { if (try ui.MakeButton("Show Labels")) {
@ -57,6 +57,8 @@ pub fn main() !void {
if (other_button_shown) { if (other_button_shown) {
_ = try ui.PushBox("TextArray", .{}, dir); _ = try ui.PushBox("TextArray", .{}, dir);
defer ui.PopBox(); defer ui.PopBox();
try ui.PushStyle(.{ .text_color = raylib.YELLOW });
defer ui.PopStyle();
_ = try ui.MakeLabel("This is some text"); _ = try ui.MakeLabel("This is some text");
@ -64,8 +66,9 @@ pub fn main() !void {
try ui.PushStyle(.{ .hover_color = raylib.SKYBLUE }); try ui.PushStyle(.{ .hover_color = raylib.SKYBLUE });
defer ui.PopStyle(); defer ui.PopStyle();
for (0..20) |_| { for (0..10) |_| {
_ = try ui.MakeButton("So is this"); _ = try ui.MakeButton("So is this");
_ = try ui.MakeBox("spacer", .{}, dir);
} }
} }