Appearance
Introduction
Barton is a declarative UI framework for C++23. An app describes its interface as a function of its state, and whenever the state changes, Barton re-renders the affected views.
Early development
Barton's API is evolving, and these pages grow with it.
Foundations
Component: A type with a render function that returns a view. Its props are the values it's created with.
State: A type nested in a component, constructed by Barton when the component first appears and kept for as long as it's on screen. A constructor taking the component seeds it from props.
Environment: Values a component can request by type, without its parent passing them in.
View: The tree render returns, built from other views nested to any depth.
Render functions and event handlers request what they need by specifying it in their parameter list, and Barton passes each one in by type. See Parameters.
Example
cpp
struct Counter {
struct State {
int clicks = 0;
};
View render(const State& state) const {
return Container {
padding = 12_px,
on_click = [](State& state) { state.clicks += 1; },
Text { std::format("Clicked {} times", state.clicks) },
};
}
};Clicking runs the handler, which updates the state. Barton then calls render again and updates what changed.
Direction
Barton started as part of a level editor and is designed with desktop applications in mind. Its windows are lightweight and quick to open, and custom GPU rendering can sit alongside regular interface elements.
Multiple windows are already supported, and embedded wgpu viewports are under active development.
Next steps
- Getting started builds a first app.
- Concepts covers props, state and environment in more depth.