parent
5903370cda
commit
c7df101090
|
@ -89,3 +89,9 @@ pub const platform_impls = if (@hasDecl(root_options, "platform_impls"))
|
|||
root_options.platform_impls
|
||||
else
|
||||
default_platform_impls;
|
||||
|
||||
/// Set this to true to draw debugging information such as various bounding boxes.
|
||||
pub const debug_render: bool = if (@hasDecl(root_options, "debug_render"))
|
||||
root_options.debug_render
|
||||
else
|
||||
false;
|
||||
|
|
|
@ -142,12 +142,69 @@ fn Prototype(comptime Self: type) type {
|
|||
/// Draw the given span of text at the given position.
|
||||
/// The caller asserts that the font of the span is from the same platform as this painter.
|
||||
pub fn span(self: *Self, pos: Position, text_span: Span) !void {
|
||||
if (zenolith.debug_render) {
|
||||
for (text_span.glyphs.items) |glyph| {
|
||||
// Size of the glyph suitable for rendering the debug overlay with.
|
||||
const glyphsize_debug = Size{
|
||||
.width = @max(2, glyph.glyph.size.width),
|
||||
.height = @max(2, glyph.glyph.size.height),
|
||||
};
|
||||
// Position with bearing removed
|
||||
try self.strokeRect(
|
||||
.{
|
||||
.pos = pos.add(glyph.position).sub(glyph.glyph.bearing),
|
||||
.size = glyphsize_debug,
|
||||
},
|
||||
1,
|
||||
Color.fromInt(0xffff00ff),
|
||||
null,
|
||||
);
|
||||
|
||||
// Position without bearing
|
||||
try self.strokeRect(
|
||||
.{
|
||||
.pos = pos.add(glyph.position),
|
||||
.size = glyphsize_debug,
|
||||
},
|
||||
1,
|
||||
Color.fromInt(0xff0000ff),
|
||||
null,
|
||||
);
|
||||
}
|
||||
// Baseline
|
||||
try self.rect(
|
||||
.{
|
||||
.pos = pos.add(.{ .x = 0, .y = @intCast(text_span.baseline_y) }),
|
||||
.size = .{ .width = text_span.baseline_width, .height = 2 },
|
||||
},
|
||||
Color.fromInt(0x00ff00ff),
|
||||
);
|
||||
}
|
||||
return statspatch.implcall(self, .ptr, "span", anyerror!void, .{ pos, text_span });
|
||||
}
|
||||
|
||||
/// Draw the given chunk of text at the given position.
|
||||
/// The caller asserts that the font of the spans of this chunk is from the same platform as this painter.
|
||||
pub fn chunk(self: *Self, pos: Position, text_chunk: Chunk) !void {
|
||||
if (zenolith.debug_render) {
|
||||
for (text_chunk.spans.items) |sspan| {
|
||||
const rendersize = sspan.span.renderSize();
|
||||
|
||||
// Size of spans suitable for debug rendering.
|
||||
const spansize_debug = Size{
|
||||
.width = @max(4, rendersize.width),
|
||||
.height = @max(4, rendersize.height),
|
||||
};
|
||||
|
||||
try self.strokeRect(
|
||||
.{ .pos = pos.add(sspan.position), .size = spansize_debug },
|
||||
2,
|
||||
Color.fromInt(0xff8000ff),
|
||||
null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (statspatch.implcallOptional(
|
||||
self,
|
||||
.ptr,
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
//! This event signals widgets that they should be drawn using the given painter.
|
||||
const zenolith = @import("../main.zig");
|
||||
|
||||
const Color = @import("../Color.zig");
|
||||
const Painter = @import("../painter.zig").Painter;
|
||||
const Size = @import("../layout/Size.zig");
|
||||
const Widget = @import("../widget.zig").Widget;
|
||||
|
||||
painter: *Painter,
|
||||
|
@ -9,5 +13,18 @@ const Draw = @This();
|
|||
pub fn dispatch(self: Draw, widget: *Widget) !void {
|
||||
for (widget.children()) |child| {
|
||||
try child.treevent(self);
|
||||
if (zenolith.debug_render) {
|
||||
const debug_size = Size{
|
||||
.width = @max(4, child.data.size.width),
|
||||
.height = @max(4, child.data.size.height),
|
||||
};
|
||||
|
||||
try self.painter.strokeRect(
|
||||
.{ .pos = child.data.position, .size = debug_size },
|
||||
2,
|
||||
Color.fromInt(0x00ffffff),
|
||||
null,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue