MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / setString

Method setString

Source/ButtonSprite.cpp:172–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172void ButtonSprite::setString(std::string_view str)
173{
174 if (!_hasTextProvided)
175 return;
176
177 // Shrink label if too long
178 _label->setScale(1);
179 _label->setString(str);
180
181 if (_width > 0)
182 {
183 float labelWidth = _label->getContentSize().width;
184 if (labelWidth > _width)
185 _label->setScale(_width / labelWidth);
186 }
187
188 if (_label->getScale() >= _scale)
189 {
190 _label->setScale(_scale);
191 }
192
193 // Update content size
194 Vec2 newContentSize(16, 0);
195
196 if (_absoluteWidth)
197 {
198 newContentSize.width += _width;
199 }
200 else
201 {
202 float labelWidth = _label->getContentSize().width;
203
204 if (_minWidth < (labelWidth * _label->getScale()))
205 {
206 newContentSize.width += labelWidth * _label->getScale();
207 }
208 else
209 {
210 newContentSize.width += _minWidth;
211 }
212 }
213
214 if (_height == 0)
215 {
216 newContentSize.height = _label->getContentSize().height + 4;
217 }
218 else
219 {
220 newContentSize.height = _height;
221 }
222
223 _buttonTexture->setContentSize(newContentSize);
224 this->setContentSize(_buttonTexture->getContentSize());
225
226 // Update positions
227 _label->setPosition({ _spriteOffset.x + (this->getContentSize().width / 2), _spriteOffset.y + (this->getContentSize().height / 2) });
228 _buttonTexture->setPosition(this->getContentSize() / 2);
229

Callers 11

initWithTextMethod · 0.95
updateBGImageMethod · 0.95
updateMethod · 0.45
drawPropertiesFunction · 0.45
updateMethod · 0.45
handleWindowsMethod · 0.45
setTextMethod · 0.45
initMethod · 0.45
initMethod · 0.45
onNextMethod · 0.45

Calls 2

setScaleMethod · 0.80
setPositionMethod · 0.80

Tested by

no test coverage detected