Commit 2ad634fa738e36171a4116b09b94c19cd5c60a81
Committed by
Ali Alzyod
1 parent
4f2d9d01
Dali-tests: add support for SELECTED_TEXT_START/END
Modify simple-text-field to support programatical selection modification Change-Id: I173f0484113cf5e8cbc99b54ab1e0b2e83ea6c05
Showing
1 changed file
with
52 additions
and
9 deletions
examples/simple-text-field/simple-text-field.cpp
| ... | ... | @@ -22,6 +22,7 @@ |
| 22 | 22 | |
| 23 | 23 | // EXTERNAL INCLUDES |
| 24 | 24 | #include <dali-toolkit/dali-toolkit.h> |
| 25 | +#include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h> | |
| 25 | 26 | #include <iostream> |
| 26 | 27 | |
| 27 | 28 | using namespace Dali; |
| ... | ... | @@ -54,17 +55,56 @@ public: |
| 54 | 55 | window.KeyEventSignal().Connect(this, &SimpleTextFieldExample::OnKeyEvent); |
| 55 | 56 | window.SetBackgroundColor(Vector4(0.04f, 0.345f, 0.392f, 1.0f)); |
| 56 | 57 | |
| 57 | - TextField field = TextField::New(); | |
| 58 | - field.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); | |
| 59 | - field.SetProperty(Actor::Property::SIZE, Vector2(300.f, 60.f)); | |
| 60 | - field.SetBackgroundColor(Color::WHITE); | |
| 61 | - field.SetBackgroundColor(Vector4(1.f, 1.f, 1.f, 0.15f)); | |
| 58 | + mTextField = TextField::New(); | |
| 59 | + mTextField.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); | |
| 60 | + mTextField.SetProperty(Actor::Property::SIZE, Vector2(300.f, 60.f)); | |
| 61 | + mTextField.SetBackgroundColor(Color::WHITE); | |
| 62 | + mTextField.SetBackgroundColor(Vector4(1.f, 1.f, 1.f, 0.15f)); | |
| 63 | + | |
| 64 | + mTextField.SetProperty(TextField::Property::TEXT_COLOR, Color::BLACK); | |
| 65 | + mTextField.SetProperty(TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder"); | |
| 66 | + mTextField.SetProperty(TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name."); | |
| 67 | + | |
| 68 | + mButtonSelectionStart = PushButton::New(); | |
| 69 | + mButtonSelectionEnd = PushButton::New(); | |
| 70 | + | |
| 71 | + mButtonSelectionStart.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); | |
| 72 | + mButtonSelectionStart.SetProperty(Actor::Property::SIZE, Vector2(140.f, 50.f)); | |
| 73 | + mButtonSelectionStart.SetProperty(Actor::Property::POSITION, Vector2(0.f, 80.f)); | |
| 74 | + mButtonSelectionStart.SetBackgroundColor(Color::BLUE); | |
| 75 | + mButtonSelectionStart.SetProperty(Button::Property::LABEL, "select <--"); | |
| 76 | + mButtonSelectionStart.ClickedSignal().Connect(this, &SimpleTextFieldExample::OnButtonClicked); | |
| 77 | + | |
| 78 | + mButtonSelectionEnd.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); | |
| 79 | + mButtonSelectionEnd.SetProperty(Actor::Property::SIZE, Vector2(140.f, 50.f)); | |
| 80 | + mButtonSelectionEnd.SetProperty(Actor::Property::POSITION, Vector2(0.f, 140.f)); | |
| 81 | + mButtonSelectionEnd.SetBackgroundColor(Color::BLUE); | |
| 82 | + mButtonSelectionEnd.SetProperty(Button::Property::LABEL, "select -->"); | |
| 83 | + mButtonSelectionEnd.ClickedSignal().Connect(this, &SimpleTextFieldExample::OnButtonClicked); | |
| 84 | + | |
| 85 | + window.Add(mTextField); | |
| 86 | + window.Add(mButtonSelectionStart); | |
| 87 | + window.Add(mButtonSelectionEnd); | |
| 88 | + } | |
| 89 | + | |
| 62 | 90 | |
| 63 | - field.SetProperty(TextField::Property::TEXT_COLOR, Color::BLACK); | |
| 64 | - field.SetProperty(TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder"); | |
| 65 | - field.SetProperty(TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name."); | |
| 91 | + bool OnButtonClicked(Button button) | |
| 92 | + { | |
| 93 | + if(button == mButtonSelectionStart) | |
| 94 | + { | |
| 95 | + int iStart = mTextField.GetProperty(DevelTextField::Property::SELECTED_TEXT_START).Get<int>() - 1; | |
| 96 | + if (iStart < 0) | |
| 97 | + { | |
| 98 | + iStart = 0; | |
| 99 | + } | |
| 100 | + mTextField.SetProperty(DevelTextField::Property::SELECTED_TEXT_START, iStart); | |
| 101 | + } | |
| 102 | + else if(button == mButtonSelectionEnd) | |
| 103 | + { | |
| 104 | + mTextField.SetProperty(DevelTextField::Property::SELECTED_TEXT_END , mTextField.GetProperty(DevelTextField::Property::SELECTED_TEXT_END).Get<int>() + 1); | |
| 105 | + } | |
| 66 | 106 | |
| 67 | - window.Add(field); | |
| 107 | + return true; | |
| 68 | 108 | } |
| 69 | 109 | |
| 70 | 110 | /** |
| ... | ... | @@ -83,6 +123,9 @@ public: |
| 83 | 123 | |
| 84 | 124 | private: |
| 85 | 125 | Application& mApplication; |
| 126 | + TextField mTextField; | |
| 127 | + PushButton mButtonSelectionStart; | |
| 128 | + PushButton mButtonSelectionEnd; | |
| 86 | 129 | }; |
| 87 | 130 | |
| 88 | 131 | void RunTest(Application& application) | ... | ... |