expander
Parameters
- self:*Branch
- *Branch
- src:std.builtin.SourceLocation
- std.builtin.SourceLocation
- init_opts:ExpanderOptions
- ExpanderOptions
- opts:Options
- Options
Source
Implementation
pub fn expander(self: *Branch, src: std.builtin.SourceLocation, init_opts: ExpanderOptions, opts: Options) bool {
var clicked: bool = false;
if (self.button.clicked()) {
clicked = true;
}
self.hbox.deinit();
self.button.deinit();
const default_opts = Options{
.name = "Expander",
.margin = .{ .x = init_opts.indent },
};
self.anim = dvui.animate(
@src(),
.{
.duration = self.init_options.animation_duration,
.easing = self.init_options.animation_easing,
.kind = if (self.init_options.animation_duration > 0) .vertical else .none,
},
default_opts.override(opts),
);
if (clicked) {
if (self.expanded) {
self.anim.?.init_opts.easing = dvui.easing.outQuad;
self.anim.?.init_opts.duration = @divTrunc(self.init_options.animation_duration, 2);
self.anim.?.startEnd();
} else {
self.anim.?.val = 0.0;
self.anim.?.start();
self.expanded = true;
}
}
if (self.anim.?.end()) {
self.expanded = false;
}
if (self.expanded) {
// Always expand the inner box to fill the animation
const expander_opts = dvui.Options{ .expand = .both };
self.expander_vbox.init(src, .{ .dir = .vertical }, expander_opts.override(opts.strip()));
self.expander_vbox.drawBackground();
}
self.can_expand = true;
return self.expanded;
}