Skip to content

Commit

Permalink
(very slightly) cleaned up buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
10aded committed Mar 14, 2024
1 parent 40fe801 commit 117f726
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions buttons.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const shapes = @import("shapes.zig");

const Vec2 = @Vector(2, f32);
const Color = [4] u8;
const Color = [4] u8;

const DEBUG = Color{255, 0, 255, 255};
const DEBUG = Color{255, 0, 255, 255};

pub const Button = struct {
hovering : bool,
Expand All @@ -21,11 +21,14 @@ pub fn render_arrow_button(b : Button, arrow_is_pointing_left : bool) void {
const dir : f32 = if (arrow_is_pointing_left) 1 else -1;
const background_color = if (b.hovering) b.color1_hov else b.color1_def;
const detail_color = if (b.hovering) b.color2_hov else b.color2_def;
// Background first.

// Draw the background.
shapes.draw_centered_rect(b.pos, b.width, b.height, background_color);
// Draw arrow body.

// Draw the arrow body.
shapes.draw_centered_rect(b.pos + Vec2{dir * 0.1 * b.width, 0}, 0.5 * b.width, 0.4 * b.height, detail_color);
// Draw arrowhead triangle.

// Draw the arrowhead.
const p1 = Vec2{b.pos[0] - dir * 0.4 * b.width, b.pos[1]};
const p2 = Vec2{b.pos[0] - dir * 0.1 * b.width, b.pos[1] - 0.4 * b.height};
const p3 = Vec2{b.pos[0] - dir * 0.1 * b.width, b.pos[1] + 0.4 * b.height};
Expand All @@ -42,8 +45,10 @@ pub fn render_menu_button(b : Button) void {
};
const background_color = if (b.hovering) b.color1_hov else b.color1_def;
const detail_color = if (b.hovering) b.color2_hov else b.color2_def;
// Background first.

// Draw the background.
shapes.draw_centered_rect(b.pos, b.width, b.height, background_color);

// Draw the three rectangles.
for (rect_pos) |pos| {
shapes.draw_centered_rect(pos, square_length, subrectangle_height, detail_color);
Expand Down

0 comments on commit 117f726

Please sign in to comment.