headerCell
Create a header cell for the requested column Returns a hbox for the created cell.
- deinit() must be called on this hbox before any new cells are created.
- header cells can be created in any order, but it is more efficient to create them from left to right.
- no header cells should be created after the first body cell is created.
Parameters
- self:*GridWidget
- *GridWidget
- src:std.builtin.SourceLocation
- std.builtin.SourceLocation
- col_num:usize
- usize
- opts:CellOptions
- CellOptions
Source
Implementation
pub fn headerCell(self: *GridWidget, src: std.builtin.SourceLocation, col_num: usize, opts: CellOptions) *BoxWidget {
if (self.hscroll == null) {
if (self.bscroll != null) {
dvui.log.debug("GridWidget {x} all header cells must be created before any body cells. Header will be placed in body.\n", .{self.data().id});
dvui.Debug.errorOutline(self.bscroll.?.data().rectScale().r);
} else {
self.headerScrollAreaCreate();
}
}
const header_width: f32 = width: {
if (opts.width() > 0) {
break :width opts.width();
} else {
break :width self.colWidth(col_num);
}
};
const header_height: f32 = height: {
if (opts.height() > 0) {
break :height if (self.resizing) opts.height() else @max(opts.height(), self.header_height);
} else {
break :height if (self.resizing) 0 else self.header_height;
}
};
var cell_opts = opts.toOptions();
const pos_x = self.posX(col_num);
cell_opts.rect = .{ .x = pos_x, .y = 0, .w = header_width, .h = header_height };
cell_opts.id_extra = col_num;
// Create the cell and install as parent.
var cell = dvui.box(src, .{ .dir = .horizontal }, cell_opts);
const first_frame = dvui.firstFrame(cell.data().id);
// Determine heights for next frame.
if (!first_frame) {
const cell_size = cell.data().rect.size();
self.header_height = @max(self.header_height, cell_size.h);
self.colWidthSet(col_num, cell_size.w);
}
return cell;
}