checkmark
Parameters
Source
Implementation
pub fn checkmark(checked: bool, focused: bool, rs: RectScale, pressed: bool, hovered: bool, opts: Options) void {
const cornerRad = opts.cornersGet().finalize(opts.theme).scale(rs.s, CornerRect.Physical);
rs.r.fill(cornerRad, .{ .color = opts.color(.border), .fade = 1.0 });
if (focused) {
rs.r.stroke(cornerRad, .{ .thickness = 2 * rs.s, .color = dvui.themeGet().focus });
}
var fill: Options.ColorAsk = .fill;
if (pressed) {
fill = .fill_press;
} else if (hovered) {
fill = .fill_hover;
}
var options = opts;
if (checked) {
options.style = .highlight;
rs.r.insetAll(0.5 * rs.s).fill(cornerRad, .{ .color = options.color(fill), .fade = 1.0 });
} else {
rs.r.insetAll(rs.s).fill(cornerRad, .{ .color = options.color(fill), .fade = 1.0 });
}
if (checked) {
const r = rs.r.insetAll(0.5 * rs.s);
const pad = @max(1.0, r.w / 6);
var thick = @max(1.0, r.w / 5);
const size = r.w - (thick / 2) - pad * 2;
const third = size / 3.0;
const x = r.x + pad + (0.25 * thick) + third;
const y = r.y + pad + (0.25 * thick) + size - (third * 0.5);
thick /= 1.5;
const path: Path = .{ .points = &.{
.{ .x = x - third, .y = y - third },
.{ .x = x, .y = y },
.{ .x = x + third * 2, .y = y - third * 2 },
} };
path.stroke(.{ .thickness = thick, .color = options.color(.text), .endcap_style = .square });
}
}