1
0
Fork 0

Compare commits

...

2 commits

2 changed files with 29 additions and 0 deletions

27
src/WidgetIter.zig Normal file
View file

@ -0,0 +1,27 @@
//! This is a iterator to iterate over the widget tree
//! Depth-first
const std = @import("std");
const Widget = @import("widget.zig").Widget;
current: *Widget,
const WidgetIter = @This();
pub fn next(self: *WidgetIter) ?*Widget {
var last: ?*Widget = null;
while (true) {
const children = self.current.children();
const slice = if (last) |l|
children[std.mem.indexOfScalar(*Widget, children, l).? + 1 ..]
else
children;
if (slice.len == 0) {
last = self.current;
self.current = self.current.data.parent orelse return null;
} else {
self.current = slice[0];
return self.current;
}
}
}

View file

@ -16,6 +16,7 @@ test {
_ = widget;
_ = Color;
_ = WidgetIter;
}
pub const attreebute = @import("attreebute.zig");
@ -31,6 +32,7 @@ pub const util = @import("util.zig");
pub const widget = @import("widget.zig");
pub const Color = @import("Color.zig");
pub const WidgetIter = @import("WidgetIter.zig");
/// List of the default widget implementations included with Zenolith.
/// If you set zenolith_options.widget_impls, include this if you want to use Zenolith's widgets.