feat: add support for resize hooks on WidgetLists
This commit is contained in:
parent
e0c78a975e
commit
1489a96013
1 changed files with 10 additions and 4 deletions
|
@ -24,6 +24,8 @@ widgets: ArrayList(WidgetState),
|
|||
layout: Layout,
|
||||
direction: Direction,
|
||||
box: ?Widget.Box = null,
|
||||
on_resize: *const fn (ctx: ?*anyopaque, self: *Self, pos_: Widget.Box) void = on_resize_default,
|
||||
on_resize_ctx: ?*anyopaque = null,
|
||||
|
||||
pub fn createH(a: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self {
|
||||
const self: *Self = try a.create(Self);
|
||||
|
@ -166,14 +168,18 @@ fn get_loc_b(self: *Self, pos: *Widget.Box) *usize {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn resize(self: *Self, pos: Widget.Box) void {
|
||||
return self.handle_resize(pos);
|
||||
}
|
||||
|
||||
fn refresh_layout(self: *Self) void {
|
||||
return if (self.box) |box| self.handle_resize(box);
|
||||
}
|
||||
|
||||
pub fn resize(self: *Self, pos: Widget.Box) void {
|
||||
return self.on_resize(self.on_resize_ctx, self, pos);
|
||||
}
|
||||
|
||||
fn on_resize_default(_: ?*anyopaque, self: *Self, pos: Widget.Box) void {
|
||||
self.handle_resize(pos);
|
||||
}
|
||||
|
||||
pub fn handle_resize(self: *Self, pos_: Widget.Box) void {
|
||||
self.box = pos_;
|
||||
var pos = pos_;
|
||||
|
|
Loading…
Add table
Reference in a new issue