DVUI

init

It's expected to call this when self is undefined

Parameters

#
self:*ScrollContainerWidget
*ScrollContainerWidget
src:std.builtin.SourceLocation
std.builtin.SourceLocation
io_scroll_info:*ScrollInfo
*ScrollInfo
init_options:InitOptions
InitOptions
opts:Options
Options

Source

Implementation

#
pub fn init(self: *ScrollContainerWidget, src: std.builtin.SourceLocation, io_scroll_info: *ScrollInfo, init_options: InitOptions, opts: Options) void {
    const options = defaults.override(opts);
    self.* = .{
        .wd = WidgetData.init(src, .{}, options),
        .si = io_scroll_info,
        .init_opts = init_options,
        .last_focus = dvui.lastFocusedIdInFrame(),
        .subwindowId = dvui.subwindowCurrentId(),
    };

    if (self.init_opts.user_scroll) |us| us.* = .{};

    if (dvui.dataGet(null, self.data().id, "_finger_down", bool)) |down| self.finger_down = down;

    const crect = self.data().contentRect();
    self.si.viewport.w = crect.w;
    self.si.viewport.h = crect.h;

    self.data().register();

    if (self.init_opts.scroll_area) |sa| {
        sa.setContainerRect(crect);
    }

    switch (self.si.horizontal) {
        .none => self.si.virtual_size.w = crect.w,
        .auto => {},
        .given => {},
    }
    switch (self.si.vertical) {
        .none => self.si.virtual_size.h = crect.h,
        .auto => {},
        .given => {},
    }

    self.data().borderAndBackground(.{});

    self.prevClip = dvui.clip(self.data().contentRectScale().r);

    self.frame_viewport = self.init_opts.frame_viewport orelse self.si.viewport.topLeft();

    self.lock_visible = self.init_opts.lock_visible;
    if (self.lock_visible) {
        self.first_visible_id = dvui.dataGet(null, self.data().id, "_fv_id", dvui.Id) orelse blk: {
            dvui.log.debug("ScrollContainerWidget forcing lock_visible false due to not having a first visible widget\n", .{});
            self.lock_visible = false;
            break :blk .zero;
        };
        self.first_visible_offset = dvui.dataGet(null, self.data().id, "_fv_offset", Point) orelse .{};
        self.first_visible_viewport = dvui.dataGet(null, self.data().id, "_fv_viewport", Point) orelse .{};
    }

    dvui.parentSet(self.widget());
    self.parentScroll = scrollSet(self);
}