Appearance
Painting
A component can draw itself with a Painter and still take part in layout and styling.
Paint functions
Give a component paint(Painter&) instead of render. It lays out and styles like any other component, and the painter draws inside its resolved bounds.
cpp
struct Swatch {
Color color;
void paint(Painter& painter) const {
const Rect b = painter.bounds();
painter.rect(b, color, CornerRadius::all(6.f));
painter.line({ b.x, b.y }, { b.x + b.width, b.y + b.height },
1.f, Color::WHITE);
}
private:
friend StyleAccess;
Styles m_styles { width = 48_px, height = 48_px };
};The painter draws rectangles, lines, polygons, shadows, text and images.
Animation
Animation runs on frames. A Frame& parameter gives the current frame's time, and requesting another frame keeps the animation going:
cpp
struct Pulse {
void paint(Painter& painter, Frame& frame) const {
const auto t = 0.5 + 0.5 * std::sin(frame.time().seconds() * 3.0);
painter.rect(Color::BLUE_VIOLET.set_a(static_cast<float>(t)));
frame.request();
}
};When a component stops requesting frames, Barton stops redrawing until something changes.
Viewports
Embedded wgpu viewports are being built now. This section will cover them once they land.