Skip to content

Commit f7bf34c

Browse files
committed
- Fixup plotBarsValues
- Add TagX/Y functions
1 parent b68a14a commit f7bf34c

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

src/plot.zig

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,11 @@ fn PlotBarsValuesGen(comptime T: type) type {
604604
};
605605
}
606606
pub fn plotBarsValues(label_id: [:0]const u8, comptime T: type, args: PlotBarsValuesGen(T)) void {
607-
assert(args.xv.len == args.yv.len);
608-
zguiPlot_PlotBars(
607+
zguiPlot_PlotBarsValues(
609608
label_id,
610609
gui.typeToDataTypeEnum(T),
611610
args.v.ptr,
612-
@as(i32, @intCast(args.xv.len)),
611+
@as(i32, @intCast(args.v.len)),
613612
args.bar_size,
614613
args.shift,
615614
args.flags,
@@ -655,6 +654,30 @@ pub fn dragPoint(id: i32, args: DragPoint) bool {
655654
}
656655
extern fn zguiPlot_DragPoint(id: i32, x: *f64, y: *f64, *const [4]f32, size: f32, flags: DragToolFlags) bool;
657656
//----------------------------------------------------------------------------------------------
657+
pub const Tag = struct {
658+
round: bool = false,
659+
};
660+
661+
pub fn tagX(x: f64, col: [4]f32, args: Tag) void {
662+
zguiPlot_TagX(x, &col, args.round);
663+
}
664+
extern fn zguiPlot_TagX(x: f64, col: *const [4]f32, round: bool) void;
665+
666+
pub fn tagXText(x: f64, col: [4]f32, comptime fmt: []const u8, fmt_args: anytype) void {
667+
zguiPlot_TagXText(x, &col, "%s", gui.formatZ(fmt, fmt_args).ptr);
668+
}
669+
extern fn zguiPlot_TagXText(x: f64, col: *const [4]f32, fmt: [*:0]const u8, ...) void;
670+
671+
pub fn tagY(y: f64, col: [4]f32, args: Tag) void {
672+
zguiPlot_TagY(y, &col, args.round);
673+
}
674+
extern fn zguiPlot_TagY(y: f64, col: *const [4]f32, round: bool) void;
675+
676+
pub fn tagYText(y: f64, col: [4]f32, comptime fmt: []const u8, fmt_args: anytype) void {
677+
zguiPlot_TagYText(y, &col, "%s", gui.formatZ(fmt, fmt_args).ptr);
678+
}
679+
extern fn zguiPlot_TagYText(y: f64, col: *const [4]f32, fmt: [*:0]const u8, ...) void;
680+
//----------------------------------------------------------------------------------------------
658681
// PlotText
659682
const PlotTextFlags = packed struct(u32) {
660683
vertical: bool = false,

src/zplot.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,32 @@ extern "C"
352352
flags);
353353
}
354354

355+
ZGUI_API void zguiPlot_TagX(double x, float col[4], bool round)
356+
{
357+
ImPlot::TagX(x, (*(const ImVec4 *)&(col[0])), round);
358+
}
359+
360+
ZGUI_API void zguiPlot_TagXText(double x, float col[4], const char *fmt, ...)
361+
{
362+
va_list args;
363+
va_start(args, fmt);
364+
ImPlot::TagXV(x, (*(const ImVec4 *)&(col[0])), fmt, args);
365+
va_end(args);
366+
}
367+
368+
ZGUI_API void zguiPlot_TagY(double y, float col[4], bool round)
369+
{
370+
ImPlot::TagY(y, (*(const ImVec4 *)&(col[0])), round);
371+
}
372+
373+
ZGUI_API void zguiPlot_TagYText(double y, float col[4], const char *fmt, ...)
374+
{
375+
va_list args;
376+
va_start(args, fmt);
377+
ImPlot::TagYV(y, (*(const ImVec4 *)&(col[0])), fmt, args);
378+
va_end(args);
379+
}
380+
355381
ZGUI_API void zguiPlot_PlotText(
356382
const char *text,
357383
double x, double y,

0 commit comments

Comments
 (0)