| 145 | } |
| 146 | |
| 147 | bool ButtonAt(const StringView label, const Vec2& center, const Optional<double>& _width, const bool enabled) |
| 148 | { |
| 149 | const Font& font = GetFont(); |
| 150 | const auto dtext = font(label); |
| 151 | |
| 152 | const double labelWidth = Math::Ceil(dtext.region().w); |
| 153 | const double width = _width.value_or_eval([&](){ return (labelWidth + 40); }); |
| 154 | |
| 155 | const RectF rect{ Arg::center = center, width, UnitSize }; |
| 156 | const Vec2 labelPos{ (rect.x + (width - labelWidth) / 2.0), (center.y - font.height() / 2.0 + FontYOffset) }; |
| 157 | |
| 158 | const bool mouseOver = (enabled && rect.mouseOver()); |
| 159 | const bool pushed = (mouseOver && Cursor::OnClientRect() && MouseL.down()); |
| 160 | const RoundRect rrect = rect.rounded(RoundSize); |
| 161 | |
| 162 | if (enabled) |
| 163 | { |
| 164 | rrect.draw(mouseOver ? ButtonMouseOverColor : BackgroundColor); |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | rrect.draw(DisabledBackgroundColor); |
| 169 | } |
| 170 | |
| 171 | if (not pushed) |
| 172 | { |
| 173 | rrect.drawFrame(1, 0, FrameColor); |
| 174 | } |
| 175 | |
| 176 | dtext.draw(labelPos, GetTextColor(enabled)); |
| 177 | |
| 178 | if (mouseOver) |
| 179 | { |
| 180 | Cursor::RequestStyle(CursorStyle::Hand); |
| 181 | } |
| 182 | |
| 183 | return pushed; |
| 184 | } |
| 185 | |
| 186 | RectF SliderRegion(const Vec2& pos, double labelWidth, double sliderWidth) |
| 187 | { |
no test coverage detected