refactor: add Widget.get_at function
This commit is contained in:
parent
3437f4fd20
commit
c02a5d939c
1 changed files with 11 additions and 7 deletions
|
|
@ -115,6 +115,17 @@ pub fn addP(self: *Self, w_: Widget) !*Widget {
|
||||||
return &w.widget;
|
return &w.widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get(self: *Self, name_: []const u8) ?*Widget {
|
||||||
|
for (self.widgets.items) |*w|
|
||||||
|
if (w.widget.get(name_)) |p|
|
||||||
|
return p;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_at(self: *const Self, n: usize) ?*Widget {
|
||||||
|
return if (n < self.widgets.items.len) &self.widgets.items[n].widget else null;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn remove(self: *Self, w: Widget) void {
|
pub fn remove(self: *Self, w: Widget) void {
|
||||||
for (self.widgets.items, 0..) |p, i| if (p.widget.ptr == w.ptr) {
|
for (self.widgets.items, 0..) |p, i| if (p.widget.ptr == w.ptr) {
|
||||||
self.widgets.orderedRemove(i).widget.deinit(self.allocator);
|
self.widgets.orderedRemove(i).widget.deinit(self.allocator);
|
||||||
|
|
@ -391,13 +402,6 @@ fn do_resize(self: *Self, padding: Widget.Style.Margin) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(self: *Self, name_: []const u8) ?*Widget {
|
|
||||||
for (self.widgets.items) |*w|
|
|
||||||
if (w.widget.get(name_)) |p|
|
|
||||||
return p;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn walk(self: *Self, ctx: *anyopaque, f: Widget.WalkFn, self_w: *Widget) bool {
|
pub fn walk(self: *Self, ctx: *anyopaque, f: Widget.WalkFn, self_w: *Widget) bool {
|
||||||
for (self.widgets.items) |*w|
|
for (self.widgets.items) |*w|
|
||||||
if (w.widget.walk(ctx, f)) return true;
|
if (w.widget.walk(ctx, f)) return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue