LineEdit.cpp 20 KB

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