Skip to content

Commit e2244b1

Browse files
committed
Remove set_text forced flag
1 parent 9504afc commit e2244b1

3 files changed

Lines changed: 17 additions & 16 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.9.12",
3+
.version = "0.9.13",
44
.fingerprint = 0xe8a81a8d0aa558d5,
55
.minimum_zig_version = "0.15.2",
66
.dependencies = .{

src/element.zig

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,15 @@ pub const Element = struct {
626626

627627
/// set_text updates the `text` and `translation` fields of labels,
628628
/// checkboxes and buttons, and regenerates the grahpics/image
629-
/// textures for each word if the text was changed or `forced`
630-
/// is requested.
629+
/// textures for each word if the text was changed.
630+
///
631+
/// The memory behind the `new_text` must remain valid while the element
632+
/// exists and is displaying this string.
631633
pub inline fn set_text(
632634
self: *Element,
633635
allocator: Allocator,
634636
display: *Display,
635637
new_text: []const u8,
636-
forced: bool,
637638
) error{OutOfMemory}!void {
638639
const old_translated = switch (self.type) {
639640
.text_input => self.type.text_input.text.items,
@@ -664,9 +665,9 @@ pub const Element = struct {
664665
old_translated,
665666
new_translated,
666667
});
667-
if (std.mem.eql(u8, new_translated, old_translated) and !forced) {
668-
// Don't update if nothing changed
669-
// TODO: This should not be needed
668+
if (std.mem.eql(u8, new_translated, old_translated)) {
669+
// Do nothing if the text has not changed. This assumes that
670+
// the original text buffer was not modified.
670671
return;
671672
}
672673

@@ -1026,9 +1027,9 @@ pub const Element = struct {
10261027
/// a chance to regenerate its translation and text texture.
10271028
pub fn language_changed(self: *Element, allocator: Allocator, display: *Display, lang: Lang) !void {
10281029
switch (self.type) {
1029-
.label => try self.set_text(allocator, display, self.type.label.text, false),
1030-
.checkbox => try self.set_text(allocator, display, self.type.checkbox.text, false),
1031-
.button => try self.set_text(allocator, display, self.type.button.text, false),
1030+
.label => try self.set_text(allocator, display, self.type.label.text),
1031+
.checkbox => try self.set_text(allocator, display, self.type.checkbox.text),
1032+
.button => try self.set_text(allocator, display, self.type.button.text),
10321033
.panel => for (self.type.panel.children.items) |child| {
10331034
try child.language_changed(allocator, display, lang);
10341035
},

src/engine.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,7 +2822,7 @@ pub fn setup_checkbox(
28222822
if (element.focus == .unspecified)
28232823
element.focus = .can_focus;
28242824

2825-
try element.set_text(allocator, self, element.type.checkbox.text, true);
2825+
try element.set_text(allocator, self, element.type.checkbox.text);
28262826

28272827
if (try self.load_texture(allocator, "ios-checkbox-on")) |texture| {
28282828
element.type.checkbox.on_texture = texture;
@@ -2879,7 +2879,7 @@ pub fn setup_label(
28792879
else
28802880
element.focus = .accessibility_focus;
28812881
}
2882-
try element.set_text(allocator, self, element.type.label.text, true);
2882+
try element.set_text(allocator, self, element.type.label.text);
28832883

28842884
// Is there a background for this label?
28852885
if (element.background.image_name) |name| {
@@ -2934,9 +2934,9 @@ pub fn setup_text_input(
29342934
element.type.text_input.text = .empty;
29352935
element.type.text_input.runes = .empty;
29362936
if (element.type.text_input.initial_text) |text| {
2937-
try element.set_text(allocator, self, text, true);
2937+
try element.set_text(allocator, self, text);
29382938
} else {
2939-
try element.set_text(allocator, self, "", true);
2939+
try element.set_text(allocator, self, "");
29402940
}
29412941
if (element.type.text_input.placeholder_text) |text| {
29422942
try element.set_placeholder_text(allocator, self, text);
@@ -3031,7 +3031,7 @@ pub fn setup_button(
30313031
element.background.image_name.?,
30323032
});
30333033

3034-
try element.set_text(allocator, display, element.type.button.text, true);
3034+
try element.set_text(allocator, display, element.type.button.text);
30353035

30363036
if (element.type.button.icon_default_name) |icon_default| {
30373037
if (try display.load_texture(allocator, icon_default)) |texture| {
@@ -3535,7 +3535,7 @@ test "button sizing" {
35353535
try std.testing.expect(display.resources.by_uid.count() > 0);
35363536
_ = try display.load_font(allocator, "Roboto-Light");
35373537

3538-
try button.set_text(allocator, display, "Hello", true);
3538+
try button.set_text(allocator, display, "Hello");
35393539
display.relayout();
35403540
try eq(83, @trunc(button.rect.width));
35413541
try eq(100, @trunc(panel.rect.width));

0 commit comments

Comments
 (0)