MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / calculateTextOffset

Method calculateTextOffset

src/OpenLoco/src/Ui/TextInput.cpp:118–141  ·  view source on GitHub ↗

* 0x004CEB67 * * @param containerWidth @ */

Source from the content-addressed store, hash-verified

116 * @param containerWidth @<edx>
117 */
118 void InputSession::calculateTextOffset(int16_t containerWidth)
119 {
120 std::string cursorStr = buffer.substr(0, cursorPosition);
121
122 const auto font = Gfx::Font::medium_bold;
123 const auto stringWidth = Gfx::TextRenderer::getStringWidth(font, buffer.c_str());
124 const auto cursorX = Gfx::TextRenderer::getStringWidth(font, cursorStr.c_str());
125
126 const auto midX = containerWidth / 2;
127
128 // Prefer to centre cursor
129 xOffset = -1 * (cursorX - midX);
130
131 // Make sure that text will always be at the left edge
132 int16_t minOffset = textboxPadding;
133 int16_t maxOffset = textboxPadding;
134
135 if (stringWidth + textboxPadding * 2 > containerWidth)
136 {
137 // Make sure that the whole textbox is filled up
138 minOffset = -stringWidth + containerWidth - textboxPadding;
139 }
140 xOffset = std::clamp<int16_t>(xOffset, minOffset, maxOffset);
141 }
142
143 void InputSession::clearInput()
144 {

Callers 8

internalOpenFunction · 0.80
keyUpFunction · 0.80
openFunction · 0.80
keyUpFunction · 0.80
openFunction · 0.80
keyUpFunction · 0.80
openTextInputFunction · 0.80
keyUpFunction · 0.80

Calls 1

getStringWidthFunction · 0.85

Tested by

no test coverage detected