Commit dbe9b795d03114abef61adda554b558a38c94d8e
Committed by
Richard Huang
1 parent
fde46e3e
Focus Integration Sample
You can check the InputFocus is given to focused Control. After that, when key is pressed, focused control's KeyEvent callback will be called. Change-Id: I93c605e7bcde5505099948445c762873f57e8381 Signed-off-by: minho.sun <minho.sun@samsung.com>
Showing
6 changed files
with
216 additions
and
0 deletions
com.samsung.dali-demo.xml
| ... | ... | @@ -197,4 +197,7 @@ |
| 197 | 197 | <ui-application appid="pivot.example" exec="/usr/apps/com.samsung.dali-demo/bin/pivot.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 198 | 198 | <label>Clipping</label> |
| 199 | 199 | </ui-application> |
| 200 | + <ui-application appid="focus-integration.example" exec="/usr/apps/com.samsung.dali-demo/bin/focus-integration.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | |
| 201 | + <label>Focus Integration</label> | |
| 202 | + </ui-application> | |
| 200 | 203 | </manifest> | ... | ... |
examples-reel/dali-examples-reel.cpp
| ... | ... | @@ -44,6 +44,7 @@ int DALI_EXPORT_API main(int argc, char **argv) |
| 44 | 44 | demo.AddExample(Example("dissolve-effect.example", DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION)); |
| 45 | 45 | demo.AddExample(Example("effects-view.example", DALI_DEMO_STR_TITLE_EFFECTS_VIEW)); |
| 46 | 46 | demo.AddExample(Example("flex-container.example", DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND)); |
| 47 | + demo.AddExample(Example("focus-integration.example", DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION)); | |
| 47 | 48 | demo.AddExample(Example("gradients.example", DALI_DEMO_STR_TITLE_COLOR_GRADIENT)); |
| 48 | 49 | demo.AddExample(Example("image-scaling-and-filtering.example", DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING)); |
| 49 | 50 | demo.AddExample(Example("image-scaling-irregular-grid.example", DALI_DEMO_STR_TITLE_IMAGE_SCALING)); | ... | ... |
examples/focus-integration/focus-integration.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2017 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +#include "shared/view.h" | |
| 19 | +#include <dali-toolkit/dali-toolkit.h> | |
| 20 | + | |
| 21 | +using namespace Dali; | |
| 22 | +using namespace Dali::Toolkit; | |
| 23 | + | |
| 24 | +namespace | |
| 25 | +{ | |
| 26 | + | |
| 27 | +const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg"; | |
| 28 | +const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; | |
| 29 | +const char* const TOOLBAR_TITLE = "Focus Integration"; | |
| 30 | +const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f ); | |
| 31 | + | |
| 32 | +// Layout sizes | |
| 33 | +const int MARGIN_SIZE = 10; | |
| 34 | +const int TOP_MARGIN = 85; | |
| 35 | +const std::string ITEMNAME[] = { "TextLabel", "TextField", "TextEditor", "PushButton", "RadioButton", "CheckBoxButton" }; | |
| 36 | + | |
| 37 | +} // namespace | |
| 38 | + | |
| 39 | +/** | |
| 40 | + * @brief Shows how integrated DALi Focus works. | |
| 41 | + */ | |
| 42 | +class FocusIntegrationExample: public ConnectionTracker | |
| 43 | +{ | |
| 44 | +public: | |
| 45 | + | |
| 46 | + FocusIntegrationExample( Application& application ) | |
| 47 | + : mApplication( application ) | |
| 48 | + { | |
| 49 | + // Connect to the Application's Init signal | |
| 50 | + mApplication.InitSignal().Connect( this, &FocusIntegrationExample::Create ); | |
| 51 | + } | |
| 52 | + | |
| 53 | + void Create( Application& application ) | |
| 54 | + { | |
| 55 | + mStage = Stage::GetCurrent(); | |
| 56 | + mContentLayer = DemoHelper::CreateView( application, | |
| 57 | + mView, | |
| 58 | + mToolBar, | |
| 59 | + BACKGROUND_IMAGE, | |
| 60 | + TOOLBAR_IMAGE, | |
| 61 | + TOOLBAR_TITLE ); | |
| 62 | + | |
| 63 | + TableView contentTable = TableView::New(2, 1); | |
| 64 | + contentTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); | |
| 65 | + contentTable.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); | |
| 66 | + contentTable.SetAnchorPoint(AnchorPoint::TOP_LEFT); | |
| 67 | + contentTable.SetParentOrigin(ParentOrigin::TOP_LEFT); | |
| 68 | + contentTable.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE * 0.5f)); | |
| 69 | + contentTable.SetKeyboardFocusable(true); | |
| 70 | + | |
| 71 | + for( unsigned int i = 0; i < contentTable.GetRows(); ++i ) | |
| 72 | + { | |
| 73 | + contentTable.SetFitHeight( i ); | |
| 74 | + } | |
| 75 | + contentTable.SetPosition( 0.0f, TOP_MARGIN ); | |
| 76 | + mContentLayer.Add( contentTable ); | |
| 77 | + | |
| 78 | + // Create label to display which control's KeyEvent callback is called | |
| 79 | + mEventLabel = TextLabel::New("Controls don't get KeyEvent yet"); | |
| 80 | + mEventLabel.SetSize( mStage.GetSize().width, mStage.GetSize().height*0.1f ); | |
| 81 | + mEventLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); | |
| 82 | + mEventLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); | |
| 83 | + mEventLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); | |
| 84 | + mEventLabel.SetBackgroundColor( Color::WHITE ); | |
| 85 | + contentTable.Add( mEventLabel ); | |
| 86 | + | |
| 87 | + mContainer = TableView::New( 4, 3 ); | |
| 88 | + mContainer.SetSize( mStage.GetSize().width, mStage.GetSize().height*0.4f ); | |
| 89 | + mContainer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); | |
| 90 | + mContainer.SetBackgroundColor( BACKGROUND_COLOUR ); | |
| 91 | + mContainer.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); | |
| 92 | + mContainer.SetRelativeHeight( 0, 0.2f); | |
| 93 | + mContainer.SetRelativeHeight( 1, 0.3f); | |
| 94 | + mContainer.SetRelativeHeight( 2, 0.2f); | |
| 95 | + mContainer.SetRelativeHeight( 3, 0.3f); | |
| 96 | + mContainer.SetKeyboardFocusable(true); | |
| 97 | + contentTable.Add( mContainer ); | |
| 98 | + | |
| 99 | + // Make name label for each controls | |
| 100 | + for(int i = 0; i < 6; i++) | |
| 101 | + { | |
| 102 | + TextLabel itemLabel = TextLabel::New( ITEMNAME[i] ); | |
| 103 | + itemLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | |
| 104 | + itemLabel.SetBackgroundColor( BACKGROUND_COLOUR ); | |
| 105 | + itemLabel.SetProperty( TextLabel::Property::POINT_SIZE, 14.0f ); | |
| 106 | + itemLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); | |
| 107 | + itemLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); | |
| 108 | + mContainer.AddChild( itemLabel, TableView::CellPosition( (i/3)*2, i%3 ) ); | |
| 109 | + } | |
| 110 | + | |
| 111 | + TextLabel textLabel = TextLabel::New("TextLabel"); | |
| 112 | + mContainer.AddChild( textLabel, TableView::CellPosition( 1, 0 ) ); | |
| 113 | + | |
| 114 | + TextField textField = TextField::New(); | |
| 115 | + textField.SetBackgroundColor( Color::WHITE ); | |
| 116 | + textField.SetProperty( TextField::Property::TEXT, "Text" ); | |
| 117 | + mContainer.AddChild( textField, TableView::CellPosition( 1, 1 ) ); | |
| 118 | + | |
| 119 | + TextEditor textEditor = TextEditor::New(); | |
| 120 | + textEditor.SetBackgroundColor( Color::WHITE ); | |
| 121 | + textEditor.SetProperty( TextEditor::Property::TEXT, "Text\nText" ); | |
| 122 | + mContainer.AddChild( textEditor, TableView::CellPosition( 1, 2 ) ); | |
| 123 | + | |
| 124 | + PushButton pushButton = PushButton::New(); | |
| 125 | + mContainer.AddChild( pushButton, TableView::CellPosition( 3, 0 ) ); | |
| 126 | + | |
| 127 | + RadioButton radioButton = RadioButton::New(); | |
| 128 | + mContainer.AddChild( radioButton, TableView::CellPosition( 3, 1 ) ); | |
| 129 | + | |
| 130 | + CheckBoxButton checkBoxButton = CheckBoxButton::New(); | |
| 131 | + mContainer.AddChild( checkBoxButton, TableView::CellPosition( 3, 2 ) ); | |
| 132 | + | |
| 133 | + // Set name and keyboard focusable for each controls | |
| 134 | + for(int i = 0; i<6; i++) | |
| 135 | + { | |
| 136 | + Control control = Control::DownCast( mContainer.GetChildAt( TableView::CellPosition( (i/3)*2+1, i%3 ) ) ); | |
| 137 | + control.SetKeyboardFocusable(true); | |
| 138 | + control.SetName(ITEMNAME[i]); | |
| 139 | + control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | |
| 140 | + control.KeyEventSignal().Connect( this, &FocusIntegrationExample::OnControlKeyEvent ); | |
| 141 | + } | |
| 142 | + | |
| 143 | + KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &FocusIntegrationExample::OnPreFocusChange ); | |
| 144 | + } | |
| 145 | + | |
| 146 | + // Callback for KeyboardFocusManager | |
| 147 | + Actor OnPreFocusChange( Actor current, Actor next, Control::KeyboardFocus::Direction direction ) | |
| 148 | + { | |
| 149 | + if( !current && !next ) | |
| 150 | + { | |
| 151 | + next = mContainer.GetChildAt( TableView::CellPosition( 1, 0 ) ); | |
| 152 | + } | |
| 153 | + return next; | |
| 154 | + } | |
| 155 | + | |
| 156 | + // Callback for each controls. | |
| 157 | + // Display current control name. | |
| 158 | + bool OnControlKeyEvent( Control control, const KeyEvent& event ) | |
| 159 | + { | |
| 160 | + std::string controlName = control.GetName(); | |
| 161 | + mEventLabel.SetProperty( TextLabel::Property::TEXT, controlName+"'s KeyEvent works\n" ); | |
| 162 | + | |
| 163 | + return false; | |
| 164 | + } | |
| 165 | + | |
| 166 | +private: | |
| 167 | + | |
| 168 | + /** | |
| 169 | + * Main key event handler | |
| 170 | + */ | |
| 171 | + void OnKeyEvent(const KeyEvent& event) | |
| 172 | + { | |
| 173 | + if(event.state == KeyEvent::Down) | |
| 174 | + { | |
| 175 | + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) | |
| 176 | + { | |
| 177 | + mApplication.Quit(); | |
| 178 | + } | |
| 179 | + } | |
| 180 | + } | |
| 181 | + | |
| 182 | +private: | |
| 183 | + | |
| 184 | + Application& mApplication; | |
| 185 | + Stage mStage; | |
| 186 | + TableView mContainer; | |
| 187 | + TextLabel mEventLabel; | |
| 188 | + Toolkit::Control mView; ///< The View instance. | |
| 189 | + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. | |
| 190 | + Layer mContentLayer; ///< Content layer. | |
| 191 | +}; | |
| 192 | + | |
| 193 | +// Entry point for Linux & Tizen applications | |
| 194 | +// | |
| 195 | +int DALI_EXPORT_API main( int argc, char **argv ) | |
| 196 | +{ | |
| 197 | + Application application = Application::New( &argc, &argv ); | |
| 198 | + | |
| 199 | + FocusIntegrationExample test( application ); | |
| 200 | + | |
| 201 | + application.MainLoop(); | |
| 202 | + | |
| 203 | + return 0; | |
| 204 | +} | ... | ... |
resources/po/en_GB.po
resources/po/en_US.po
shared/dali-demo-strings.h
| ... | ... | @@ -46,6 +46,7 @@ extern "C" |
| 46 | 46 | #define DALI_DEMO_STR_TITLE_EMOJI_TEXT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EMOJI_TEXT") |
| 47 | 47 | #define DALI_DEMO_STR_TITLE_FPP_GAME dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FPP_GAME") |
| 48 | 48 | #define DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND") |
| 49 | +#define DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION") | |
| 49 | 50 | #define DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING") |
| 50 | 51 | #define DALI_DEMO_STR_TITLE_IMAGE_SCALING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_SCALING") |
| 51 | 52 | #define DALI_DEMO_STR_TITLE_IMAGE_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW") |
| ... | ... | @@ -105,6 +106,7 @@ extern "C" |
| 105 | 106 | #define DALI_DEMO_STR_TITLE_EMOJI_TEXT "Emoji Text" |
| 106 | 107 | #define DALI_DEMO_STR_TITLE_FPP_GAME "First Person Game" |
| 107 | 108 | #define DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND "Flexbox Playground" |
| 109 | +#define DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION "Focus Integration" | |
| 108 | 110 | #define DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING "Image Fitting and Sampling" |
| 109 | 111 | #define DALI_DEMO_STR_TITLE_IMAGE_SCALING "Image Scaling Grid" |
| 110 | 112 | #define DALI_DEMO_STR_TITLE_IMAGE_VIEW "Image View" | ... | ... |