picker
To pick between the built in themes, pass &Theme.builtins as the themes argument
Sets the theme on the current dvui.Window upon selection
Parameters
- src:std.builtin.SourceLocation
- std.builtin.SourceLocation
- themes:[]const Theme
- []const Theme
- opts:Options
- Options
Source
Implementation
pub fn picker(src: std.builtin.SourceLocation, themes: []const Theme, opts: Options) bool {
var picked = false;
const defaults: Options = .{
.name = "Theme Picker",
.min_size_content = .{ .w = 120 },
};
const options = defaults.override(opts);
const current_theme_name = dvui.themeGet().name;
const theme_choice: ?usize = for (themes, 0..) |val, i| {
if (std.mem.eql(u8, current_theme_name, val.name)) {
break i;
}
} else null;
var dd: dvui.DropdownWidget = undefined;
dd.init(
src,
.{ .selected_index = theme_choice, .label = current_theme_name },
options,
);
if (dd.dropped()) {
for (themes) |theme| {
if (dd.addChoiceLabel(theme.name)) {
dvui.themeSet(theme);
picked = true;
break;
}
}
}
dd.deinit();
return picked;
}