init
It's expected to call this when self is undefined
Parameters
- self:*AnimateWidget
- *AnimateWidget
- src:std.builtin.SourceLocation
- std.builtin.SourceLocation
- init_opts:InitOptions
- InitOptions
- opts:Options
- Options
Source
Implementation
pub fn init(self: *AnimateWidget, src: std.builtin.SourceLocation, init_opts: InitOptions, opts: Options) void {
const defaults = Options{ .name = "Animate" };
self.* = .{ .wd = WidgetData.init(src, .{}, defaults.override(opts)), .init_opts = init_opts };
if (self.init_opts.kind != .none) {
if (dvui.firstFrame(self.data().id)) {
// start begin animation
self.start();
}
if (dvui.animationGet(self.data().id, "_end")) |a| {
self.val = a.value();
} else if (dvui.animationGet(self.data().id, "_start")) |a| {
self.val = a.value();
}
}
if (self.val) |v| {
switch (self.init_opts.kind) {
.none => {},
.alpha => {
self.prev_alpha = dvui.alpha(v);
},
.vertical => {
if (dvui.minSizeGet(self.data().id)) |ms| {
if (self.data().rect.h > ms.h + 0.001) {
// we are bigger than our min size (maybe expanded) - account for floating point
const h = self.data().rect.h;
self.data().rect.h *= @max(v, 0);
self.data().rect.y += self.data().options.gravityGet().y * (h - self.data().rect.h);
}
}
},
.horizontal => {
if (dvui.minSizeGet(self.data().id)) |ms| {
if (self.data().rect.w > ms.w + 0.001) {
// we are bigger than our min size (maybe expanded) - account for floating point
const w = self.data().rect.w;
self.data().rect.w *= @max(v, 0);
self.data().rect.x += self.data().options.gravityGet().x * (w - self.data().rect.w);
}
}
},
}
}
dvui.parentSet(self.widget());
self.data().register();
self.data().borderAndBackground(.{});
}