@@ -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 );
0 commit comments