Commit 042691b612dcd736da9126b81da04e68d07885ac
1 parent
54cf171c
A very simple scroll-view example
Change-Id: I49298a830fd6faaf20325ef1f0339d012140b88e
Showing
6 changed files
with
185 additions
and
2 deletions
com.samsung.dali-demo.xml
| ... | ... | @@ -232,6 +232,9 @@ |
| 232 | 232 | <ui-application appid="simple-layout.example" exec="/usr/apps/com.samsung.dali-demo/bin/simple-layout.example" nodisplay="true" multiple="false" taskmanage="true" type="c++app"> |
| 233 | 233 | <label>Simple Layout</label> |
| 234 | 234 | </ui-application> |
| 235 | + <ui-application appid="simple-scroll-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/simple-scroll-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | |
| 236 | + <label>Simple Scroll View</label> | |
| 237 | + </ui-application> | |
| 235 | 238 | <ui-application appid="simple-text-field.example" exec="/usr/apps/com.samsung.dali-demo/bin/simple-text-field.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 236 | 239 | <label>Simple Text Field</label> |
| 237 | 240 | </ui-application> | ... | ... |
examples/simple-scroll-view/simple-scroll-view-example.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2019 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 | +// EXTERNAL INCLUDES | |
| 19 | +#include <dali/dali.h> | |
| 20 | +#include <dali-toolkit/dali-toolkit.h> | |
| 21 | + | |
| 22 | +using namespace Dali; | |
| 23 | +using namespace Dali::Toolkit; | |
| 24 | + | |
| 25 | +namespace | |
| 26 | +{ | |
| 27 | +const int NUMBER_OF_PAGES = 9; ///< Number of Pages going across | |
| 28 | +const int ROWS_PER_PAGE = 5; ///< Number of Images going down (rows) within a Page | |
| 29 | + | |
| 30 | +const float DISTANCE_BETWEEN_IMAGES = 6.0f; ///< The distance between the images | |
| 31 | + | |
| 32 | +} // unnamed namespace | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * An example showing how to create a very simple scroll view | |
| 36 | + */ | |
| 37 | +class ExampleController : public ConnectionTracker | |
| 38 | +{ | |
| 39 | +public: | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * Constructor | |
| 43 | + * @param application class, stored as reference | |
| 44 | + */ | |
| 45 | + ExampleController( Application& application ) | |
| 46 | + : mApplication( application ) | |
| 47 | + { | |
| 48 | + // Connect to the Application's Init and orientation changed signal | |
| 49 | + mApplication.InitSignal().Connect(this, &ExampleController::OnInit); | |
| 50 | + } | |
| 51 | + | |
| 52 | + ~ExampleController() = default; | |
| 53 | + | |
| 54 | +private: | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * This method gets called once the main loop of application is up and running | |
| 58 | + */ | |
| 59 | + void OnInit(Application& app) | |
| 60 | + { | |
| 61 | + Stage stage = Dali::Stage::GetCurrent(); | |
| 62 | + stage.SetBackgroundColor( Color::WHITE ); | |
| 63 | + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); | |
| 64 | + | |
| 65 | + // Make the scroll view's size a certain percentage of the stage | |
| 66 | + const Vector2 pageSize = stage.GetSize() * 0.75f; | |
| 67 | + | |
| 68 | + // Create a scroll view and set our desired properties | |
| 69 | + ScrollView scrollView = ScrollView::New(); | |
| 70 | + scrollView.SetAnchorPoint( AnchorPoint::CENTER ); | |
| 71 | + scrollView.SetParentOrigin( ParentOrigin::CENTER ); | |
| 72 | + scrollView.SetSize( pageSize ); | |
| 73 | + scrollView.SetAxisAutoLock( true ); | |
| 74 | + stage.Add( scrollView ); | |
| 75 | + | |
| 76 | + // We want to the scroll-view so only one page is shown | |
| 77 | + scrollView.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); | |
| 78 | + | |
| 79 | + // Create rulers for the X and Y domains, we want to disable vertical scrolling but enable horizontal scrolling | |
| 80 | + RulerPtr rulerX = new FixedRuler( pageSize.width ); // Snaps to a multiple of this when flicking | |
| 81 | + RulerPtr rulerY = new DefaultRuler; | |
| 82 | + rulerX->SetDomain( RulerDomain( 0.0f, pageSize.width * NUMBER_OF_PAGES, true ) ); // Set the domain to equal the number of pages used | |
| 83 | + rulerY->Disable(); | |
| 84 | + | |
| 85 | + scrollView.SetRulerX( rulerX ); | |
| 86 | + scrollView.SetRulerY( rulerY ); | |
| 87 | + | |
| 88 | + // Populate the Pages | |
| 89 | + for( int column = 0, textNumber = 0; column < NUMBER_OF_PAGES; column++ ) | |
| 90 | + { | |
| 91 | + Actor page = CreatePage( pageSize, textNumber ); | |
| 92 | + page.SetPosition( column * pageSize.x, 0.0f ); | |
| 93 | + scrollView.Add( page ); | |
| 94 | + } | |
| 95 | + | |
| 96 | + // Do a little animation from the last page to the first page on load | |
| 97 | + scrollView.ScrollTo( NUMBER_OF_PAGES - 1, 0.0f ); | |
| 98 | + scrollView.ScrollTo( 0 ); | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Creates a page using a source of images. | |
| 103 | + */ | |
| 104 | + Actor CreatePage( const Vector2& pageSize, int& textNumber ) | |
| 105 | + { | |
| 106 | + Actor page = Actor::New(); | |
| 107 | + page.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | |
| 108 | + page.SetParentOrigin( ParentOrigin::CENTER ); | |
| 109 | + page.SetAnchorPoint( AnchorPoint::CENTER ); | |
| 110 | + | |
| 111 | + Stage stage = Stage::GetCurrent(); | |
| 112 | + | |
| 113 | + // Calculate the number of images going across (columns) within a page, the image size and the size of the text | |
| 114 | + const int imageColumns = round( ROWS_PER_PAGE * ( pageSize.width ) / ( pageSize.height ) ); | |
| 115 | + const Vector3 imageSize( ( pageSize.width / imageColumns ) - DISTANCE_BETWEEN_IMAGES, | |
| 116 | + ( pageSize.height / ROWS_PER_PAGE) - DISTANCE_BETWEEN_IMAGES, | |
| 117 | + 0.0f); | |
| 118 | + const float textPixelSize = imageSize.width / 3.0f; | |
| 119 | + | |
| 120 | + // Populate the page | |
| 121 | + for( int row = 0; row < ROWS_PER_PAGE; row++ ) | |
| 122 | + { | |
| 123 | + for( int column = 0; column < imageColumns; column++ ) | |
| 124 | + { | |
| 125 | + const Vector3 position( DISTANCE_BETWEEN_IMAGES * 0.5f + ( imageSize.x + DISTANCE_BETWEEN_IMAGES ) * column - pageSize.width * 0.5f, | |
| 126 | + DISTANCE_BETWEEN_IMAGES * 0.5f + ( imageSize.y + DISTANCE_BETWEEN_IMAGES ) * row - pageSize.height * 0.5f, | |
| 127 | + 0.0f); | |
| 128 | + | |
| 129 | + Control item = TextLabel::New( std::to_string( textNumber++ ) ); | |
| 130 | + item.SetProperty( Actor::Property::POSITION, position + imageSize * 0.5f ); | |
| 131 | + item.SetProperty( Actor::Property::SIZE, imageSize ); | |
| 132 | + item.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); | |
| 133 | + item.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); | |
| 134 | + item.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK ); | |
| 135 | + item.SetProperty( TextLabel::Property::PIXEL_SIZE, textPixelSize ); | |
| 136 | + item.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER ); | |
| 137 | + item.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER ); | |
| 138 | + item.SetProperty( TextLabel::Property::OUTLINE, Property::Map{ { "width", 2 }, { "color", Color::WHITE } } ); | |
| 139 | + item.SetProperty( Control::Property::BACKGROUND, Vector4( Random::Range( 0.0f, 1.0f ), Random::Range( 0.0f, 1.0f ), Random::Range( 0.0f, 1.0f ), 0.7f ) ); | |
| 140 | + page.Add(item); | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 144 | + return page; | |
| 145 | + } | |
| 146 | + | |
| 147 | + /** | |
| 148 | + * Main key event handler | |
| 149 | + */ | |
| 150 | + void OnKeyEvent(const KeyEvent& event) | |
| 151 | + { | |
| 152 | + if(event.state == KeyEvent::Down) | |
| 153 | + { | |
| 154 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | |
| 155 | + { | |
| 156 | + mApplication.Quit(); | |
| 157 | + } | |
| 158 | + } | |
| 159 | + } | |
| 160 | + | |
| 161 | +private: | |
| 162 | + Application& mApplication; ///< Application instance | |
| 163 | +}; | |
| 164 | + | |
| 165 | +int DALI_EXPORT_API main(int argc, char **argv) | |
| 166 | +{ | |
| 167 | + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); | |
| 168 | + ExampleController test(app); | |
| 169 | + app.MainLoop(); | |
| 170 | + return 0; | |
| 171 | +} | ... | ... |
resources/po/en_GB.po
| ... | ... | @@ -184,6 +184,9 @@ msgstr "Script-based UI" |
| 184 | 184 | msgid "DALI_DEMO_STR_TITLE_SCROLL_VIEW" |
| 185 | 185 | msgstr "Scroll View" |
| 186 | 186 | |
| 187 | +msgid "DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW" | |
| 188 | +msgstr "Simple Scroll View" | |
| 189 | + | |
| 187 | 190 | msgid "DALI_DEMO_STR_TITLE_SPARKLE" |
| 188 | 191 | msgstr "Sparkle" |
| 189 | 192 | ... | ... |
resources/po/en_US.po
| ... | ... | @@ -187,6 +187,9 @@ msgstr "Script-based UI" |
| 187 | 187 | msgid "DALI_DEMO_STR_TITLE_SCROLL_VIEW" |
| 188 | 188 | msgstr "Scroll View" |
| 189 | 189 | |
| 190 | +msgid "DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW" | |
| 191 | +msgstr "Simple Scroll View" | |
| 192 | + | |
| 190 | 193 | msgid "DALI_DEMO_STR_TITLE_SPARKLE" |
| 191 | 194 | msgstr "Sparkle" |
| 192 | 195 | ... | ... |
shared/dali-demo-strings.h
| ... | ... | @@ -102,9 +102,10 @@ extern "C" |
| 102 | 102 | #define DALI_DEMO_STR_TITLE_RENDERING_RADIAL_PROGRESS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_RADIAL_PROGRESS") |
| 103 | 103 | #define DALI_DEMO_STR_TITLE_RENDERING_RAY_MARCHING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_RAY_MARCHING") |
| 104 | 104 | #define DALI_DEMO_STR_TITLE_RENDERER_STENCIL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERER_STENCIL") |
| 105 | -#define DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL") | |
| 106 | 105 | #define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI") |
| 107 | 106 | #define DALI_DEMO_STR_TITLE_SCROLL_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCROLL_VIEW") |
| 107 | +#define DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW") | |
| 108 | +#define DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL") | |
| 108 | 109 | #define DALI_DEMO_STR_TITLE_SKYBOX dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SKYBOX") |
| 109 | 110 | #define DALI_DEMO_STR_TITLE_SPARKLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SPARKLE") |
| 110 | 111 | #define DALI_DEMO_STR_TITLE_STYLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_STYLING") |
| ... | ... | @@ -199,9 +200,10 @@ extern "C" |
| 199 | 200 | #define DALI_DEMO_STR_TITLE_RENDERING_RAY_MARCHING "Ray Marching" |
| 200 | 201 | #define DALI_DEMO_STR_TITLE_RENDERING_RADIAL_PROGRESS "Radial Progress" |
| 201 | 202 | #define DALI_DEMO_STR_TITLE_RENDERER_STENCIL "Renderer Stencils" |
| 202 | -#define DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL "Simple Visuals Control" | |
| 203 | 203 | #define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI "Script Based UI" |
| 204 | 204 | #define DALI_DEMO_STR_TITLE_SCROLL_VIEW "Scroll View" |
| 205 | +#define DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW "Simple Scroll View" | |
| 206 | +#define DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL "Simple Visuals Control" | |
| 205 | 207 | #define DALI_DEMO_STR_TITLE_SKYBOX "Skybox" |
| 206 | 208 | #define DALI_DEMO_STR_TITLE_SPARKLE "Sparkle" |
| 207 | 209 | #define DALI_DEMO_STR_TITLE_STYLING "Styling" | ... | ... |
tests-reel/dali-tests-reel.cpp
| ... | ... | @@ -49,6 +49,7 @@ int DALI_EXPORT_API main(int argc, char **argv) |
| 49 | 49 | demo.AddExample(Example("text-overlap.example", DALI_DEMO_STR_TITLE_TEXT_OVERLAP)); |
| 50 | 50 | demo.AddExample(Example("visual-fitting-mode.example", DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE)); |
| 51 | 51 | demo.AddExample(Example("visual-transitions.example", DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS)); |
| 52 | + demo.AddExample(Example("simple-scroll-view.example", DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW)); | |
| 52 | 53 | demo.AddExample(Example("simple-text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)); |
| 53 | 54 | demo.AddExample(Example("simple-text-field.example", DALI_DEMO_STR_TITLE_TEXT_FIELD)); |
| 54 | 55 | demo.AddExample(Example("simple-text-renderer.example", DALI_DEMO_STR_TITLE_TEXT_RENDERER)); | ... | ... |