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);
56 GuiLabel& bind(std::function<std::string()> fn);
58 GuiLabel& visibleWhen(std::function<
bool()> fn);
68 GuiChip(UiScope& scope,
const char * text =
"");
70 void setText(
const char * t) { label.setText(t); }
72 GuiChip& bind(std::function<std::string()> fn);
73 GuiChip& visibleWhen(std::function<
bool()> fn);
88 GuiTextButton(UiScope& scope,
const char * text);
90 GuiTextButton& size(
int w,
int h);
92 GuiTextButton& fontSize(
int px);
98 GuiTextButton& style(
const GuiShapeStyle& s);
100 GuiTextButton& rounded(
float radius);
102 GuiTextButton& disabled(
bool d =
true);
104 void setText(
const char * t);
106 GuiTextButton& bind(std::function<std::string()> fn);
108 GuiTextButton& visibleWhen(std::function<
bool()> fn);
110 GuiTextButton&
enabledWhen(std::function<
bool()> fn);
112 void update(InputController * c)
override;
113 void setLayoutSize(
int w,
int h)
override;
142 GuiCard(UiScope& scope);
148 GuiCard& style(
const GuiShapeStyle& s);
150 GuiCard& corners(
const GuiCorners& c);
152 GuiCard& selectable(
bool s);
154 GuiCard& disabled(
bool d =
true);
156 GuiCard& visibleWhen(std::function<
bool()> fn);
160 GuiCard& size(
int w,
int h) { setFixedSize(w, h);
return *
this; }
161 GuiCard& pad(
float all) { setPadding(all);
return *
this; }
162 GuiCard& pad(
float horizontal,
float vertical) { setPadding(horizontal, vertical);
return *
this; }
163 GuiCard& add(GuiElement& e,
const GuiItem& item = GuiItem()) {
GuiLayout::add(&e, item);
return *
this; }
164 GuiCard& add(GuiElement * e,
const GuiItem& item = GuiItem()) {
GuiLayout::add(e, item);
return *
this; }
166 void update(InputController * c)
override;
169 GuiCardSurface surface;
184 UiScope(
const UiScope&) =
delete;
185 UiScope& operator=(
const UiScope&) =
delete;
189 template<
class T,
class... Args>
190 T& make(Args&&... args)
192 Held<T> * h =
new Held<T>(std::forward<Args>(args)...);
193 holders.push_back(h);
194 h->value.setRemoveOnDestroy(
true);
198 template<
class T,
class... Args>
199 T& own(Args&&... args)
201 Held<T> * h =
new Held<T>(std::forward<Args>(args)...);
202 holders.push_back(h);
206 GuiRow& row() {
return make<GuiRow>(); }
207 GuiColumn& column() {
return make<GuiColumn>(); }
208 GuiGrid& grid(
int columns) {
return make<GuiGrid>(columns); }
209 GuiOverlay& overlay() {
return make<GuiOverlay>(); }
210 GuiLabel& label(
const char * text =
"") {
return make<GuiLabel>(*
this, text); }
211 GuiChip& chip(
const char * text =
"") {
return make<GuiChip>(*
this, text); }
212 GuiTextButton& button(
const char * text) {
return make<GuiTextButton>(*
this, text); }
213 GuiCard& card() {
return make<GuiCard>(*
this); }
214 GuiGlyph& glyph(
GLYPH kind,
const char * letter =
"") {
return make<GuiGlyph>(kind, letter); }
215 GuiControllerView& controllerView(
const GuiControllerLayout& layout,
float scale = 1.0f) {
return make<GuiControllerView>(layout, scale); }
220 void visibleWhen(GuiElement& e, std::function<
bool()> fn);
227 void setTrigger(GuiTrigger * t) { trig = t ? t : &primary; }
228 GuiTrigger * trigger() {
return trig; }
230 void setSounds(GuiSound * over, GuiSound * click) { soundOver = over; soundClick = click; }
231 GuiSound * getSoundOver() {
return soundOver; }
232 GuiSound * getSoundClick() {
return soundClick; }
236 void attachTo(GuiWindow& window);
241 struct Holder {
virtual ~Holder() {} };
245 template<
class... A> Held(A&&... a) : value(std::forward<A>(a)...) {}
250 std::vector<Holder*> holders;
251 std::vector<UiCallback> bindings;
254 GuiSound * soundOver;
255 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.
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. Starts as the default dark theme.
8-bit-per-channel RGBA color used by the video interfaces.