Skip to content

Commit db086b8

Browse files
author
Jay
committed
Improve warnings for misconfig
1 parent 37ee6cf commit db086b8

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

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.2.0",
3+
.version = "0.2.1",
44
.fingerprint = 0xe8a81a8d0aa558d5,
55
.minimum_zig_version = "0.14.1",
66
.dependencies = .{

src/engine.zig

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ pub const Element = struct {
355355
icon_hover_name: ?[]const u8 = "",
356356
icon_pressed: ?*TextureInfo = null,
357357
icon_pressed_name: ?[]const u8 = "",
358+
background_default_name: ?[]const u8 = null,
358359
background_hover: ?*TextureInfo = null,
359360
background_hover_name: ?[]const u8 = "",
360361
background_pressed: ?*TextureInfo = null,
@@ -4233,14 +4234,14 @@ pub const Display = struct {
42334234
display,
42344235
.{
42354236
.name = "back",
4236-
.icon_default_name = "icon-back",
4237-
.icon_pressed_name = "icon-back",
4238-
.icon_hover_name = "icon-back",
42394237
.focus = .can_focus,
42404238
.rect = .{ .x = 20, .y = 20, .width = 120, .height = 120 },
42414239
.pad = .{ .left = 20, .right = 20, .top = 20, .bottom = 20 },
42424240
.layout = .{ .x = .fixed, .y = .fixed, .position = .float },
42434241
.type = .{ .button = .{
4242+
.icon_default_name = "icon-back",
4243+
.icon_pressed_name = "icon-back",
4244+
.icon_hover_name = "icon-back",
42444245
.text = "",
42454246
.translated = "",
42464247
.on_click = close_fn,
@@ -4616,19 +4617,17 @@ pub fn setup_label(
46164617
allocator: Allocator,
46174618
element: *Element,
46184619
) (error{ OutOfMemory, UnknownImageFormat, ResourceNotFound, ResourceReadError } || ResourcesError)!void {
4620+
element.texture = null;
4621+
element.background_texture = null;
46194622
element.type.label.translated = "";
4623+
element.type.label.elements = .empty;
46204624

46214625
if (element.focus == .unspecified) {
4622-
if (element.type.label.on_click != null) {
4623-
element.focus = .can_focus;
4624-
} else {
4626+
if (element.type.label.on_click != null)
4627+
element.focus = .can_focus
4628+
else
46254629
element.focus = .accessibility_focus;
4626-
}
46274630
}
4628-
element.texture = null;
4629-
element.background_texture = null;
4630-
4631-
element.type.label.elements = .empty;
46324631
try element.set_text(allocator, self, element.type.label.text, true);
46334632

46344633
// Is there a background for this label?
@@ -4719,19 +4718,22 @@ pub fn setup_button(
47194718
allocator: Allocator,
47204719
element: *Element,
47214720
) (error{ OutOfMemory, UnknownImageFormat, ResourceNotFound, ResourceReadError } || ResourcesError)!void {
4721+
element.type.button.translated = "";
47224722
element.texture = null;
47234723
element.background_texture = null;
4724-
if (element.focus == .unspecified)
4725-
element.focus = .can_focus;
4726-
4727-
element.type.button.translated = "";
47284724
element.type.button.icon_pressed = null;
47294725
element.type.button.icon_hover = null;
47304726
element.type.button.background_pressed = null;
47314727
element.type.button.background_hover = null;
47324728

4729+
if (element.focus == .unspecified)
4730+
element.focus = .can_focus;
4731+
47334732
if (element.texture_name != null)
4734-
warn("button named `{s}` has texture_name `{s}`. Buttons do not use `texture_name`", .{ element.name, element.texture_name.? });
4733+
warn("button named `{s}` has texture_name `{s}`. Buttons use `icon_default_name`", .{ element.name, element.texture_name.? });
4734+
4735+
if (element.background_texture_name != null)
4736+
warn("button named `{s}` has background_texture_name `{s}`. Buttons do not use `background_default_name`", .{ element.name, element.background_texture_name.? });
47354737

47364738
try element.set_text(allocator, display, element.type.button.text, true);
47374739

@@ -4763,7 +4765,7 @@ pub fn setup_button(
47634765
element.type.button.icon_hover = element.texture.?.clone();
47644766
}
47654767

4766-
if (element.background_texture_name) |background_default| {
4768+
if (element.type.button.background_default_name) |background_default| {
47674769
if (try display.load_texture_resource(allocator, background_default)) |texture|
47684770
element.background_texture = texture
47694771
else

0 commit comments

Comments
 (0)