Compare commits
2 commits
ff9c651272
...
a899c90a14
Author | SHA1 | Date | |
---|---|---|---|
LordMZTE | a899c90a14 | ||
5d38cea63a |
27
src/WidgetIter.zig
Normal file
27
src/WidgetIter.zig
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue