parent
ad388687cd
commit
f925e5736c
|
@ -135,18 +135,22 @@ fn Prototype(comptime Self: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the child at position or the last child if position is null.
|
/// Removes the child at position or the last child if position is null.
|
||||||
/// The function then returns the removed child.
|
/// The function then unlinks and returns the removed child.
|
||||||
/// The caller must ensure that position is less than children().len and children() is not
|
/// The caller must ensure that position is less than children().len and children() is not
|
||||||
/// empty, otherwise, undefined behaviour is invoked.
|
/// empty, otherwise, undefined behaviour is invoked.
|
||||||
/// Returns error.Unsupported if the widget does not support such functionality.
|
/// Returns error.Unsupported if the widget does not support such functionality.
|
||||||
pub fn removeChild(self: *Self, position: usize) !*Widget {
|
pub fn removeChild(self: *Self, position: ?usize) !*Widget {
|
||||||
return statspatch.implcallOptional(
|
const child = try (statspatch.implcallOptional(
|
||||||
self,
|
self,
|
||||||
.ptr,
|
.ptr,
|
||||||
"removeChild",
|
"removeChild",
|
||||||
anyerror!void,
|
anyerror!*Widget,
|
||||||
.{ self, position },
|
.{ self, position },
|
||||||
) orelse error.Unsupported;
|
) orelse return error.Unsupported);
|
||||||
|
|
||||||
|
try child.unlink();
|
||||||
|
|
||||||
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if self is a child widget of other.
|
/// Returns true if self is a child widget of other.
|
||||||
|
@ -169,6 +173,7 @@ fn Prototype(comptime Self: type) type {
|
||||||
/// the widget tree.
|
/// the widget tree.
|
||||||
/// It is safe to deinitialize the subtree after it has been unlinked.
|
/// It is safe to deinitialize the subtree after it has been unlinked.
|
||||||
pub fn unlink(self: *Self) !void {
|
pub fn unlink(self: *Self) !void {
|
||||||
|
zenolith.log.debug("child {s}@{x} unlinked", .{ @tagName(self.u), @intFromPtr(self) });
|
||||||
try (statspatch.implcallOptional(self, .ptr, "unlink", anyerror!void, .{self}) orelse {});
|
try (statspatch.implcallOptional(self, .ptr, "unlink", anyerror!void, .{self}) orelse {});
|
||||||
|
|
||||||
self.data.parent = null;
|
self.data.parent = null;
|
||||||
|
|
|
@ -249,7 +249,7 @@ pub fn addChildPositioned(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn removeChild(self: *Box, selfw: *Widget, position: ?usize) void {
|
pub fn removeChild(self: *Box, selfw: *Widget, position: ?usize) *Widget {
|
||||||
_ = selfw;
|
_ = selfw;
|
||||||
if (position) |pos| {
|
if (position) |pos| {
|
||||||
const old = self.children.get(pos).widget;
|
const old = self.children.get(pos).widget;
|
||||||
|
|
Loading…
Reference in a new issue