* 0x004CEB67 * * @param containerWidth @ */
| 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 | { |
no test coverage detected