MCPcopy Create free account
hub / github.com/Siv3D/OpenSiv3D / ButtonAt

Function ButtonAt

Siv3D/src/Siv3D/SimpleGUI/SivSimpleGUI.cpp:147–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers 1

ButtonFunction · 0.85

Calls 11

CeilFunction · 0.85
OnClientRectFunction · 0.85
GetTextColorFunction · 0.85
RequestStyleFunction · 0.85
regionMethod · 0.45
heightMethod · 0.45
mouseOverMethod · 0.45
downMethod · 0.45
roundedMethod · 0.45
drawMethod · 0.45
drawFrameMethod · 0.45

Tested by

no test coverage detected