DVUI

addChoice

Parameters

#
self:*DropdownWidget
*DropdownWidget

Source

Implementation

#
pub fn addChoice(self: *DropdownWidget) *MenuItemWidget {
    // record how far down in our parent we would be
    if (self.drop_mi_id) |mid| {
        if (dvui.minSizeGet(mid)) |ms| {
            self.drop_height += ms.h;
        }
    }

    self.drop_mi.init(@src(), .{}, self.options.styleOnly().override(.{
        .role = .list_item,
        .label = .{ .label_widget = .next },
        .id_extra = self.drop_mi_index,
        .expand = .horizontal,
    }));
    self.drop_mi_id = self.drop_mi.data().id;
    self.drop_mi.processEvents();
    self.drop_mi.drawBackground();

    if (self.drop_first_frame) {
        if (self.init_options.selected_index) |si| {
            if (si == self.drop_mi_index) {
                dvui.focusWidget(self.drop_mi.data().id, null, null);
                dvui.dataSet(null, self.data().id, "_drop_adjust", self.drop_height);
            }
        } else if (self.drop_mi_index == 0) {
            dvui.focusWidget(self.drop_mi.data().id, null, null);
            dvui.dataSet(null, self.data().id, "_drop_adjust", self.drop_height);
        }
    }
    self.drop_mi_index += 1;

    return &self.drop_mi;
}