19 const auto& s = get_checkbox_style(ctx);
20 const bool highlighted = enabled && is_highlighted(ctx);
23 if (draw_background) {
26 if (s.border_width > 0.0F) {
31 { transform.position.x + padding, transform.position.y + padding },
32 { transform.size.x - (padding * 2.0F), transform.size.y - (padding * 2.0F) }
36 const auto& unchecked_tex = current_texture(ctx);
37 if (unchecked_tex !=
nullptr) {
39 if (checked && enabled) {
40 if (highlighted && texture_checked_hover !=
nullptr) {
41 tex = &texture_checked_hover;
42 }
else if (texture_checked !=
nullptr) {
43 tex = &texture_checked;
45 }
else if (checked && texture_checked !=
nullptr) {
46 tex = &texture_checked;
52 const float box_size = std::min(inner.size.x, inner.size.y);
54 const float box_x = box_right ? inner.position.x + inner.size.x - box_size : inner.position.x;
55 const asw::Quad<float> box { { box_x, inner.position.y }, { box_size, box_size } };
59 box_color = s.box_disabled;
60 }
else if (_pressed) {
61 box_color = s.box_pressed;
62 }
else if (highlighted) {
63 box_color = s.box_hover;
67 if (s.box_border_width > 0.0F) {
72 const float inset = std::max(3.0F, box_size / 4.0F);
73 const asw::Quad<float> mark { { box.position.x + inset, box.position.y + inset },
74 { box_size - (inset * 2.0F), box_size - (inset * 2.0F) } };
78 if (
const auto& f =
pick_font(font, ctx.
theme); !text.empty() && f !=
nullptr) {
81 = inner.position.y + ((inner.size.y -
static_cast<float>(text_size.y)) / 2.0F);
83 = box_right ? inner.position.x : inner.position.x + box_size + ctx.
theme.
gap;
84 asw::draw::text(f, text, { text_x, text_y }, enabled ? s.text : s.text_disabled,
Shared state for the UI system.
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....
const asw::Font & pick_font(const asw::Font &own, const Theme &theme)
The font a widget draws with: its own, or the theme font.