LineEdit.cpp 21 KB

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