LineEdit.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. // Copyright (c) 2008-2022 the Urho3D project
  2. // License: MIT
  3. #include "../Precompiled.h"
  4. #include "../Core/Context.h"
  5. #include "../Input/Input.h"
  6. #include "../UI/LineEdit.h"
  7. #include "../UI/Text.h"
  8. #include "../UI/UI.h"
  9. #include "../UI/UIEvents.h"
  10. #include "../DebugNew.h"
  11. #include <SDL/SDL.h>
  12. namespace Urho3D
  13. {
  14. StringHash VAR_DRAGDROPCONTENT("DragDropContent");
  15. extern const char* UI_CATEGORY;
  16. LineEdit::LineEdit(Context* context) :
  17. BorderImage(context),
  18. lastFont_(nullptr),
  19. lastFontSize_(0),
  20. cursorPosition_(0),
  21. dragBeginCursor_(M_MAX_UNSIGNED),
  22. cursorBlinkRate_(1.0f),
  23. cursorBlinkTimer_(0.0f),
  24. maxLength_(0),
  25. echoCharacter_(0),
  26. cursorMovable_(true),
  27. textSelectable_(true),
  28. textCopyable_(true)
  29. {
  30. clipChildren_ = true;
  31. SetEnabled(true);
  32. focusMode_ = FM_FOCUSABLE_DEFOCUSABLE;
  33. text_ = CreateChild<Text>("LE_Text");
  34. text_->SetInternal(true);
  35. cursor_ = CreateChild<BorderImage>("LE_Cursor");
  36. cursor_->SetInternal(true);
  37. cursor_->SetPriority(1); // Show over text
  38. SubscribeToEvent(this, E_FOCUSED, URHO3D_HANDLER(LineEdit, HandleFocused));
  39. SubscribeToEvent(this, E_DEFOCUSED, URHO3D_HANDLER(LineEdit, HandleDefocused));
  40. SubscribeToEvent(this, E_LAYOUTUPDATED, URHO3D_HANDLER(LineEdit, HandleLayoutUpdated));
  41. }
  42. LineEdit::~LineEdit() = default;
  43. void LineEdit::RegisterObject(Context* context)
  44. {
  45. context->RegisterFactory<LineEdit>(UI_CATEGORY);
  46. URHO3D_COPY_BASE_ATTRIBUTES(BorderImage);
  47. URHO3D_UPDATE_ATTRIBUTE_DEFAULT_VALUE("Clip Children", true);
  48. URHO3D_UPDATE_ATTRIBUTE_DEFAULT_VALUE("Is Enabled", true);
  49. URHO3D_UPDATE_ATTRIBUTE_DEFAULT_VALUE("Focus Mode", FM_FOCUSABLE_DEFOCUSABLE);
  50. URHO3D_ACCESSOR_ATTRIBUTE("Max Length", GetMaxLength, SetMaxLength, unsigned, 0, AM_FILE);
  51. URHO3D_ACCESSOR_ATTRIBUTE("Is Cursor Movable", IsCursorMovable, SetCursorMovable, bool, true, AM_FILE);
  52. URHO3D_ACCESSOR_ATTRIBUTE("Is Text Selectable", IsTextSelectable, SetTextSelectable, bool, true, AM_FILE);
  53. URHO3D_ACCESSOR_ATTRIBUTE("Is Text Copyable", IsTextCopyable, SetTextCopyable, bool, true, AM_FILE);
  54. URHO3D_ACCESSOR_ATTRIBUTE("Cursor Blink Rate", GetCursorBlinkRate, SetCursorBlinkRate, float, 1.0f, AM_FILE);
  55. URHO3D_ATTRIBUTE("Echo Character", unsigned, echoCharacter_, 0, AM_FILE);
  56. }
  57. void LineEdit::ApplyAttributes()
  58. {
  59. BorderImage::ApplyAttributes();
  60. // Set the text's position to match clipping and indent width, so that text left edge is not left partially hidden
  61. text_->SetPosition(GetIndentWidth() + clipBorder_.left_, clipBorder_.top_);
  62. // Sync the text line
  63. line_ = text_->GetText();
  64. }
  65. void LineEdit::Update(float timeStep)
  66. {
  67. if (cursorBlinkRate_ > 0.0f)
  68. cursorBlinkTimer_ = fmodf(cursorBlinkTimer_ + cursorBlinkRate_ * timeStep, 1.0f);
  69. // Update cursor position if font has changed
  70. if (text_->GetFont() != lastFont_ || text_->GetFontSize() != lastFontSize_)
  71. {
  72. lastFont_ = text_->GetFont();
  73. lastFontSize_ = text_->GetFontSize();
  74. UpdateCursor();
  75. }
  76. bool cursorVisible = HasFocus() ? cursorBlinkTimer_ < 0.5f : false;
  77. cursor_->SetVisible(cursorVisible);
  78. }
  79. void LineEdit::OnClickBegin(const IntVector2& position, const IntVector2& screenPosition, MouseButton button, MouseButtonFlags buttons, QualifierFlags qualifiers,
  80. Cursor* cursor)
  81. {
  82. if (button == MOUSEB_LEFT && cursorMovable_)
  83. {
  84. unsigned pos = GetCharIndex(position);
  85. if (pos != M_MAX_UNSIGNED)
  86. {
  87. SetCursorPosition(pos);
  88. text_->ClearSelection();
  89. }
  90. }
  91. }
  92. void LineEdit::OnDoubleClick(const IntVector2& position, const IntVector2& screenPosition, MouseButton button, MouseButtonFlags buttons, QualifierFlags qualifiers,
  93. Cursor* cursor)
  94. {
  95. if (button == MOUSEB_LEFT)
  96. text_->SetSelection(0);
  97. }
  98. void LineEdit::OnDragBegin(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags buttons, QualifierFlags qualifiers,
  99. Cursor* cursor)
  100. {
  101. UIElement::OnDragBegin(position, screenPosition, buttons, qualifiers, cursor);
  102. dragBeginCursor_ = GetCharIndex(position);
  103. }
  104. void LineEdit::OnDragMove(const IntVector2& position, const IntVector2& screenPosition, const IntVector2& deltaPos, MouseButtonFlags buttons,
  105. QualifierFlags qualifiers, Cursor* cursor)
  106. {
  107. if (cursorMovable_ && textSelectable_)
  108. {
  109. unsigned start = dragBeginCursor_;
  110. unsigned current = GetCharIndex(position);
  111. if (start != M_MAX_UNSIGNED && current != M_MAX_UNSIGNED)
  112. {
  113. if (start < current)
  114. text_->SetSelection(start, current - start);
  115. else
  116. text_->SetSelection(current, start - current);
  117. SetCursorPosition(current);
  118. }
  119. }
  120. }
  121. bool LineEdit::OnDragDropTest(UIElement* source)
  122. {
  123. if (source && editable_)
  124. {
  125. if (source->GetVars().Contains(VAR_DRAGDROPCONTENT))
  126. return true;
  127. StringHash sourceType = source->GetType();
  128. return sourceType == LineEdit::GetTypeStatic() || sourceType == Text::GetTypeStatic();
  129. }
  130. return false;
  131. }
  132. bool LineEdit::OnDragDropFinish(UIElement* source)
  133. {
  134. if (source && editable_)
  135. {
  136. // If the UI element in question has a drag-and-drop content string defined, use it instead of element text
  137. if (source->GetVars().Contains(VAR_DRAGDROPCONTENT))
  138. {
  139. SetText(source->GetVar(VAR_DRAGDROPCONTENT).GetString());
  140. return true;
  141. }
  142. StringHash sourceType = source->GetType();
  143. if (sourceType == LineEdit::GetTypeStatic())
  144. {
  145. auto* sourceLineEdit = static_cast<LineEdit*>(source);
  146. SetText(sourceLineEdit->GetText());
  147. return true;
  148. }
  149. else if (sourceType == Text::GetTypeStatic())
  150. {
  151. auto* sourceText = static_cast<Text*>(source);
  152. SetText(sourceText->GetText());
  153. return true;
  154. }
  155. }
  156. return false;
  157. }
  158. void LineEdit::OnKey(Key key, MouseButtonFlags buttons, QualifierFlags qualifiers)
  159. {
  160. bool changed = false;
  161. bool cursorMoved = false;
  162. switch (key)
  163. {
  164. case KEY_X:
  165. case KEY_C:
  166. if (textCopyable_ && qualifiers & QUAL_CTRL)
  167. {
  168. unsigned start = text_->GetSelectionStart();
  169. unsigned length = text_->GetSelectionLength();
  170. if (text_->GetSelectionLength())
  171. GetSubsystem<UI>()->SetClipboardText(line_.SubstringUTF8(start, length));
  172. if (key == KEY_X && editable_)
  173. {
  174. if (start + length < line_.LengthUTF8())
  175. line_ = line_.SubstringUTF8(0, start) + line_.SubstringUTF8(start + length);
  176. else
  177. line_ = line_.SubstringUTF8(0, start);
  178. text_->ClearSelection();
  179. cursorPosition_ = start;
  180. changed = true;
  181. }
  182. }
  183. break;
  184. case KEY_V:
  185. if (editable_ && textCopyable_ && qualifiers & QUAL_CTRL)
  186. {
  187. const String& clipBoard = GetSubsystem<UI>()->GetClipboardText();
  188. if (!clipBoard.Empty())
  189. {
  190. // Remove selected text first
  191. if (text_->GetSelectionLength() > 0)
  192. {
  193. unsigned start = text_->GetSelectionStart();
  194. unsigned length = text_->GetSelectionLength();
  195. if (start + length < line_.LengthUTF8())
  196. line_ = line_.SubstringUTF8(0, start) + line_.SubstringUTF8(start + length);
  197. else
  198. line_ = line_.SubstringUTF8(0, start);
  199. text_->ClearSelection();
  200. cursorPosition_ = start;
  201. }
  202. if (cursorPosition_ < line_.LengthUTF8())
  203. line_ = line_.SubstringUTF8(0, cursorPosition_) + clipBoard + line_.SubstringUTF8(cursorPosition_);
  204. else
  205. line_ += clipBoard;
  206. cursorPosition_ += clipBoard.LengthUTF8();
  207. changed = true;
  208. }
  209. }
  210. break;
  211. case KEY_HOME:
  212. qualifiers |= QUAL_CTRL;
  213. // Fallthru
  214. case KEY_LEFT:
  215. if (cursorMovable_ && cursorPosition_ > 0)
  216. {
  217. if (textSelectable_ && qualifiers & QUAL_SHIFT && !text_->GetSelectionLength())
  218. dragBeginCursor_ = cursorPosition_;
  219. if (qualifiers & QUAL_CTRL)
  220. cursorPosition_ = 0;
  221. else if (text_->GetSelectionLength() && !(qualifiers & QUAL_SHIFT))
  222. cursorPosition_ = text_->GetSelectionStart();
  223. else
  224. --cursorPosition_;
  225. cursorMoved = true;
  226. if (textSelectable_ && qualifiers & QUAL_SHIFT)
  227. {
  228. unsigned start = dragBeginCursor_;
  229. unsigned current = cursorPosition_;
  230. if (start < current)
  231. text_->SetSelection(start, current - start);
  232. else
  233. text_->SetSelection(current, start - current);
  234. }
  235. }
  236. if (!(qualifiers & QUAL_SHIFT))
  237. text_->ClearSelection();
  238. break;
  239. case KEY_END:
  240. qualifiers |= QUAL_CTRL;
  241. // Fallthru
  242. case KEY_RIGHT:
  243. if (cursorMovable_ && cursorPosition_ < line_.LengthUTF8())
  244. {
  245. if (textSelectable_ && qualifiers & QUAL_SHIFT && !text_->GetSelectionLength())
  246. dragBeginCursor_ = cursorPosition_;
  247. if (qualifiers & QUAL_CTRL)
  248. cursorPosition_ = line_.LengthUTF8();
  249. else if (text_->GetSelectionLength() && !(qualifiers & QUAL_SHIFT))
  250. cursorPosition_ = text_->GetSelectionStart() + text_->GetSelectionLength();
  251. else
  252. ++cursorPosition_;
  253. cursorMoved = true;
  254. if (textSelectable_ && qualifiers & QUAL_SHIFT)
  255. {
  256. unsigned start = dragBeginCursor_;
  257. unsigned current = cursorPosition_;
  258. if (start < current)
  259. text_->SetSelection(start, current - start);
  260. else
  261. text_->SetSelection(current, start - current);
  262. }
  263. }
  264. if (!(qualifiers & QUAL_SHIFT))
  265. text_->ClearSelection();
  266. break;
  267. case KEY_DELETE:
  268. if (editable_)
  269. {
  270. if (!text_->GetSelectionLength())
  271. {
  272. if (cursorPosition_ < line_.LengthUTF8())
  273. {
  274. line_ = line_.SubstringUTF8(0, cursorPosition_) + line_.SubstringUTF8(cursorPosition_ + 1);
  275. changed = true;
  276. }
  277. }
  278. else
  279. {
  280. // If a selection exists, erase it
  281. unsigned start = text_->GetSelectionStart();
  282. unsigned length = text_->GetSelectionLength();
  283. if (start + length < line_.LengthUTF8())
  284. line_ = line_.SubstringUTF8(0, start) + line_.SubstringUTF8(start + length);
  285. else
  286. line_ = line_.SubstringUTF8(0, start);
  287. text_->ClearSelection();
  288. cursorPosition_ = start;
  289. changed = true;
  290. }
  291. }
  292. break;
  293. case KEY_UP:
  294. case KEY_DOWN:
  295. case KEY_PAGEUP:
  296. case KEY_PAGEDOWN:
  297. {
  298. using namespace UnhandledKey;
  299. VariantMap& eventData = GetEventDataMap();
  300. eventData[P_ELEMENT] = this;
  301. eventData[P_KEY] = key;
  302. eventData[P_BUTTONS] = (unsigned)buttons;
  303. eventData[P_QUALIFIERS] = (unsigned)qualifiers;
  304. SendEvent(E_UNHANDLEDKEY, eventData);
  305. }
  306. return;
  307. case KEY_BACKSPACE:
  308. if (editable_)
  309. {
  310. if (!text_->GetSelectionLength())
  311. {
  312. if (line_.LengthUTF8() && cursorPosition_)
  313. {
  314. if (cursorPosition_ < line_.LengthUTF8())
  315. line_ = line_.SubstringUTF8(0, cursorPosition_ - 1) + line_.SubstringUTF8(cursorPosition_);
  316. else
  317. line_ = line_.SubstringUTF8(0, cursorPosition_ - 1);
  318. --cursorPosition_;
  319. changed = true;
  320. }
  321. }
  322. else
  323. {
  324. // If a selection exists, erase it
  325. unsigned start = text_->GetSelectionStart();
  326. unsigned length = text_->GetSelectionLength();
  327. if (start + length < line_.LengthUTF8())
  328. line_ = line_.SubstringUTF8(0, start) + line_.SubstringUTF8(start + length);
  329. else
  330. line_ = line_.SubstringUTF8(0, start);
  331. text_->ClearSelection();
  332. cursorPosition_ = start;
  333. changed = true;
  334. }
  335. }
  336. break;
  337. case KEY_RETURN:
  338. case KEY_RETURN2:
  339. case KEY_KP_ENTER:
  340. {
  341. // If using the on-screen keyboard, defocus this element to hide it now
  342. if (GetSubsystem<UI>()->GetUseScreenKeyboard() && HasFocus())
  343. SetFocus(false);
  344. using namespace TextFinished;
  345. VariantMap& eventData = GetEventDataMap();
  346. eventData[P_ELEMENT] = this;
  347. eventData[P_TEXT] = line_;
  348. SendEvent(E_TEXTFINISHED, eventData);
  349. return;
  350. }
  351. default: break;
  352. }
  353. if (changed)
  354. {
  355. UpdateText();
  356. UpdateCursor();
  357. }
  358. else if (cursorMoved)
  359. UpdateCursor();
  360. }
  361. void LineEdit::OnTextInput(const String& text)
  362. {
  363. if (!editable_)
  364. return;
  365. bool changed = false;
  366. // Send text entry as an event to allow changing it
  367. using namespace TextEntry;
  368. VariantMap& eventData = GetEventDataMap();
  369. eventData[P_ELEMENT] = this;
  370. eventData[P_TEXT] = text;
  371. SendEvent(E_TEXTENTRY, eventData);
  372. const String newText = eventData[P_TEXT].GetString().SubstringUTF8(0);
  373. if (!newText.Empty() && (!maxLength_ || line_.LengthUTF8() + newText.LengthUTF8() <= maxLength_))
  374. {
  375. if (!text_->GetSelectionLength())
  376. {
  377. if (cursorPosition_ == line_.LengthUTF8())
  378. line_ += newText;
  379. else
  380. line_ = line_.SubstringUTF8(0, cursorPosition_) + newText + line_.SubstringUTF8(cursorPosition_);
  381. cursorPosition_ += newText.LengthUTF8();
  382. }
  383. else
  384. {
  385. // If a selection exists, erase it first
  386. unsigned start = text_->GetSelectionStart();
  387. unsigned length = text_->GetSelectionLength();
  388. if (start + length < line_.LengthUTF8())
  389. line_ = line_.SubstringUTF8(0, start) + newText + line_.SubstringUTF8(start + length);
  390. else
  391. line_ = line_.SubstringUTF8(0, start) + newText;
  392. cursorPosition_ = start + newText.LengthUTF8();
  393. }
  394. changed = true;
  395. }
  396. if (changed)
  397. {
  398. text_->ClearSelection();
  399. UpdateText();
  400. UpdateCursor();
  401. }
  402. }
  403. void LineEdit::SetText(const String& text)
  404. {
  405. if (text != line_)
  406. {
  407. line_ = text;
  408. cursorPosition_ = line_.LengthUTF8();
  409. UpdateText();
  410. UpdateCursor();
  411. }
  412. }
  413. void LineEdit::SetCursorPosition(unsigned position)
  414. {
  415. if (position > line_.LengthUTF8() || !cursorMovable_)
  416. position = line_.LengthUTF8();
  417. if (position != cursorPosition_)
  418. {
  419. cursorPosition_ = position;
  420. UpdateCursor();
  421. }
  422. }
  423. void LineEdit::SetCursorBlinkRate(float rate)
  424. {
  425. cursorBlinkRate_ = Max(rate, 0.0f);
  426. if (cursorBlinkRate_ == 0.0f)
  427. cursorBlinkTimer_ = 0.0f; // Cursor does not blink, i.e. always visible
  428. }
  429. void LineEdit::SetMaxLength(unsigned length)
  430. {
  431. maxLength_ = length;
  432. }
  433. void LineEdit::SetEchoCharacter(c32 c)
  434. {
  435. echoCharacter_ = c;
  436. UpdateText();
  437. }
  438. void LineEdit::SetCursorMovable(bool enable)
  439. {
  440. cursorMovable_ = enable;
  441. }
  442. void LineEdit::SetTextSelectable(bool enable)
  443. {
  444. textSelectable_ = enable;
  445. }
  446. void LineEdit::SetTextCopyable(bool enable)
  447. {
  448. textCopyable_ = enable;
  449. }
  450. bool LineEdit::FilterImplicitAttributes(XMLElement& dest) const
  451. {
  452. if (!BorderImage::FilterImplicitAttributes(dest))
  453. return false;
  454. XMLElement childElem = dest.GetChild("element");
  455. if (!childElem)
  456. return false;
  457. if (!RemoveChildXML(childElem, "Name", "LE_Text"))
  458. return false;
  459. if (!RemoveChildXML(childElem, "Position"))
  460. return false;
  461. childElem = childElem.GetNext("element");
  462. if (!childElem)
  463. return false;
  464. if (!RemoveChildXML(childElem, "Name", "LE_Cursor"))
  465. return false;
  466. if (!RemoveChildXML(childElem, "Priority", "1"))
  467. return false;
  468. if (!RemoveChildXML(childElem, "Position"))
  469. return false;
  470. if (!RemoveChildXML(childElem, "Is Visible"))
  471. return false;
  472. return true;
  473. }
  474. void LineEdit::UpdateText()
  475. {
  476. i32 utf8Length = line_.LengthUTF8();
  477. // If maxLength_ nonzero, truncate line to enforce length
  478. if (maxLength_ && utf8Length > maxLength_)
  479. {
  480. line_ = line_.SubstringUTF8(0, maxLength_);
  481. utf8Length = maxLength_;
  482. }
  483. if (!echoCharacter_)
  484. {
  485. text_->SetText(line_);
  486. }
  487. else
  488. {
  489. String echoText;
  490. for (i32 i = 0; i < utf8Length; ++i)
  491. echoText.AppendUTF8(echoCharacter_);
  492. text_->SetText(echoText);
  493. }
  494. if (cursorPosition_ > utf8Length)
  495. {
  496. cursorPosition_ = utf8Length;
  497. UpdateCursor();
  498. }
  499. using namespace TextChanged;
  500. VariantMap& eventData = GetEventDataMap();
  501. eventData[P_ELEMENT] = this;
  502. eventData[P_TEXT] = line_;
  503. SendEvent(E_TEXTCHANGED, eventData);
  504. }
  505. void LineEdit::UpdateCursor()
  506. {
  507. int x = text_->GetCharPosition(cursorPosition_).x_;
  508. text_->SetPosition(GetIndentWidth() + clipBorder_.left_, clipBorder_.top_);
  509. cursor_->SetPosition(text_->GetPosition() + IntVector2(x, 0));
  510. cursor_->SetSize(cursor_->GetWidth(), text_->GetRowHeight());
  511. IntVector2 screenPosition = ElementToScreen(cursor_->GetPosition());
  512. SDL_Rect rect = {screenPosition.x_, screenPosition.y_, cursor_->GetSize().x_, cursor_->GetSize().y_};
  513. SDL_SetTextInputRect(&rect);
  514. // Scroll if necessary
  515. int sx = -GetChildOffset().x_;
  516. int left = clipBorder_.left_;
  517. int right = GetWidth() - clipBorder_.left_ - clipBorder_.right_ - cursor_->GetWidth();
  518. if (x - sx > right)
  519. sx = x - right;
  520. if (x - sx < left)
  521. sx = x - left;
  522. if (sx < 0)
  523. sx = 0;
  524. SetChildOffset(IntVector2(-sx, 0));
  525. // Restart blinking
  526. cursorBlinkTimer_ = 0.0f;
  527. }
  528. unsigned LineEdit::GetCharIndex(const IntVector2& position)
  529. {
  530. IntVector2 screenPosition = ElementToScreen(position);
  531. IntVector2 textPosition = text_->ScreenToElement(screenPosition);
  532. if (textPosition.x_ < 0)
  533. return 0;
  534. for (int i = text_->GetNumChars(); i >= 0; --i)
  535. {
  536. if (textPosition.x_ >= text_->GetCharPosition((unsigned)i).x_)
  537. return (unsigned)i;
  538. }
  539. return M_MAX_UNSIGNED;
  540. }
  541. void LineEdit::HandleFocused(StringHash /*eventType*/, VariantMap& eventData)
  542. {
  543. if (eventData[Focused::P_BYKEY].GetBool())
  544. {
  545. cursorPosition_ = line_.LengthUTF8();
  546. text_->SetSelection(0);
  547. }
  548. UpdateCursor();
  549. if (GetSubsystem<UI>()->GetUseScreenKeyboard())
  550. GetSubsystem<Input>()->SetScreenKeyboardVisible(true);
  551. }
  552. void LineEdit::HandleDefocused(StringHash /*eventType*/, VariantMap& /*eventData*/)
  553. {
  554. text_->ClearSelection();
  555. if (GetSubsystem<UI>()->GetUseScreenKeyboard())
  556. GetSubsystem<Input>()->SetScreenKeyboardVisible(false);
  557. }
  558. void LineEdit::HandleLayoutUpdated(StringHash /*eventType*/, VariantMap& /*eventData*/)
  559. {
  560. UpdateCursor();
  561. }
  562. }