| 1139 | } |
| 1140 | |
| 1141 | static void WidgetTextBoxDraw(RenderTarget& rt, WindowBase& w, WidgetIndex widgetIndex) |
| 1142 | { |
| 1143 | // Get the widget |
| 1144 | const auto& widget = w.widgets[widgetIndex]; |
| 1145 | |
| 1146 | // Resolve the absolute ltrb |
| 1147 | ScreenCoordsXY topLeft{ w.windowPos + ScreenCoordsXY{ widget.left, widget.top } }; |
| 1148 | ScreenCoordsXY bottomRight{ w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; |
| 1149 | |
| 1150 | auto& tbIdent = Windows::GetCurrentTextBox(); |
| 1151 | bool active = w.classification == tbIdent.window.classification && w.number == tbIdent.window.number |
| 1152 | && widgetIndex == tbIdent.widgetIndex; |
| 1153 | |
| 1154 | // Rectangle::fillInset(rt, l, t, r, b, colour, 0x20 | (!active ? 0x40 : 0x00)); |
| 1155 | Rectangle::fillInset( |
| 1156 | rt, { topLeft, bottomRight }, w.colours[widget.colour], Rectangle::BorderStyle::inset, |
| 1157 | Rectangle::FillBrightness::light, Rectangle::FillMode::dontLightenWhenInset); |
| 1158 | |
| 1159 | // Figure out where the text should be positioned vertically. |
| 1160 | topLeft.y = w.windowPos.y + widget.textTop(); |
| 1161 | |
| 1162 | auto* textInput = Windows::GetTextboxSession(); |
| 1163 | if (!active || textInput == nullptr) |
| 1164 | { |
| 1165 | if (widget.text != 0) |
| 1166 | { |
| 1167 | u8string wrappedString; |
| 1168 | wrapString(widget.string, bottomRight.x - topLeft.x - 5, FontStyle::medium, &wrappedString, nullptr); |
| 1169 | drawText(rt, { topLeft.x + 2, topLeft.y }, wrappedString, { w.colours[1], { TextPaintFlag::noFormatting } }); |
| 1170 | } |
| 1171 | return; |
| 1172 | } |
| 1173 | |
| 1174 | // String length needs to add 12 either side of box |
| 1175 | // +13 for cursor when max length. |
| 1176 | u8string wrappedString; |
| 1177 | wrapString(*textInput->Buffer, bottomRight.x - topLeft.x - 5 - 6, FontStyle::medium, &wrappedString, nullptr); |
| 1178 | |
| 1179 | drawText(rt, { topLeft.x + 2, topLeft.y }, wrappedString, { w.colours[1], { TextPaintFlag::noFormatting } }); |
| 1180 | |
| 1181 | // Make a trimmed view of the string for measuring the width. |
| 1182 | int32_t curX = topLeft.x |
| 1183 | + getStringWidth( |
| 1184 | u8string_view{ wrappedString.c_str(), std::min(wrappedString.length(), textInput->SelectionStart) }, |
| 1185 | FontStyle::medium, true) |
| 1186 | + 3; |
| 1187 | |
| 1188 | int32_t width = 6; |
| 1189 | if (static_cast<uint32_t>(textInput->SelectionStart) < textInput->Buffer->size()) |
| 1190 | { |
| 1191 | // Make a new 1 character wide string for measuring the width |
| 1192 | // of the character that the cursor is under. (NOTE: this is broken for multi byte utf8 codepoints) |
| 1193 | width = std::max( |
| 1194 | getStringWidth(u8string{ (*textInput->Buffer)[textInput->SelectionStart] }, FontStyle::medium, true) - 2, 4); |
| 1195 | } |
| 1196 | |
| 1197 | if (Windows::TextBoxCaretIsFlashed()) |
| 1198 | { |
no test coverage detected