bar
Parameters
- self:*PlotWidget
- *PlotWidget
- opts:BarOptions
- BarOptions
Source
Implementation
pub fn bar(self: *PlotWidget, opts: BarOptions) void {
const dp1 = Data{ .x = opts.x, .y = opts.y };
const dp2 = Data{ .x = opts.x + opts.w, .y = opts.y + opts.h };
self.dataForRange(dp1);
self.dataForRange(dp2);
const sp1 = self.dataToScreen(dp1);
const sp2 = self.dataToScreen(dp2);
if (self.mouse_point) |mp| {
const smin: dvui.Point.Physical = .{ .x = @min(sp1.x, sp2.x), .y = @min(sp1.y, sp2.y) };
const smax: dvui.Point.Physical = .{ .x = @max(sp1.x, sp2.x), .y = @max(sp1.y, sp2.y) };
const srect = dvui.Rect.Physical{
.x = smin.x,
.y = smin.y,
.w = smax.x - smin.x,
.h = smax.y - smin.y,
};
if (srect.contains(mp)) {
self.hover_data = .{ .bar = .{
.x = opts.x,
.y = opts.y,
.w = opts.w,
.h = opts.h,
} };
}
}
dvui.Path.fillConvex(
.{
.points = &.{
sp1,
.{ .x = sp2.x, .y = sp1.y },
sp2,
.{ .x = sp1.x, .y = sp2.y },
},
},
.{ .color = opts.color orelse dvui.themeGet().focus },
);
}