ui::SvgImage¶
Header: winui/render/SvgImage.hpp.
An SVG document as image content: the markup, kept as text, plus the natural size read from its root element.
Nothing here interprets the drawing. Renderer::draw_svg() hands the markup to the renderer, which draws a subset of SVG. Copies share one immutable markup string, so passing an SvgImage around by value is cheap.
Example:
const ui::SvgImage logo = ui::SvgImage::read("assets/logo.svg"); // throws if unreadable
const ui::SvgImage dot{R"(<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
<circle cx="8" cy="8" r="6" fill="`#0078D4`"/></svg>)"};
// The logo drawn at 64x64, the dot at twice the 16x16 its root element gives.
window.set_content(ui::HorizontalStack{
.spacing = 8,
.content = {
ui::Image{.source = logo, .width = 64, .height = 64},
ui::Image{.source = dot, .width = 2 * dot.natural_size().width, .height = 2 * dot.natural_size().height},
},
});
SvgImage¶
An empty document; draws nothing.
SvgImage¶
UTF-8 SVG markup. Throws nothing: a document whose root cannot be read has a zero natural size, and a backend that cannot parse it draws nothing.
empty¶
True when there is no markup.
markup¶
The UTF-8 markup as given; valid while this SvgImage (or a copy of it) lives.
natural_size¶
The root element's size in DIPs (see svg_natural_size()); zero when it has none.
read¶
The file at path, read as UTF-8. Throws std::runtime_error if it cannot be read.