17 return texture_disabled !=
nullptr ? texture_disabled : texture;
19 if (_pressed && texture_pressed !=
nullptr) {
20 return texture_pressed;
22 if (is_highlighted(ctx) && texture_hover !=
nullptr) {
31 if (auto_size && texture !=
nullptr) {
33 transform.size = tex_size +
asw::Vec2<float>(padding * 2.0f, padding * 2.0f);
40 texture_hover = hover;
41 texture_pressed = pressed;
42 texture_disabled = disabled;
43 draw_background =
false;
44 set_texture(normal, auto_size);
51 if (!auto_size || text.empty()) {
55 if (font !=
nullptr) {
67 size.x + padding * 2.0f,
68 size.y + padding * 2.0f);
91 const auto& s = get_style(ctx);
92 const bool highlighted = enabled && is_highlighted(ctx);
94 if (draw_background) {
98 }
else if (_pressed) {
100 }
else if (highlighted) {
106 if (s.border_width > 0.0F) {
111 { transform.position.x + padding, transform.position.y + padding },
112 { transform.size.x - padding * 2.0f, transform.size.y - padding * 2.0f }
115 if (
const auto& tex = current_texture(ctx); tex !=
nullptr) {
119 if (
const auto& f =
pick_font(font, ctx.
theme); !text.empty() && f !=
nullptr) {
122 color = s.text_disabled;
123 }
else if (highlighted) {
124 color = s.text_hover;
129 = inner.position.y + ((inner.size.y -
static_cast<float>(text_size.y)) / 2.0F);
131 float text_x = inner.get_center().x - (text_size.x / 2.0F);
133 text_x = inner.position.x;
135 text_x = inner.position.x + inner.size.x - text_size.x;
Shared state for the UI system.
Theme theme
The current UI theme.
Routines for drawing sprites and primitives to the screen.
void rect(const asw::Quad< float > &position, asw::Color color, float thickness=1.0F)
Draw a rectangle.
void stretch_sprite(const asw::Texture &tex, const asw::Quad< float > &position)
Draw a sprite with the option to stretch it.
void text(const asw::Font &font, const std::string &text, const asw::Vec2< float > &position, asw::Color color, asw::TextJustify justify=asw::TextJustify::Left)
Draw text. The position is rounded to whole pixels after justification so glyphs stay sharp....
void rect_fill(const asw::Quad< float > &position, asw::Color color)
Draw a filled rectangle.
const asw::Font & pick_font(const asw::Font &own, const Theme &theme)
The font a widget draws with: its own, or the theme font.
asw::Vec2< int > get_text_size(const asw::Font &font, std::string_view text)
Get text size.
asw::Vec2< float > get_texture_size(const asw::Texture &tex)
Get texture size.
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
RGBA color struct with 8-bit channels.
General utility functions.