42 const bool wasPressed = _pressed;
47 if (wasPressed && in) {
70 if (auto_size && texture !=
nullptr) {
72 transform.size = tex_size +
asw::Vec2<float>(padding * 2.0f, padding * 2.0f);
79 if (auto_size && font !=
nullptr && !text.empty()) {
82 size.x + padding * 2.0f,
83 size.y + padding * 2.0f);
92 }
else if (_pressed) {
94 }
else if (_hovered) {
101 { transform.position.x + padding, transform.position.y + padding },
102 { transform.size.x - padding * 2.0f, transform.size.y - padding * 2.0f }
105 if (texture !=
nullptr) {
109 if (!text.empty() && font !=
nullptr) {
112 = inner.get_center() -
asw::Vec2<float>(text_size.x / 2.0f, text_size.y / 2.0f);
120 ring.position.x -= 2;
121 ring.position.y -= 2;
Shared state for the UI system.
Widget * pointer_capture
The widget that has captured pointer input.
FocusManager focus
The focus manager.
Theme theme
The current UI theme.
void set_focus(Context &ctx, Widget *w)
Set focus to a specific widget.
Routines for drawing sprites and primitives to the screen.
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.
void rect(const asw::Quad< float > &position, asw::Color color)
Draw a rectangle.
void rect_fill(const asw::Quad< float > &position, asw::Color color)
Draw a filled rectangle.
asw::Vec2< float > get_texture_size(const asw::Texture &tex)
Get texture size.
asw::Vec2< int > get_text_size(const asw::Font &font, const std::string &text)
Get text size.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
RGBA color struct with 8-bit channels.
asw::Color text
Default text color.
bool show_focus
Show focus rings around focused widgets. Enabled by default when using keyboard navigation.
asw::Color panel_bg
Panel background color.
asw::Color btn_pressed
Button pressed color.
asw::Color btn_focus_ring
Button focus ring color.
asw::Color btn_hover
Button hover color.
asw::Color btn_bg
Button background color.
Event structure for UI interactions.
asw::Vec2< float > pointer_pos
The pointer position.
Type type
The type of the event.
General utility functions.