gridHeadingCheckbox
A grid heading with a checkbox for select-all and select-none
Returns true if the selection state has changed. selection - out parameter containing the current selection state.
Parameters
- src:std.builtin.SourceLocation
- std.builtin.SourceLocation
- g:*GridWidget
- *GridWidget
- col_num:usize
- usize
- select_state:*selection.SelectAllState
- *selection.SelectAllState
- cell_style:anytype
- anytype
Source
Implementation
pub fn gridHeadingCheckbox(
src: std.builtin.SourceLocation,
g: *GridWidget,
col_num: usize,
select_state: *selection.SelectAllState,
cell_style: anytype, // GridWidget.CellStyle
) bool {
const header_defaults: Options = .{
.background = true,
.expand = .both,
.margin = ButtonWidget.defaults.marginGet(),
.gravity_x = 0.5,
.gravity_y = 0.5,
};
const opts = if (@TypeOf(cell_style) == @TypeOf(.{})) GridWidget.CellStyle.none else cell_style;
const header_options = header_defaults.override(opts.options(.col(col_num)));
var checkbox_opts: Options = header_options.strip();
checkbox_opts.padding = ButtonWidget.defaults.paddingGet();
checkbox_opts.gravity_x = header_options.gravity_x;
checkbox_opts.gravity_y = header_options.gravity_y;
var checkbox_wd: WidgetData = undefined;
checkbox_opts.data_out = &checkbox_wd;
var cell = g.headerCell(src, col_num, opts.cellOptions(.col(col_num)));
defer cell.deinit();
var is_clicked = false;
var selected = select_state.* == .select_all;
{
_ = dvui.separator(@src(), .{ .expand = .vertical, .gravity_x = 1.0 });
var hbox = dvui.box(@src(), .{ .dir = .horizontal }, header_options);
defer hbox.deinit();
is_clicked = dvui.checkbox(@src(), &selected, null, checkbox_opts);
}
if (is_clicked) {
select_state.* = if (selected) .select_all else .select_none;
}
if (checkbox_wd.accesskit_node()) |ak_node| {
AccessKit.nodeSetLabel(ak_node, if (select_state.* == .select_all) "Select none" else "Select all");
}
return is_clicked;
}