Skip to content

Commit 956c95b

Browse files
author
Jay
committed
Progress bar colours added to theme
1 parent 65b1b10 commit 956c95b

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .engine,
3-
.version = "0.7.7",
3+
.version = "0.7.8",
44
.fingerprint = 0xe8a81a8d0aa558d5,
55
.minimum_zig_version = "0.15.2",
66
.dependencies = .{

src/engine.zig

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ pub const Element = struct {
337337

338338
texture: ?*TextureInfo = null,
339339
texture_name: ?[]const u8 = null,
340+
341+
style: ThemeColour = .normal,
340342
colour: Colour = WHITE,
341343

342344
background: Background = .{
@@ -357,7 +359,6 @@ pub const Element = struct {
357359
children: ArrayListUnmanaged(*Element) = .empty,
358360
direction: LayoutDirection = .centre,
359361
spacing: f32 = 0,
360-
style: ThemeColour = .normal,
361362
on_click: Callback = .{ .func = null },
362363
update: UpdateCallback = .{ .func = null },
363364
scrollable: Scroller = .{
@@ -413,9 +414,7 @@ pub const Element = struct {
413414
placeholder_text: ?[]const u8 = "",
414415
placeholder_translate: []const u8 = "",
415416
},
416-
rectangle: struct {
417-
style: ThemeColour = .normal,
418-
},
417+
rectangle: struct {},
419418
button: struct {
420419
font: *FontInfo = undefined,
421420
font_name: ?[]const u8 = null,
@@ -436,7 +435,6 @@ pub const Element = struct {
436435
background_pressed_name: ?[]const u8 = null,
437436
on_click: Callback = .{ .func = null },
438437
toggle: ToggleState = .no_toggle,
439-
style: ThemeColour = .normal,
440438
},
441439
button_bar: struct {},
442440
progress_bar: struct {
@@ -593,9 +591,9 @@ pub const Element = struct {
593591
}
594592

595593
inline fn button_text_tint(self: *Element, theme: *Theme) Colour {
596-
if (self.type.button.style == .success) return theme.success_text_colour;
597-
if (self.type.button.style == .failed) return theme.failed_text_colour;
598-
if (self.type.button.style == .custom) return self.colour;
594+
if (self.style == .success) return theme.success_text_colour;
595+
if (self.style == .failed) return theme.failed_text_colour;
596+
if (self.style == .custom) return self.colour;
599597
if (self.pressed) return theme.tinted_text_colour;
600598
if (self.hovered) return theme.tinted_text_colour;
601599

@@ -608,7 +606,7 @@ pub const Element = struct {
608606
texture: *sdl.SDL_Texture,
609607
) void {
610608
if (self.type == .button) {
611-
switch (self.type.button.style) {
609+
switch (self.style) {
612610
.success => {
613611
tint_texture(texture, display.theme.success_button_colour);
614612
return;
@@ -638,7 +636,7 @@ pub const Element = struct {
638636
}
639637

640638
if (self.type == .panel) {
641-
switch (self.type.panel.style) {
639+
switch (self.style) {
642640
.emphasised => tint_texture(texture, display.theme.emphasised_panel_colour),
643641
.success => tint_texture(texture, display.theme.success_panel_colour),
644642
.failed => tint_texture(texture, display.theme.failed_panel_colour),
@@ -648,7 +646,7 @@ pub const Element = struct {
648646
else => {
649647
warn(
650648
"unhandled panel tint option: {s}",
651-
.{@tagName(self.type.panel.style)},
649+
.{@tagName(self.style)},
652650
);
653651
tint_texture(texture, engine.WHITE);
654652
},
@@ -1433,7 +1431,7 @@ pub const Element = struct {
14331431
_: ?Clip,
14341432
scroll_offset: Vector,
14351433
) void {
1436-
const colour = element.type.rectangle.style.panel(display.theme, element.background.colour);
1434+
const colour = element.style.panel(display.theme, element.background.colour);
14371435
_ = sdl.SDL_SetRenderDrawColor(
14381436
display.renderer,
14391437
colour.r,
@@ -1668,15 +1666,15 @@ pub const Element = struct {
16681666
inline fn draw_progress_bar(element: *Element, display: *Display, _: Vector, _: ?Clip) void {
16691667
// Draw the background matching the current button state
16701668
if (element.texture) |texture| {
1671-
//const radius = @as(f32, @floatFromInt(texture.texture.h >> 1));
16721669
// Progress bar background
1670+
var tint = display.theme.progress_bar_background;
16731671
var dest: Rect = .{
16741672
.x = element.rect.x + element.pad.left,
16751673
.y = element.rect.y + element.pad.top,
16761674
.width = element.rect.width - element.pad.left - element.pad.right,
16771675
.height = element.rect.height - element.pad.top - element.pad.bottom,
16781676
};
1679-
var tint = display.theme.label_background_colour;
1677+
_ = sdl.SDL_SetTextureAlphaMod(texture.texture, tint.a);
16801678
_ = sdl.SDL_SetTextureColorMod(texture.texture, tint.r, tint.g, tint.b);
16811679
var corner: f32 = element.background.corner_radius;
16821680
if (corner * 2 > dest.height) corner = dest.height / 2;
@@ -1700,8 +1698,9 @@ pub const Element = struct {
17001698

17011699
// Progress bar foreground
17021700
if (element.type.progress_bar.progress > 0.01) {
1701+
tint = display.theme.progress_bar_foreground;
17031702
dest.width *= element.type.progress_bar.progress;
1704-
tint = display.theme.placeholder_text_colour;
1703+
_ = sdl.SDL_SetTextureAlphaMod(texture.texture, tint.a);
17051704
_ = sdl.SDL_SetTextureColorMod(texture.texture, tint.r, tint.g, tint.b);
17061705
if (element.background.image_corner_radius == 0) {
17071706
_ = sdl.SDL_RenderTexture(display.renderer, texture.texture, null, @ptrCast(&dest));
@@ -1801,7 +1800,7 @@ pub const Element = struct {
18011800
dest.y += dest.height;
18021801
dest.height = 0 - dest.height;
18031802
}
1804-
if (element.type.button.style != .custom) {
1803+
if (element.style != .custom) {
18051804
_ = sdl.SDL_SetTextureColorMod(
18061805
icon_image,
18071806
tint.r,
@@ -5923,7 +5922,8 @@ test "test_init" {
59235922
.minimum = .{ .width = 300, .height = 130 },
59245923
.layout = .{ .x = .fixed, .y = .fixed, .position = .float },
59255924
.background = .{ .colour = .{ .r = 99, .g = 150, .b = 50, .a = 255 } },
5926-
.type = .{ .rectangle = .{ .style = .background } },
5925+
.style = .background,
5926+
.type = .{ .rectangle = .{} },
59275927
};
59285928
try panel.add_element(allocator, element);
59295929
try eq(1, display.root.type.panel.children.items[0].type.panel.children.items.len);

src/theme.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ pub const Theme = struct {
3939
toggle_button_picked: Colour,
4040
toggle_button_correct: Colour,
4141
toggle_button_incorrect: Colour,
42+
43+
progress_bar_background: Colour,
44+
progress_bar_foreground: Colour,
4245
};
4346

4447
pub const ThemeColour = enum {
@@ -103,6 +106,8 @@ pub const default_themes = [5]Theme{
103106
.toggle_button_picked = .{ .r = 80, .g = 99, .b = 119, .a = 255 },
104107
.toggle_button_correct = .{ .r = 80, .g = 119, .b = 81, .a = 255 },
105108
.toggle_button_incorrect = .{ .r = 119, .g = 80, .b = 80, .a = 255 },
109+
.progress_bar_background = .{ .r = 31, .g = 34, .b = 48, .a = 255 },
110+
.progress_bar_foreground = .{ .r = 132, .g = 142, .b = 172, .a = 255 },
106111
},
107112
.{
108113
.tag = "midnight",
@@ -126,6 +131,8 @@ pub const default_themes = [5]Theme{
126131
.toggle_button_picked = .{ .r = 80, .g = 99, .b = 119, .a = 255 },
127132
.toggle_button_correct = .{ .r = 80, .g = 119, .b = 81, .a = 255 },
128133
.toggle_button_incorrect = .{ .r = 119, .g = 80, .b = 80, .a = 255 },
134+
.progress_bar_background = .{ .r = 47, .g = 58, .b = 69, .a = 255 },
135+
.progress_bar_foreground = .{ .r = 146, .g = 146, .b = 175, .a = 255 },
129136
},
130137

131138
.{
@@ -150,6 +157,8 @@ pub const default_themes = [5]Theme{
150157
.toggle_button_picked = .{ .r = 157, .g = 138, .b = 118, .a = 255 },
151158
.toggle_button_correct = .{ .r = 132, .g = 160, .b = 100, .a = 255 },
152159
.toggle_button_incorrect = .{ .r = 159, .g = 111, .b = 98, .a = 255 },
160+
.progress_bar_background = .{ .r = 210, .g = 200, .b = 190, .a = 255 },
161+
.progress_bar_foreground = .{ .r = 128, .g = 128, .b = 85, .a = 255 },
153162
},
154163

155164
.{
@@ -174,6 +183,8 @@ pub const default_themes = [5]Theme{
174183
.toggle_button_picked = .{ .r = 131, .g = 142, .b = 149, .a = 255 },
175184
.toggle_button_correct = .{ .r = 132, .g = 160, .b = 100, .a = 255 },
176185
.toggle_button_incorrect = .{ .r = 159, .g = 111, .b = 98, .a = 255 },
186+
.progress_bar_background = .{ .r = 217, .g = 230, .b = 242, .a = 255 },
187+
.progress_bar_foreground = .{ .r = 104, .g = 104, .b = 114, .a = 255 },
177188
},
178189
.{
179190
.tag = "garden",
@@ -197,6 +208,8 @@ pub const default_themes = [5]Theme{
197208
.toggle_button_picked = .{ .r = 80, .g = 99, .b = 119, .a = 255 },
198209
.toggle_button_correct = .{ .r = 80, .g = 119, .b = 81, .a = 255 },
199210
.toggle_button_incorrect = .{ .r = 119, .g = 80, .b = 80, .a = 255 },
211+
.progress_bar_background = .{ .r = 86, .g = 150, .b = 114, .a = 255 },
212+
.progress_bar_foreground = .{ .r = 136, .g = 194, .b = 136, .a = 255 },
200213
},
201214
};
202215

0 commit comments

Comments
 (0)