pointToCell
Convert a screen physical coord into a grid cell position. Not valid when using variable row heights.
Parameters
- self:*GridWidget
- *GridWidget
- point:Point.Physical
- Point.Physical
Source
Implementation
pub fn pointToCell(self: *GridWidget, point: Point.Physical) ?Cell {
if (self.init_opts.row_height_variable) return null;
if (self.resizing or self.init_opts.resize_cols) return null;
if (self.row_height < 1) return null;
if (self.pointToBodyRelative(point)) |point_rel| {
const row_num: usize = @trunc((self.frame_viewport.y + point_rel.y) / self.row_height);
const col_num = blk: {
var total_w: f32 = 0;
for (self.col_widths, 0..) |w, col| {
total_w += w;
if (point_rel.x < total_w) {
break :blk col;
}
}
return null;
};
return .{ .col_num = col_num, .row_num = row_num };
}
return null;
}