| | | @@ -0,0 +1,957 @@ |
| 1 | + | /* |
| 2 | + | * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient> |
| 3 | + | * |
| 4 | + | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + | * of this software and associated documentation files (the "Software"), to deal |
| 6 | + | * in the Software without restriction, including without limitation the rights |
| 7 | + | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + | * copies of the Software, and to permit persons to whom the Software is |
| 9 | + | * furnished to do so, subject to the following conditions: |
| 10 | + | * |
| 11 | + | * The above copyright notice and this permission notice shall be included in |
| 12 | + | * all copies or substantial portions of the Software. |
| 13 | + | * |
| 14 | + | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | + | * THE SOFTWARE. |
| 21 | + | */ |
| 22 | + | |
| 23 | + | #include "uitextedit.h" |
| 24 | + | #include "uimanager.h" |
| 25 | + | #include "uitranslator.h" |
| 26 | + | |
| 27 | + | #include <framework/graphics/bitmapfont.h> |
| 28 | + | #include <framework/graphics/graphics.h> |
| 29 | + | #include <framework/platform/platformwindow.h> |
| 30 | + | #include <framework/core/clock.h> |
| 31 | + | #include <framework/otml/otmlnode.h> |
| 32 | + | #include <framework/core/application.h> |
| 33 | + | #include <framework/graphics/fontmanager.h> |
| 34 | + | |
| 35 | + | UITextEdit::UITextEdit() |
| 36 | + | { |
| 37 | + | m_cursorPos = 0; |
| 38 | + | m_textAlign = Fw::AlignTopLeft; |
| 39 | + | m_textHidden = false; |
| 40 | + | m_shiftNavigation = false; |
| 41 | + | m_multiline = false; |
| 42 | + | #ifdef ANDROID |
| 43 | + | m_cursorVisible = false; |
| 44 | + | #else |
| 45 | + | m_cursorVisible = true; |
| 46 | + | #endif |
| 47 | + | m_cursorInRange = true; |
| 48 | + | m_maxLength = 0; |
| 49 | + | m_editable = true; |
| 50 | + | m_selectable = true; |
| 51 | + | m_autoScroll = true; |
| 52 | + | m_autoSubmit = false; |
| 53 | + | setCursor("text"); |
| 54 | + | m_selectionReference = 0; |
| 55 | + | m_selectionStart = 0; |
| 56 | + | m_selectionEnd = 0; |
| 57 | + | m_updatesEnabled = true; |
| 58 | + | m_selectionColor = Color::white; |
| 59 | + | m_selectionBackgroundColor = Color::black; |
| 60 | + | m_glyphsMustRecache = true; |
| 61 | + | m_placeholder = ""; |
| 62 | + | m_placeholderColor = Color::gray; |
| 63 | + | m_placeholderFont = g_fonts.getDefaultFont(); |
| 64 | + | m_placeholderAlign = Fw::AlignLeftCenter; |
| 65 | + | blinkCursor(); |
| 66 | + | } |
| 67 | + | |
| 68 | + | void UITextEdit::drawSelf(Fw::DrawPane drawPane) |
| 69 | + | { |
| 70 | + | if(drawPane != Fw::ForegroundPane) |
| 71 | + | return; |
| 72 | + | |
| 73 | + | drawBackground(m_rect); |
| 74 | + | drawBorder(m_rect); |
| 75 | + | drawImage(m_rect); |
| 76 | + | drawIcon(m_rect); |
| 77 | + | |
| 78 | + | int textLength = m_glyphsCoords.size(); |
| 79 | + | const TexturePtr& texture = m_font->getTexture(); |
| 80 | + | if(!texture) |
| 81 | + | return; |
| 82 | + | |
| 83 | + | if (textLength == 0) { |
| 84 | + | if (m_placeholderColor != Color::alpha && !m_placeholder.empty()) { |
| 85 | + | m_placeholderFont->drawText(m_placeholder, m_drawArea, m_placeholderAlign, m_placeholderColor); |
| 86 | + | } |
| 87 | + | } |
| 88 | + | |
| 89 | + | bool glyphsMustRecache = m_glyphsMustRecache; |
| 90 | + | if(glyphsMustRecache) |
| 91 | + | m_glyphsMustRecache = false; |
| 92 | + | |
| 93 | + | if(m_color != Color::alpha) { |
| 94 | + | if(glyphsMustRecache) { |
| 95 | + | m_glyphsTextCoordsBuffer.clear(); |
| 96 | + | for (int i = 0; i < textLength; ++i) { |
| 97 | + | if(m_glyphsCoords[i].isValid()) |
| 98 | + | m_glyphsTextCoordsBuffer.addRect(m_glyphsCoords[i], m_glyphsTexCoords[i]); |
| 99 | + | } |
| 100 | + | } |
| 101 | + | if (m_drawTextColors.empty()) { |
| 102 | + | g_drawQueue->addTextureCoords(m_glyphsTextCoordsBuffer, texture, m_color); |
| 103 | + | } else { |
| 104 | + | if (m_drawTextColors.size() == 1) { // optimization for 1 color |
| 105 | + | g_drawQueue->addTextureCoords(m_glyphsTextCoordsBuffer, texture, m_drawTextColors[0].second); |
| 106 | + | } else { |
| 107 | + | g_drawQueue->addColoredTextureCoords(m_glyphsTextCoordsBuffer, texture, m_drawTextColors); |
| 108 | + | } |
| 109 | + | } |
| 110 | + | } |
| 111 | + | |
| 112 | + | if(hasSelection()) { |
| 113 | + | if(glyphsMustRecache) { |
| 114 | + | m_glyphsSelectCoordsBuffer.clear(); |
| 115 | + | for(int i=m_selectionStart;i<m_selectionEnd;++i) |
| 116 | + | m_glyphsSelectCoordsBuffer.addRect(m_glyphsCoords[i], m_glyphsTexCoords[i]); |
| 117 | + | } |
| 118 | + | g_drawQueue->addFillCoords(m_glyphsSelectCoordsBuffer, m_selectionBackgroundColor); |
| 119 | + | g_drawQueue->addTextureCoords(m_glyphsSelectCoordsBuffer, texture, m_selectionColor); |
| 120 | + | } |
| 121 | + | |
| 122 | + | // render cursor |
| 123 | + | if(isExplicitlyEnabled() && m_cursorVisible && m_cursorInRange && isActive() && m_cursorPos >= 0) { |
| 124 | + | VALIDATE(m_cursorPos <= textLength); |
| 125 | + | // draw every 333ms |
| 126 | + | const int delay = 333; |
| 127 | + | int elapsed = g_clock.millis() - m_cursorTicks; |
| 128 | + | if(elapsed <= delay) { |
| 129 | + | Rect cursorRect; |
| 130 | + | // when cursor is at 0 |
| 131 | + | if(m_cursorPos == 0) |
| 132 | + | cursorRect = Rect(m_rect.left()+m_padding.left, m_rect.top()+m_padding.top, 1, m_font->getGlyphHeight()); |
| 133 | + | else |
| 134 | + | cursorRect = Rect(m_glyphsCoords[m_cursorPos-1].right(), m_glyphsCoords[m_cursorPos-1].top(), 1, m_font->getGlyphHeight()); |
| 135 | + | |
| 136 | + | if (hasSelection() && m_cursorPos >= m_selectionStart && m_cursorPos <= m_selectionEnd) |
| 137 | + | g_drawQueue->addFilledRect(cursorRect, m_selectionColor); |
| 138 | + | else |
| 139 | + | g_drawQueue->addFilledRect(cursorRect, m_color); |
| 140 | + | } else if(elapsed >= 2*delay) { |
| 141 | + | m_cursorTicks = g_clock.millis(); |
| 142 | + | } |
| 143 | + | } |
| 144 | + | } |
| 145 | + | |
| 146 | + | void UITextEdit::update(bool focusCursor) |
| 147 | + | { |
| 148 | + | if(!m_updatesEnabled) |
| 149 | + | return; |
| 150 | + | |
| 151 | + | std::string text = getDisplayedText(); |
| 152 | + | m_drawText = text; |
| 153 | + | int textLength = text.length(); |
| 154 | + | |
| 155 | + | // prevent glitches |
| 156 | + | if(m_rect.isEmpty()) |
| 157 | + | return; |
| 158 | + | |
| 159 | + | // recache coords buffers |
| 160 | + | recacheGlyphs(); |
| 161 | + | |
| 162 | + | // map glyphs positions |
| 163 | + | Size textBoxSize; |
| 164 | + | const std::vector<Point>& glyphsPositions = m_font->calculateGlyphsPositions(text, m_textAlign, &textBoxSize); |
| 165 | + | const Rect *glyphsTextureCoords = m_font->getGlyphsTextureCoords(); |
| 166 | + | const Size *glyphsSize = m_font->getGlyphsSize(); |
| 167 | + | int glyph; |
| 168 | + | |
| 169 | + | // update rect size |
| 170 | + | if(!m_rect.isValid() || m_textHorizontalAutoResize || m_textVerticalAutoResize) { |
| 171 | + | textBoxSize += Size(m_padding.left + m_padding.right, m_padding.top + m_padding.bottom) + m_textOffset.toSize(); |
| 172 | + | Size size = getSize(); |
| 173 | + | if(size.width() <= 0 || (m_textHorizontalAutoResize && !m_textWrap)) |
| 174 | + | size.setWidth(textBoxSize.width()); |
| 175 | + | if(size.height() <= 0 || m_textVerticalAutoResize) |
| 176 | + | size.setHeight(textBoxSize.height()); |
| 177 | + | setSize(size); |
| 178 | + | } |
| 179 | + | |
| 180 | + | // resize just on demand |
| 181 | + | if(textLength != (int)m_glyphsCoords.size()) { |
| 182 | + | m_glyphsCoords.resize(textLength); |
| 183 | + | m_glyphsTexCoords.resize(textLength); |
| 184 | + | } |
| 185 | + | |
| 186 | + | Point oldTextAreaOffset = m_textVirtualOffset; |
| 187 | + | |
| 188 | + | if(textBoxSize.width() <= getPaddingRect().width()) |
| 189 | + | m_textVirtualOffset.x = 0; |
| 190 | + | if(textBoxSize.height() <= getPaddingRect().height()) |
| 191 | + | m_textVirtualOffset.y = 0; |
| 192 | + | |
| 193 | + | // readjust start view area based on cursor position |
| 194 | + | m_cursorInRange = false; |
| 195 | + | if(focusCursor && m_autoScroll) { |
| 196 | + | if(m_cursorPos > 0 && textLength > 0) { |
| 197 | + | VALIDATE(m_cursorPos <= textLength); |
| 198 | + | Rect virtualRect(m_textVirtualOffset, m_rect.size() - Size(m_padding.left+m_padding.right, 0)); // previous rendered virtual rect |
| 199 | + | int pos = m_cursorPos - 1; // element before cursor |
| 200 | + | glyph = (uchar)text[pos]; // glyph of the element before cursor |
| 201 | + | Rect glyphRect(glyphsPositions[pos], glyphsSize[glyph]); |
| 202 | + | |
| 203 | + | // if the cursor is not on the previous rendered virtual rect we need to update it |
| 204 | + | if(!virtualRect.contains(glyphRect.topLeft()) || !virtualRect.contains(glyphRect.bottomRight())) { |
| 205 | + | // calculate where is the first glyph visible |
| 206 | + | Point startGlyphPos; |
| 207 | + | startGlyphPos.y = std::max<int>(glyphRect.bottom() - virtualRect.height(), 0); |
| 208 | + | startGlyphPos.x = std::max<int>(glyphRect.right() - virtualRect.width(), 0); |
| 209 | + | |
| 210 | + | // find that glyph |
| 211 | + | for(pos = 0; pos < textLength; ++pos) { |
| 212 | + | glyph = (uchar)text[pos]; |
| 213 | + | glyphRect = Rect(glyphsPositions[pos], glyphsSize[glyph]); |
| 214 | + | glyphRect.setTop(std::max<int>(glyphRect.top() - m_font->getYOffset() - m_font->getGlyphSpacing().height(), 0)); |
| 215 | + | glyphRect.setLeft(std::max<int>(glyphRect.left() - m_font->getGlyphSpacing().width(), 0)); |
| 216 | + | |
| 217 | + | // first glyph entirely visible found |
| 218 | + | if(glyphRect.topLeft().x >= startGlyphPos.x && glyphRect.topLeft().y >= startGlyphPos.y) { |
| 219 | + | m_textVirtualOffset.x = glyphsPositions[pos].x; |
| 220 | + | m_textVirtualOffset.y = glyphsPositions[pos].y - m_font->getYOffset(); |
| 221 | + | break; |
| 222 | + | } |
| 223 | + | } |
| 224 | + | } |
| 225 | + | } else { |
| 226 | + | m_textVirtualOffset = Point(0,0); |
| 227 | + | } |
| 228 | + | m_cursorInRange = true; |
| 229 | + | } else { |
| 230 | + | if(m_cursorPos > 0 && textLength > 0) { |
| 231 | + | Rect virtualRect(m_textVirtualOffset, m_rect.size() - Size(2*m_padding.left+m_padding.right, 0) ); // previous rendered virtual rect |
| 232 | + | int pos = m_cursorPos - 1; // element before cursor |
| 233 | + | glyph = (uchar)text[pos]; // glyph of the element before cursor |
| 234 | + | Rect glyphRect(glyphsPositions[pos], glyphsSize[glyph]); |
| 235 | + | if(virtualRect.contains(glyphRect.topLeft()) && virtualRect.contains(glyphRect.bottomRight())) |
| 236 | + | m_cursorInRange = true; |
| 237 | + | } else { |
| 238 | + | m_cursorInRange = true; |
| 239 | + | } |
| 240 | + | } |
| 241 | + | |
| 242 | + | bool fireAreaUpdate = false; |
| 243 | + | if(oldTextAreaOffset != m_textVirtualOffset) |
| 244 | + | fireAreaUpdate = true; |
| 245 | + | |
| 246 | + | Rect textScreenCoords = m_rect; |
| 247 | + | textScreenCoords.expandLeft(-m_padding.left); |
| 248 | + | textScreenCoords.expandRight(-m_padding.right); |
| 249 | + | textScreenCoords.expandBottom(-m_padding.bottom); |
| 250 | + | textScreenCoords.expandTop(-m_padding.top); |
| 251 | + | m_drawArea = textScreenCoords; |
| 252 | + | |
| 253 | + | if(textScreenCoords.size() != m_textVirtualSize) { |
| 254 | + | m_textVirtualSize = textScreenCoords.size(); |
| 255 | + | fireAreaUpdate = true; |
| 256 | + | } |
| 257 | + | |
| 258 | + | Size totalSize = textBoxSize; |
| 259 | + | if(totalSize.width() < m_textVirtualSize.width()) |
| 260 | + | totalSize.setWidth(m_textVirtualSize.height()); |
| 261 | + | if(totalSize.height() < m_textVirtualSize.height()) |
| 262 | + | totalSize.setHeight(m_textVirtualSize.height()); |
| 263 | + | if(m_textTotalSize != totalSize) { |
| 264 | + | m_textTotalSize = totalSize; |
| 265 | + | fireAreaUpdate = true; |
| 266 | + | } |
| 267 | + | |
| 268 | + | if(m_textAlign & Fw::AlignBottom) { |
| 269 | + | m_drawArea.translate(0, textScreenCoords.height() - textBoxSize.height()); |
| 270 | + | } else if(m_textAlign & Fw::AlignVerticalCenter) { |
| 271 | + | m_drawArea.translate(0, (textScreenCoords.height() - textBoxSize.height()) / 2); |
| 272 | + | } else { // AlignTop |
| 273 | + | } |
| 274 | + | |
| 275 | + | if(m_textAlign & Fw::AlignRight) { |
| 276 | + | m_drawArea.translate(textScreenCoords.width() - textBoxSize.width(), 0); |
| 277 | + | } else if(m_textAlign & Fw::AlignHorizontalCenter) { |
| 278 | + | m_drawArea.translate((textScreenCoords.width() - textBoxSize.width()) / 2, 0); |
| 279 | + | } else { // AlignLeft |
| 280 | + | |
| 281 | + | } |
| 282 | + | |
| 283 | + | for(int i = 0; i < textLength; ++i) { |
| 284 | + | glyph = (uchar)text[i]; |
| 285 | + | m_glyphsCoords[i].clear(); |
| 286 | + | |
| 287 | + | // skip invalid glyphs |
| 288 | + | if(glyph < 32) |
| 289 | + | continue; |
| 290 | + | |
| 291 | + | // calculate initial glyph rect and texture coords |
| 292 | + | Rect glyphScreenCoords(glyphsPositions[i], glyphsSize[glyph]); |
| 293 | + | Rect glyphTextureCoords = glyphsTextureCoords[glyph]; |
| 294 | + | |
| 295 | + | // first translate to align position |
| 296 | + | if(m_textAlign & Fw::AlignBottom) { |
| 297 | + | glyphScreenCoords.translate(0, textScreenCoords.height() - textBoxSize.height()); |
| 298 | + | } else if(m_textAlign & Fw::AlignVerticalCenter) { |
| 299 | + | glyphScreenCoords.translate(0, (textScreenCoords.height() - textBoxSize.height()) / 2); |
| 300 | + | } else { // AlignTop |
| 301 | + | // nothing to do |
| 302 | + | } |
| 303 | + | |
| 304 | + | if(m_textAlign & Fw::AlignRight) { |
| 305 | + | glyphScreenCoords.translate(textScreenCoords.width() - textBoxSize.width(), 0); |
| 306 | + | } else if(m_textAlign & Fw::AlignHorizontalCenter) { |
| 307 | + | glyphScreenCoords.translate((textScreenCoords.width() - textBoxSize.width()) / 2, 0); |
| 308 | + | } else { // AlignLeft |
| 309 | + | // nothing to do |
| 310 | + | } |
| 311 | + | |
| 312 | + | // only render glyphs that are after startRenderPosition |
| 313 | + | if(glyphScreenCoords.bottom() < m_textVirtualOffset.y || glyphScreenCoords.right() < m_textVirtualOffset.x) |
| 314 | + | continue; |
| 315 | + | |
| 316 | + | // bound glyph topLeft to startRenderPosition |
| 317 | + | if(glyphScreenCoords.top() < m_textVirtualOffset.y) { |
| 318 | + | glyphTextureCoords.setTop(glyphTextureCoords.top() + (m_textVirtualOffset.y - glyphScreenCoords.top())); |
| 319 | + | glyphScreenCoords.setTop(m_textVirtualOffset.y); |
| 320 | + | } |
| 321 | + | if(glyphScreenCoords.left() < m_textVirtualOffset.x) { |
| 322 | + | glyphTextureCoords.setLeft(glyphTextureCoords.left() + (m_textVirtualOffset.x - glyphScreenCoords.left())); |
| 323 | + | glyphScreenCoords.setLeft(m_textVirtualOffset.x); |
| 324 | + | } |
| 325 | + | |
| 326 | + | // subtract startInternalPos |
| 327 | + | glyphScreenCoords.translate(-m_textVirtualOffset); |
| 328 | + | |
| 329 | + | // translate rect to screen coords |
| 330 | + | glyphScreenCoords.translate(textScreenCoords.topLeft()); |
| 331 | + | |
| 332 | + | // only render if glyph rect is visible on screenCoords |
| 333 | + | if(!textScreenCoords.intersects(glyphScreenCoords)) |
| 334 | + | continue; |
| 335 | + | |
| 336 | + | // bound glyph bottomRight to screenCoords bottomRight |
| 337 | + | if(glyphScreenCoords.bottom() > textScreenCoords.bottom()) { |
| 338 | + | glyphTextureCoords.setBottom(glyphTextureCoords.bottom() + (textScreenCoords.bottom() - glyphScreenCoords.bottom())); |
| 339 | + | glyphScreenCoords.setBottom(textScreenCoords.bottom()); |
| 340 | + | } |
| 341 | + | if(glyphScreenCoords.right() > textScreenCoords.right()) { |
| 342 | + | glyphTextureCoords.setRight(glyphTextureCoords.right() + (textScreenCoords.right() - glyphScreenCoords.right())); |
| 343 | + | glyphScreenCoords.setRight(textScreenCoords.right()); |
| 344 | + | } |
| 345 | + | |
| 346 | + | // render glyph |
| 347 | + | m_glyphsCoords[i] = glyphScreenCoords; |
| 348 | + | m_glyphsTexCoords[i] = glyphTextureCoords; |
| 349 | + | } |
| 350 | + | |
| 351 | + | if(fireAreaUpdate) |
| 352 | + | onTextAreaUpdate(m_textVirtualOffset, m_textVirtualSize, m_textTotalSize); |
| 353 | + | } |
| 354 | + | |
| 355 | + | void UITextEdit::setCursorPos(int pos) |
| 356 | + | { |
| 357 | + | if(pos < 0) |
| 358 | + | pos = m_text.length(); |
| 359 | + | |
| 360 | + | if(pos != m_cursorPos) { |
| 361 | + | if(pos < 0) |
| 362 | + | m_cursorPos = 0; |
| 363 | + | else if((uint)pos >= m_text.length()) |
| 364 | + | m_cursorPos = m_text.length(); |
| 365 | + | else |
| 366 | + | m_cursorPos = pos; |
| 367 | + | update(true); |
| 368 | + | } |
| 369 | + | } |
| 370 | + | |
| 371 | + | void UITextEdit::setSelection(int start, int end) |
| 372 | + | { |
| 373 | + | if(start == m_selectionStart && end == m_selectionEnd) |
| 374 | + | return; |
| 375 | + | |
| 376 | + | if(start > end) |
| 377 | + | std::swap(start, end); |
| 378 | + | |
| 379 | + | if(end == -1) |
| 380 | + | end = m_text.length(); |
| 381 | + | |
| 382 | + | m_selectionStart = stdext::clamp<int>(start, 0, (int)m_text.length()); |
| 383 | + | m_selectionEnd = stdext::clamp<int>(end, 0, (int)m_text.length()); |
| 384 | + | recacheGlyphs(); |
| 385 | + | } |
| 386 | + | |
| 387 | + | void UITextEdit::setTextHidden(bool hidden) |
| 388 | + | { |
| 389 | + | m_textHidden = true; |
| 390 | + | update(true); |
| 391 | + | } |
| 392 | + | |
| 393 | + | void UITextEdit::setTextVirtualOffset(const Point& offset) |
| 394 | + | { |
| 395 | + | m_textVirtualOffset = offset; |
| 396 | + | update(); |
| 397 | + | } |
| 398 | + | |
| 399 | + | void UITextEdit::appendText(std::string text) |
| 400 | + | { |
| 401 | + | if(hasSelection()) |
| 402 | + | del(); |
| 403 | + | |
| 404 | + | if(m_cursorPos >= 0) { |
| 405 | + | // replace characters that are now allowed |
| 406 | + | if(!m_multiline) |
| 407 | + | stdext::replace_all(text, "\n", " "); |
| 408 | + | stdext::replace_all(text, "\r", ""); |
| 409 | + | stdext::replace_all(text, "\t", " "); |
| 410 | + | |
| 411 | + | if(text.length() > 0) { |
| 412 | + | // only add text if textedit can add it |
| 413 | + | if(m_maxLength > 0 && m_text.length() + text.length() > m_maxLength) |
| 414 | + | return; |
| 415 | + | |
| 416 | + | // only ignore text append if it contains invalid characters |
| 417 | + | if(m_validCharacters.size() > 0) { |
| 418 | + | for(uint i = 0; i < text.size(); ++i) { |
| 419 | + | if(m_validCharacters.find(text[i]) == std::string::npos) |
| 420 | + | return; |
| 421 | + | } |
| 422 | + | } |
| 423 | + | |
| 424 | + | std::string tmp = m_text; |
| 425 | + | tmp.insert(m_cursorPos, text); |
| 426 | + | m_cursorPos += text.length(); |
| 427 | + | setText(tmp); |
| 428 | + | } |
| 429 | + | } |
| 430 | + | } |
| 431 | + | |
| 432 | + | void UITextEdit::appendCharacter(char c) |
| 433 | + | { |
| 434 | + | if((c == '\n' && !m_multiline) || c == '\r') |
| 435 | + | return; |
| 436 | + | |
| 437 | + | if(hasSelection()) |
| 438 | + | del(); |
| 439 | + | |
| 440 | + | if(m_cursorPos >= 0) { |
| 441 | + | if(m_maxLength > 0 && m_text.length() + 1 > m_maxLength) |
| 442 | + | return; |
| 443 | + | |
| 444 | + | if(m_validCharacters.size() > 0 && m_validCharacters.find(c) == std::string::npos) |
| 445 | + | return; |
| 446 | + | |
| 447 | + | std::string tmp; |
| 448 | + | tmp = c; |
| 449 | + | std::string tmp2 = m_text; |
| 450 | + | tmp2.insert(m_cursorPos, tmp); |
| 451 | + | m_cursorPos++; |
| 452 | + | setText(tmp2); |
| 453 | + | } |
| 454 | + | } |
| 455 | + | |
| 456 | + | void UITextEdit::removeCharacter(bool right) |
| 457 | + | { |
| 458 | + | std::string tmp = m_text; |
| 459 | + | if(m_cursorPos >= 0 && tmp.length() > 0) { |
| 460 | + | if((uint)m_cursorPos >= tmp.length()) { |
| 461 | + | tmp.erase(tmp.begin() + (--m_cursorPos)); |
| 462 | + | } else { |
| 463 | + | if(right) |
| 464 | + | tmp.erase(tmp.begin() + m_cursorPos); |
| 465 | + | else if(m_cursorPos > 0) |
| 466 | + | tmp.erase(tmp.begin() + --m_cursorPos); |
| 467 | + | } |
| 468 | + | setText(tmp); |
| 469 | + | } |
| 470 | + | } |
| 471 | + | |
| 472 | + | void UITextEdit::blinkCursor() |
| 473 | + | { |
| 474 | + | m_cursorTicks = g_clock.millis(); |
| 475 | + | } |
| 476 | + | |
| 477 | + | void UITextEdit::del(bool right) |
| 478 | + | { |
| 479 | + | if(hasSelection()) { |
| 480 | + | std::string tmp = m_text; |
| 481 | + | tmp.erase(m_selectionStart, m_selectionEnd - m_selectionStart); |
| 482 | + | |
| 483 | + | setCursorPos(m_selectionStart); |
| 484 | + | clearSelection(); |
| 485 | + | setText(tmp); |
| 486 | + | } else |
| 487 | + | removeCharacter(right); |
| 488 | + | } |
| 489 | + | |
| 490 | + | void UITextEdit::paste(const std::string& text) |
| 491 | + | { |
| 492 | + | if(hasSelection()) |
| 493 | + | del(); |
| 494 | + | appendText(text); |
| 495 | + | } |
| 496 | + | |
| 497 | + | std::string UITextEdit::copy() |
| 498 | + | { |
| 499 | + | std::string text; |
| 500 | + | if(hasSelection()) { |
| 501 | + | text = getSelection(); |
| 502 | + | g_window.setClipboardText(text); |
| 503 | + | } |
| 504 | + | return text; |
| 505 | + | } |
| 506 | + | |
| 507 | + | std::string UITextEdit::cut() |
| 508 | + | { |
| 509 | + | std::string text = copy(); |
| 510 | + | del(); |
| 511 | + | return text; |
| 512 | + | } |
| 513 | + | |
| 514 | + | void UITextEdit::wrapText() |
| 515 | + | { |
| 516 | + | std::vector<std::pair<int, Color>> copiedColors = m_textColors; |
| 517 | + | setText(m_font->wrapText(m_text, getPaddingRect().width() - m_textOffset.x, &copiedColors)); |
| 518 | + | m_textColors = copiedColors; |
| 519 | + | } |
| 520 | + | |
| 521 | + | void UITextEdit::moveCursorHorizontally(bool right) |
| 522 | + | { |
| 523 | + | if(right) { |
| 524 | + | if((uint)m_cursorPos+1 <= m_text.length()) |
| 525 | + | m_cursorPos++; |
| 526 | + | else |
| 527 | + | m_cursorPos = 0; |
| 528 | + | } else { |
| 529 | + | if(m_cursorPos-1 >= 0) |
| 530 | + | m_cursorPos--; |
| 531 | + | else |
| 532 | + | m_cursorPos = m_text.length(); |
| 533 | + | } |
| 534 | + | |
| 535 | + | blinkCursor(); |
| 536 | + | update(true); |
| 537 | + | } |
| 538 | + | |
| 539 | + | void UITextEdit::moveCursorVertically(bool up) |
| 540 | + | { |
| 541 | + | if (up) { |
| 542 | + | int shifted = 0; |
| 543 | + | int i = m_cursorPos - 1; |
| 544 | + | int limit = 0; |
| 545 | + | bool nextLine = false; |
| 546 | + | for (; i > 0; --i) { |
| 547 | + | if (m_text[i] == '\n') { |
| 548 | + | if (nextLine) { |
| 549 | + | i += 1; |
| 550 | + | break; |
| 551 | + | } |
| 552 | + | nextLine = true; |
| 553 | + | limit = i; |
| 554 | + | } else if(!nextLine) { |
| 555 | + | shifted++; |
| 556 | + | } |
| 557 | + | } |
| 558 | + | i += shifted; |
| 559 | + | m_cursorPos = std::min<uint>(limit, i); |
| 560 | + | } else { |
| 561 | + | int shifted = 0; |
| 562 | + | int i = m_cursorPos - 1; |
| 563 | + | for (; i >= 0; --i) { |
| 564 | + | if (m_text[i] == '\n') { |
| 565 | + | break; |
| 566 | + | } else { |
| 567 | + | shifted++; |
| 568 | + | } |
| 569 | + | } |
| 570 | + | i = m_cursorPos; |
| 571 | + | |
| 572 | + | bool nextLine = false; |
| 573 | + | int limit = m_text.size(); |
| 574 | + | int moveTo = m_text.size(); |
| 575 | + | for (; i < (int)m_text.size(); ++i) { |
| 576 | + | if (m_text[i] == '\n') { |
| 577 | + | if (nextLine) { |
| 578 | + | limit = i; |
| 579 | + | break; |
| 580 | + | } |
| 581 | + | nextLine = true; |
| 582 | + | moveTo = i + 1; |
| 583 | + | } |
| 584 | + | } |
| 585 | + | moveTo += shifted; |
| 586 | + | m_cursorPos = std::min<uint>(limit, moveTo); |
| 587 | + | } |
| 588 | + | blinkCursor(); |
| 589 | + | update(true); |
| 590 | + | } |
| 591 | + | |
| 592 | + | int UITextEdit::getTextPos(Point pos) |
| 593 | + | { |
| 594 | + | int textLength = m_text.length(); |
| 595 | + | |
| 596 | + | // find any glyph that is actually on the |
| 597 | + | int candidatePos = -1; |
| 598 | + | Rect firstGlyphRect, lastGlyphRect; |
| 599 | + | for(int i=0;i<textLength;++i) { |
| 600 | + | Rect clickGlyphRect = m_glyphsCoords[i]; |
| 601 | + | if(!clickGlyphRect.isValid()) |
| 602 | + | continue; |
| 603 | + | if(!firstGlyphRect.isValid()) |
| 604 | + | firstGlyphRect = clickGlyphRect; |
| 605 | + | lastGlyphRect = clickGlyphRect; |
| 606 | + | clickGlyphRect.expandTop(m_font->getYOffset() + m_font->getGlyphSpacing().height()); |
| 607 | + | clickGlyphRect.expandLeft(m_font->getGlyphSpacing().width()+1); |
| 608 | + | if(clickGlyphRect.contains(pos)) { |
| 609 | + | candidatePos = i; |
| 610 | + | break; |
| 611 | + | } |
| 612 | + | else if(pos.y >= clickGlyphRect.top() && pos.y <= clickGlyphRect.bottom()) { |
| 613 | + | if(pos.x <= clickGlyphRect.left()) { |
| 614 | + | candidatePos = i; |
| 615 | + | break; |
| 616 | + | } else if(pos.x >= clickGlyphRect.right()) |
| 617 | + | candidatePos = i+1; |
| 618 | + | } |
| 619 | + | } |
| 620 | + | |
| 621 | + | if(textLength > 0) { |
| 622 | + | if(pos.y < firstGlyphRect.top()) |
| 623 | + | return 0; |
| 624 | + | else if(pos.y > lastGlyphRect.bottom()) |
| 625 | + | return textLength; |
| 626 | + | } |
| 627 | + | |
| 628 | + | return candidatePos; |
| 629 | + | } |
| 630 | + | |
| 631 | + | std::string UITextEdit::getDisplayedText() |
| 632 | + | { |
| 633 | + | std::string text; |
| 634 | + | if(m_textHidden) |
| 635 | + | text = std::string(m_text.length(), '*'); |
| 636 | + | else |
| 637 | + | text = m_text; |
| 638 | + | |
| 639 | + | m_drawTextColors = m_textColors; |
| 640 | + | if(m_textWrap && m_rect.isValid()) |
| 641 | + | text = m_font->wrapText(text, getPaddingRect().width() - m_textOffset.x, &m_drawTextColors); |
| 642 | + | |
| 643 | + | return text; |
| 644 | + | } |
| 645 | + | |
| 646 | + | std::string UITextEdit::getSelection() |
| 647 | + | { |
| 648 | + | if(!hasSelection()) |
| 649 | + | return std::string(); |
| 650 | + | return m_text.substr(m_selectionStart, m_selectionEnd - m_selectionStart); |
| 651 | + | } |
| 652 | + | |
| 653 | + | void UITextEdit::updateText() |
| 654 | + | { |
| 655 | + | if(m_cursorPos > (int)m_text.length()) |
| 656 | + | m_cursorPos = m_text.length(); |
| 657 | + | |
| 658 | + | // any text changes reset the selection |
| 659 | + | if(m_selectable) { |
| 660 | + | m_selectionEnd = 0; |
| 661 | + | m_selectionStart = 0; |
| 662 | + | } |
| 663 | + | |
| 664 | + | blinkCursor(); |
| 665 | + | update(true); |
| 666 | + | } |
| 667 | + | |
| 668 | + | void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) |
| 669 | + | { |
| 670 | + | UIWidget::onStyleApply(styleName, styleNode); |
| 671 | + | |
| 672 | + | for(const OTMLNodePtr& node : styleNode->children()) { |
| 673 | + | if(node->tag() == "text") { |
| 674 | + | setText(node->value()); |
| 675 | + | setCursorPos(m_text.length()); |
| 676 | + | } else if(node->tag() == "text-hidden") |
| 677 | + | setTextHidden(node->value<bool>()); |
| 678 | + | else if(node->tag() == "shift-navigation") |
| 679 | + | setShiftNavigation(node->value<bool>()); |
| 680 | + | else if(node->tag() == "multiline") |
| 681 | + | setMultiline(node->value<bool>()); |
| 682 | + | else if(node->tag() == "max-length") |
| 683 | + | setMaxLength(node->value<int>()); |
| 684 | + | else if(node->tag() == "editable") |
| 685 | + | setEditable(node->value<bool>()); |
| 686 | + | else if(node->tag() == "selectable") |
| 687 | + | setSelectable(node->value<bool>()); |
| 688 | + | else if(node->tag() == "selection-color") |
| 689 | + | setSelectionColor(node->value<Color>()); |
| 690 | + | else if(node->tag() == "selection-background-color") |
| 691 | + | setSelectionBackgroundColor(node->value<Color>()); |
| 692 | + | else if(node->tag() == "selection") { |
| 693 | + | Point selectionRange = node->value<Point>(); |
| 694 | + | setSelection(selectionRange.x, selectionRange.y); |
| 695 | + | } |
| 696 | + | else if(node->tag() == "cursor-visible") |
| 697 | + | setCursorVisible(node->value<bool>()); |
| 698 | + | else if (node->tag() == "auto-scroll") |
| 699 | + | setAutoScroll(node->value<bool>()); |
| 700 | + | else if (node->tag() == "text-auto-submit") |
| 701 | + | setAutoSubmit(node->value<bool>()); |
| 702 | + | else if (node->tag() == "placeholder") |
| 703 | + | setPlaceholder(node->value()); |
| 704 | + | else if (node->tag() == "placeholder-color") |
| 705 | + | setPlaceholderColor(node->value<Color>()); |
| 706 | + | else if (node->tag() == "placeholder-align") |
| 707 | + | setPlaceholderAlign(Fw::translateAlignment(node->value())); |
| 708 | + | else if (node->tag() == "placeholder-font") |
| 709 | + | setPlaceholderFont(node->value()); |
| 710 | + | } |
| 711 | + | } |
| 712 | + | |
| 713 | + | void UITextEdit::onGeometryChange(const Rect& oldRect, const Rect& newRect) |
| 714 | + | { |
| 715 | + | update(true); |
| 716 | + | UIWidget::onGeometryChange(oldRect, newRect); |
| 717 | + | } |
| 718 | + | |
| 719 | + | void UITextEdit::onFocusChange(bool focused, Fw::FocusReason reason) |
| 720 | + | { |
| 721 | + | if(focused) { |
| 722 | + | if(reason == Fw::KeyboardFocusReason) |
| 723 | + | setCursorPos(m_text.length()); |
| 724 | + | else |
| 725 | + | blinkCursor(); |
| 726 | + | update(true); |
| 727 | + | } else if(m_selectable) |
| 728 | + | clearSelection(); |
| 729 | + | UIWidget::onFocusChange(focused, reason); |
| 730 | + | } |
| 731 | + | |
| 732 | + | bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks) |
| 733 | + | { |
| 734 | + | if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks)) |
| 735 | + | return true; |
| 736 | + | |
| 737 | + | if(keyboardModifiers == Fw::KeyboardNoModifier) { |
| 738 | + | if(keyCode == Fw::KeyDelete && m_editable) { // erase right character |
| 739 | + | if(hasSelection() || !m_text.empty()) { |
| 740 | + | del(true); |
| 741 | + | return true; |
| 742 | + | } |
| 743 | + | } else if(keyCode == Fw::KeyBackspace && m_editable) { // erase left character |
| 744 | + | if(hasSelection() || !m_text.empty()) { |
| 745 | + | del(false); |
| 746 | + | return true; |
| 747 | + | } |
| 748 | + | } else if(keyCode == Fw::KeyRight && !m_shiftNavigation) { // move cursor right |
| 749 | + | clearSelection(); |
| 750 | + | moveCursorHorizontally(true); |
| 751 | + | return true; |
| 752 | + | } else if(keyCode == Fw::KeyLeft && !m_shiftNavigation) { // move cursor left |
| 753 | + | clearSelection(); |
| 754 | + | moveCursorHorizontally(false); |
| 755 | + | return true; |
| 756 | + | } else if(keyCode == Fw::KeyHome) { // move cursor to first character |
| 757 | + | if(m_cursorPos != 0) { |
| 758 | + | clearSelection(); |
| 759 | + | setCursorPos(0); |
| 760 | + | return true; |
| 761 | + | } |
| 762 | + | } else if(keyCode == Fw::KeyEnd) { // move cursor to last character |
| 763 | + | if(m_cursorPos != (int)m_text.length()) { |
| 764 | + | clearSelection(); |
| 765 | + | setCursorPos(m_text.length()); |
| 766 | + | return true; |
| 767 | + | } |
| 768 | + | } else if(keyCode == Fw::KeyTab && !m_shiftNavigation) { |
| 769 | + | if (m_multiline) { |
| 770 | + | appendText(" "); |
| 771 | + | } else { |
| 772 | + | clearSelection(); |
| 773 | + | if (UIWidgetPtr parent = getParent()) |
| 774 | + | parent->focusNextChild(Fw::KeyboardFocusReason, true); |
| 775 | + | } |
| 776 | + | return true; |
| 777 | + | } else if(keyCode == Fw::KeyEnter && m_multiline && m_editable) { |
| 778 | + | appendCharacter('\n'); |
| 779 | + | return true; |
| 780 | + | } else if(keyCode == Fw::KeyUp && !m_shiftNavigation && m_multiline) { |
| 781 | + | moveCursorVertically(true); |
| 782 | + | return true; |
| 783 | + | } else if(keyCode == Fw::KeyDown && !m_shiftNavigation && m_multiline) { |
| 784 | + | moveCursorVertically(false); |
| 785 | + | return true; |
| 786 | + | } |
| 787 | + | } else if(keyboardModifiers == Fw::KeyboardCtrlModifier) { |
| 788 | + | if(keyCode == Fw::KeyV && m_editable) { |
| 789 | + | paste(g_window.getClipboardText()); |
| 790 | + | return true; |
| 791 | + | } else if(keyCode == Fw::KeyX && m_editable && m_selectable) { |
| 792 | + | if(hasSelection()) { |
| 793 | + | cut(); |
| 794 | + | return true; |
| 795 | + | } |
| 796 | + | } else if(keyCode == Fw::KeyC && m_selectable) { |
| 797 | + | if(hasSelection()) { |
| 798 | + | copy(); |
| 799 | + | return true; |
| 800 | + | } |
| 801 | + | } else if(keyCode == Fw::KeyA && m_selectable) { |
| 802 | + | if(m_text.length() > 0) { |
| 803 | + | selectAll(); |
| 804 | + | return true; |
| 805 | + | } |
| 806 | + | } |
| 807 | + | } else if(keyboardModifiers == Fw::KeyboardShiftModifier) { |
| 808 | + | if(keyCode == Fw::KeyTab && !m_shiftNavigation) { |
| 809 | + | if(UIWidgetPtr parent = getParent()) |
| 810 | + | parent->focusPreviousChild(Fw::KeyboardFocusReason, true); |
| 811 | + | return true; |
| 812 | + | } else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyLeft || ((keyCode == Fw::KeyUp || keyCode == Fw::KeyDown) && m_multiline)) { |
| 813 | + | |
| 814 | + | int oldCursorPos = m_cursorPos; |
| 815 | + | |
| 816 | + | if(keyCode == Fw::KeyRight) // move cursor right |
| 817 | + | moveCursorHorizontally(true); |
| 818 | + | else if(keyCode == Fw::KeyLeft) // move cursor left |
| 819 | + | moveCursorHorizontally(false); |
| 820 | + | else if (keyCode == Fw::KeyUp && !m_shiftNavigation && m_multiline) |
| 821 | + | moveCursorVertically(true); |
| 822 | + | else if (keyCode == Fw::KeyDown && !m_shiftNavigation && m_multiline) |
| 823 | + | moveCursorVertically(false); |
| 824 | + | |
| 825 | + | if(m_shiftNavigation) |
| 826 | + | clearSelection(); |
| 827 | + | else { |
| 828 | + | if(!hasSelection()) |
| 829 | + | m_selectionReference = oldCursorPos; |
| 830 | + | setSelection(m_selectionReference, m_cursorPos); |
| 831 | + | } |
| 832 | + | return true; |
| 833 | + | } else if(keyCode == Fw::KeyHome) { // move cursor to first character |
| 834 | + | if(m_cursorPos != 0) { |
| 835 | + | setSelection(m_cursorPos, 0); |
| 836 | + | setCursorPos(0); |
| 837 | + | return true; |
| 838 | + | } |
| 839 | + | } else if(keyCode == Fw::KeyEnd) { // move cursor to last character |
| 840 | + | if(m_cursorPos != (int)m_text.length()) { |
| 841 | + | setSelection(m_cursorPos, m_text.length()); |
| 842 | + | setCursorPos(m_text.length()); |
| 843 | + | return true; |
| 844 | + | } |
| 845 | + | } |
| 846 | + | } |
| 847 | + | |
| 848 | + | return false; |
| 849 | + | } |
| 850 | + | |
| 851 | + | bool UITextEdit::onKeyText(const std::string& keyText) |
| 852 | + | { |
| 853 | + | if(m_editable) { |
| 854 | + | #ifdef ANDROID |
| 855 | + | setText(keyText); |
| 856 | + | if (m_autoSubmit) { |
| 857 | + | InputEvent event; |
| 858 | + | event.reset(Fw::KeyDownInputEvent); |
| 859 | + | event.keyCode = Fw::KeyEnter; |
| 860 | + | g_ui.inputEvent(event); |
| 861 | + | event.reset(Fw::KeyUpInputEvent); |
| 862 | + | event.keyCode = Fw::KeyEnter; |
| 863 | + | g_ui.inputEvent(event); |
| 864 | + | } |
| 865 | + | #else |
| 866 | + | appendText(keyText); |
| 867 | + | #endif |
| 868 | + | return true; |
| 869 | + | } |
| 870 | + | return false; |
| 871 | + | } |
| 872 | + | |
| 873 | + | bool UITextEdit::onMousePress(const Point& mousePos, Fw::MouseButton button) |
| 874 | + | { |
| 875 | + | if(UIWidget::onMousePress(mousePos, button)) |
| 876 | + | return true; |
| 877 | + | |
| 878 | + | if(button == Fw::MouseLeftButton) { |
| 879 | + | #ifdef ANDROID |
| 880 | + | if (m_editable) { |
| 881 | + | g_window.showTextEditor("Edit text", "", m_text, m_multiline ? 1 : 0); |
| 882 | + | return true; |
| 883 | + | } |
| 884 | + | #else |
| 885 | + | int pos = getTextPos(mousePos); |
| 886 | + | if(pos >= 0) { |
| 887 | + | setCursorPos(pos); |
| 888 | + | |
| 889 | + | if(m_selectable) { |
| 890 | + | m_selectionReference = pos; |
| 891 | + | setSelection(pos, pos); |
| 892 | + | } |
| 893 | + | } |
| 894 | + | #endif |
| 895 | + | return true; |
| 896 | + | } |
| 897 | + | return false; |
| 898 | + | } |
| 899 | + | |
| 900 | + | bool UITextEdit::onMouseRelease(const Point& mousePos, Fw::MouseButton button) |
| 901 | + | { |
| 902 | + | return UIWidget::onMouseRelease(mousePos, button); |
| 903 | + | } |
| 904 | + | |
| 905 | + | bool UITextEdit::onMouseMove(const Point& mousePos, const Point& mouseMoved) |
| 906 | + | { |
| 907 | + | if(UIWidget::onMouseMove(mousePos, mouseMoved)) |
| 908 | + | return true; |
| 909 | + | |
| 910 | + | if(m_selectable && isPressed()) { |
| 911 | + | int pos = getTextPos(mousePos); |
| 912 | + | if(pos >= 0 && m_selectionReference != -1) { |
| 913 | + | setSelection(m_selectionReference, pos); |
| 914 | + | setCursorPos(pos); |
| 915 | + | } |
| 916 | + | return true; |
| 917 | + | } |
| 918 | + | return false; |
| 919 | + | } |
| 920 | + | |
| 921 | + | bool UITextEdit::onDoubleClick(const Point& mousePos) |
| 922 | + | { |
| 923 | + | if(UIWidget::onDoubleClick(mousePos)) |
| 924 | + | return true; |
| 925 | + | |
| 926 | + | int pos = getTextPos(mousePos); |
| 927 | + | if (m_selectable && pos >= 0 && m_text.length() > 0) { |
| 928 | + | m_selectionReference = -1; |
| 929 | + | int firstSpace = 0; |
| 930 | + | int lastSpace = m_text.length(); |
| 931 | + | for (int i = 0; i < pos && i < (int)m_text.length(); ++i) { |
| 932 | + | if (m_text[i] == ' ' || m_text[i] == '\t' || m_text[i] == '\n') { |
| 933 | + | firstSpace = i + 1; |
| 934 | + | } |
| 935 | + | } |
| 936 | + | for (int i = pos; i < (int)m_text.length(); ++i) { |
| 937 | + | if (m_text[i] == ' ' || m_text[i] == '\t' || m_text[i] == '\n') { |
| 938 | + | lastSpace = i; |
| 939 | + | break; |
| 940 | + | } |
| 941 | + | } |
| 942 | + | setSelection(firstSpace, lastSpace); |
| 943 | + | return true; |
| 944 | + | } |
| 945 | + | |
| 946 | + | return false; |
| 947 | + | } |
| 948 | + | |
| 949 | + | void UITextEdit::onTextAreaUpdate(const Point& offset, const Size& visibleSize, const Size& totalSize) |
| 950 | + | { |
| 951 | + | callLuaField("onTextAreaUpdate", offset, visibleSize, totalSize); |
| 952 | + | } |
| 953 | + | |
| 954 | + | void UITextEdit::setPlaceholderFont(const std::string& fontName) |
| 955 | + | { |
| 956 | + | m_placeholderFont = g_fonts.getFont(fontName); |
| 957 | + | } |