Skip to content

Commit ca4f1b8

Browse files
Added addTextExtended and addTextExtendedUnformatted for additional AddText Functionalities (#55)
1 parent c07ccc0 commit ca4f1b8

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/gui.zig

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4551,6 +4551,53 @@ pub const DrawList = *opaque {
45514551
text: [*]const u8,
45524552
text_end: [*]const u8,
45534553
) void;
4554+
const AddTextArgs = struct {
4555+
font: ?Font,
4556+
font_size: f32,
4557+
wrap_width: f32 = 0,
4558+
cpu_fine_clip_rect: ?[*]const [4]f32 = null,
4559+
};
4560+
pub fn addTextExtended(
4561+
draw_list: DrawList,
4562+
pos: [2]f32,
4563+
col: u32,
4564+
comptime fmt: []const u8,
4565+
args: anytype,
4566+
add_text_args: AddTextArgs,
4567+
) void {
4568+
const txt = format(fmt, args);
4569+
addTextExtendedUnformatted(draw_list, pos, col, txt, add_text_args);
4570+
}
4571+
pub fn addTextExtendedUnformatted(
4572+
draw_list: DrawList,
4573+
pos: [2]f32,
4574+
col: u32,
4575+
txt: []const u8,
4576+
add_text_args: AddTextArgs,
4577+
) void {
4578+
zguiDrawList_AddTextExtended(
4579+
draw_list,
4580+
add_text_args.font,
4581+
add_text_args.font_size,
4582+
&pos,
4583+
col,
4584+
txt.ptr,
4585+
txt.ptr + txt.len,
4586+
add_text_args.wrap_width,
4587+
add_text_args.cpu_fine_clip_rect,
4588+
);
4589+
}
4590+
extern fn zguiDrawList_AddTextExtended(
4591+
draw_list: DrawList,
4592+
font: ?Font,
4593+
font_size: f32,
4594+
pos: *const [2]f32,
4595+
col: u32,
4596+
text: [*]const u8,
4597+
text_end: [*]const u8,
4598+
wrap_width: f32,
4599+
cpu_fine_clip_rect: ?[*]const [4]f32,
4600+
) void;
45544601
//----------------------------------------------------------------------------------------------
45554602
pub fn addPolyline(draw_list: DrawList, points: []const [2]f32, args: struct {
45564603
col: u32,

src/zgui.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,6 +2519,21 @@ extern "C"
25192519
draw_list->AddText({pos[0], pos[1]}, col, text_begin, text_end);
25202520
}
25212521

2522+
ZGUI_API void zguiDrawList_AddTextExtended(
2523+
ImDrawList *draw_list,
2524+
ImFont* font,
2525+
float font_size,
2526+
const float pos[2],
2527+
ImU32 col,
2528+
const char* text_begin,
2529+
const char* text_end,
2530+
float wrap_width,
2531+
const float cpu_fine_clip_rect[][4])
2532+
{
2533+
const ImVec4* clip_rect = (cpu_fine_clip_rect != nullptr) ? (const ImVec4 *)&cpu_fine_clip_rect[0][0] : nullptr;
2534+
draw_list->AddText(font, font_size, {pos[0], pos[1]}, col, text_begin, text_end, wrap_width, clip_rect);
2535+
}
2536+
25222537
ZGUI_API void zguiDrawList_AddPolyline(
25232538
ImDrawList *draw_list,
25242539
const float points[][2],

0 commit comments

Comments
 (0)