33std::string GuiFormat(
const char * fmt, ...) __attribute__((format(printf, 1, 2)));
35std::string GuiFormat(
const char * fmt, ...);
45 GuiLabel(UiScope& scope,
const char * text =
"");
47 GuiLabel& fontSize(
int px);
51 GuiLabel& nudgeY(
int n) { setNudgeY(n);
return *
this; }
58 GuiLabel& bind(std::function<std::string()> fn);
60 GuiLabel& visibleWhen(std::function<
bool()> fn);
70 GuiChip(UiScope& scope,
const char * text =
"");
72 void setText(
const char * t) { label.setText(t); }
74 GuiChip& bind(std::function<std::string()> fn);
75 GuiChip& visibleWhen(std::function<
bool()> fn);
90 GuiTextButton(UiScope& scope,
const char * text);
92 GuiTextButton& size(
int w,
int h);
94 GuiTextButton& fontSize(
int px);
100 GuiTextButton& style(
const GuiShapeStyle& s);
102 GuiTextButton& rounded(
float radius);
104 GuiTextButton& textNudge(
int n) { text.setNudgeY(n); textLit.setNudgeY(n);
return *
this; }
106 GuiTextButton& litTextColor(PixelColor c) { textLit.textColor(c);
return *
this; }
108 GuiTextButton& disabled(
bool d =
true);
110 void setText(
const char * t);
112 GuiTextButton& bind(std::function<std::string()> fn);
114 GuiTextButton& visibleWhen(std::function<
bool()> fn);
116 GuiTextButton&
enabledWhen(std::function<
bool()> fn);
118 void update(InputController * c)
override;
119 void setLayoutSize(
int w,
int h)
override;
148 GuiCard(UiScope& scope);
154 GuiCard& style(
const GuiShapeStyle& s);
156 GuiCard& corners(
const GuiCorners& c);
158 GuiCard& selectable(
bool s);
160 GuiCard& disabled(
bool d =
true);
162 GuiCard& visibleWhen(std::function<
bool()> fn);
164 void select() { surface.setState(STATE::SELECTED); }
166 void deselect() { surface.resetState(); }
168 bool isSelected() {
const STATE s = surface.getState();
return s == STATE::SELECTED || s == STATE::HELD; }
172 GuiCard& size(
int w,
int h) { setFixedSize(w, h);
return *
this; }
173 GuiCard& pad(
float all) { setPadding(all);
return *
this; }
174 GuiCard& pad(
float horizontal,
float vertical) { setPadding(horizontal, vertical);
return *
this; }
175 GuiCard& add(GuiElement& e,
const GuiItem& item = GuiItem()) {
GuiLayout::add(&e, item);
return *
this; }
176 GuiCard& add(GuiElement * e,
const GuiItem& item = GuiItem()) {
GuiLayout::add(e, item);
return *
this; }
178 void update(InputController * c)
override;
181 GuiCardSurface surface;
196 UiScope(
const UiScope&) =
delete;
197 UiScope& operator=(
const UiScope&) =
delete;
201 template<
class T,
class... Args>
202 T& make(Args&&... args)
204 Held<T> * h =
new Held<T>(std::forward<Args>(args)...);
205 holders.push_back(h);
206 h->value.setRemoveOnDestroy(
true);
210 template<
class T,
class... Args>
211 T& own(Args&&... args)
213 Held<T> * h =
new Held<T>(std::forward<Args>(args)...);
214 holders.push_back(h);
218 GuiRow& row() {
return make<GuiRow>(); }
219 GuiColumn& column() {
return make<GuiColumn>(); }
220 GuiGrid& grid(
int columns) {
return make<GuiGrid>(columns); }
221 GuiOverlay& overlay() {
return make<GuiOverlay>(); }
222 GuiLabel& label(
const char * text =
"") {
return make<GuiLabel>(*
this, text); }
223 GuiChip& chip(
const char * text =
"") {
return make<GuiChip>(*
this, text); }
224 GuiTextButton& button(
const char * text) {
return make<GuiTextButton>(*
this, text); }
225 GuiCard& card() {
return make<GuiCard>(*
this); }
226 GuiGlyph& glyph(
GLYPH kind,
const char * letter =
"") {
return make<GuiGlyph>(kind, letter); }
231 void visibleWhen(GuiElement& e, std::function<
bool()> fn);
238 void setTrigger(GuiTrigger * t) { trig = t ? t : &primary; }
239 GuiTrigger * trigger() {
return trig; }
241 void setSounds(GuiSound * over, GuiSound * click) { soundOver = over; soundClick = click; }
242 GuiSound * getSoundOver() {
return soundOver; }
243 GuiSound * getSoundClick() {
return soundClick; }
247 void attachTo(GuiWindow& window);
252 struct Holder {
virtual ~Holder() {} };
256 template<
class... A> Held(A&&... a) : value(std::forward<A>(a)...) {}
261 std::vector<Holder*> holders;
262 std::vector<UiCallback> bindings;
265 GuiSound * soundOver;
266 GuiSound * soundClick;
virtual void setLayoutSize(int w, int h)
Gives the element a size chosen by a container (default: sets width and height)
GuiLayout & add(GuiElement *e, const GuiItem &item=GuiItem())
Adds a child. Children are laid out in the order they are added.
Stacks children in one box, each aligned inside it (centered by default).
Display, manage, and manipulate text in the GUI.
void enabledWhen(GuiElement &e, std::function< bool()> fn)
Formats like printf and returns a std::string, for bound text: ui.label().bind([&]{ return GuiFormat(...
std::function< void()> UiCallback
A callback with no arguments.
STATE
Interaction state of a GuiElement (default, selected, clicked, held, disabled).
GLYPH
Small control icons for lists and hints (the "A" in a circle, a bumper, a D-pad arrow).
Colors, metrics and the style recipes built from them.
static GuiTheme & current()
The theme the rest of the library reads. The first call fills it in with GuiThemeInit().
8-bit-per-channel RGBA color used by the video interfaces.