X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=examples%2Fsimple-scroll-view%2Fsimple-scroll-view-example.cpp;h=1a01c445c8a7bf765a2ad6854b62e6559f9f5d63;hb=1b19fd140ff139b5854a1a62447faf31b175d8f6;hp=b69bd98a13a50dcd835ae249e55350219ec9d928;hpb=b26d446b0cb6a316abc3a79d4fc70d0ae1b7994c;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/simple-scroll-view/simple-scroll-view-example.cpp b/examples/simple-scroll-view/simple-scroll-view-example.cpp index b69bd98..1a01c44 100644 --- a/examples/simple-scroll-view/simple-scroll-view-example.cpp +++ b/examples/simple-scroll-view/simple-scroll-view-example.cpp @@ -16,8 +16,8 @@ */ // EXTERNAL INCLUDES -#include #include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -37,13 +37,12 @@ const float DISTANCE_BETWEEN_IMAGES = 6.0f; ///< The distance between the images class ExampleController : public ConnectionTracker { public: - /** * Constructor * @param application class, stored as reference */ - ExampleController( Application& application ) - : mApplication( application ) + ExampleController(Application& application) + : mApplication(application) { // Connect to the Application's Init and orientation changed signal mApplication.InitSignal().Connect(this, &ExampleController::OnInit); @@ -52,15 +51,14 @@ public: ~ExampleController() = default; private: - /** * This method gets called once the main loop of application is up and running */ void OnInit(Application& app) { - Window window = app.GetWindow(); + Window window = app.GetWindow(); Vector2 windowSize = window.GetSize(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); window.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); // Make the scroll view's size a certain percentage of the window @@ -68,76 +66,76 @@ private: // Create a scroll view and set our desired properties ScrollView scrollView = ScrollView::New(); - scrollView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - scrollView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - scrollView.SetProperty( Actor::Property::SIZE, pageSize ); - scrollView.SetAxisAutoLock( true ); - window.Add( scrollView ); + scrollView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + scrollView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + scrollView.SetProperty(Actor::Property::SIZE, pageSize); + scrollView.SetAxisAutoLock(true); + window.Add(scrollView); // We want to the scroll-view so only one page is shown - scrollView.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); + scrollView.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX); // Create rulers for the X and Y domains, we want to disable vertical scrolling but enable horizontal scrolling - RulerPtr rulerX = new FixedRuler( pageSize.width ); // Snaps to a multiple of this when flicking + RulerPtr rulerX = new FixedRuler(pageSize.width); // Snaps to a multiple of this when flicking RulerPtr rulerY = new DefaultRuler; - rulerX->SetDomain( RulerDomain( 0.0f, pageSize.width * NUMBER_OF_PAGES, true ) ); // Set the domain to equal the number of pages used + rulerX->SetDomain(RulerDomain(0.0f, pageSize.width * NUMBER_OF_PAGES, true)); // Set the domain to equal the number of pages used rulerY->Disable(); - scrollView.SetRulerX( rulerX ); - scrollView.SetRulerY( rulerY ); + scrollView.SetRulerX(rulerX); + scrollView.SetRulerY(rulerY); // Populate the Pages - for( int column = 0, textNumber = 0; column < NUMBER_OF_PAGES; column++ ) + for(int column = 0, textNumber = 0; column < NUMBER_OF_PAGES; column++) { - Actor page = CreatePage( pageSize, textNumber ); - page.SetProperty( Actor::Property::POSITION, Vector2( column * pageSize.x, 0.0f )); - scrollView.Add( page ); + Actor page = CreatePage(pageSize, textNumber); + page.SetProperty(Actor::Property::POSITION, Vector2(column * pageSize.x, 0.0f)); + scrollView.Add(page); } // Do a little animation from the last page to the first page on load - scrollView.ScrollTo( NUMBER_OF_PAGES - 1, 0.0f ); - scrollView.ScrollTo( 0 ); + scrollView.ScrollTo(NUMBER_OF_PAGES - 1, 0.0f); + scrollView.ScrollTo(0); } /** * Creates a page using a source of images. */ - Actor CreatePage( const Vector2& pageSize, int& textNumber ) + Actor CreatePage(const Vector2& pageSize, int& textNumber) { Actor page = Actor::New(); - page.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - page.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - page.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + page.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + page.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + page.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); Window window = mApplication.GetWindow(); // Calculate the number of images going across (columns) within a page, the image size and the size of the text - const int imageColumns = round( ROWS_PER_PAGE * ( pageSize.width ) / ( pageSize.height ) ); - const Vector3 imageSize( ( pageSize.width / imageColumns ) - DISTANCE_BETWEEN_IMAGES, - ( pageSize.height / ROWS_PER_PAGE) - DISTANCE_BETWEEN_IMAGES, - 0.0f); - const float textPixelSize = imageSize.width / 3.0f; + const int imageColumns = round(ROWS_PER_PAGE * (pageSize.width) / (pageSize.height)); + const Vector3 imageSize((pageSize.width / imageColumns) - DISTANCE_BETWEEN_IMAGES, + (pageSize.height / ROWS_PER_PAGE) - DISTANCE_BETWEEN_IMAGES, + 0.0f); + const float textPixelSize = imageSize.width / 3.0f; // Populate the page - for( int row = 0; row < ROWS_PER_PAGE; row++ ) + for(int row = 0; row < ROWS_PER_PAGE; row++) { - for( int column = 0; column < imageColumns; column++ ) + for(int column = 0; column < imageColumns; column++) { - const Vector3 position( DISTANCE_BETWEEN_IMAGES * 0.5f + ( imageSize.x + DISTANCE_BETWEEN_IMAGES ) * column - pageSize.width * 0.5f, - DISTANCE_BETWEEN_IMAGES * 0.5f + ( imageSize.y + DISTANCE_BETWEEN_IMAGES ) * row - pageSize.height * 0.5f, - 0.0f); - - Control item = TextLabel::New( std::to_string( textNumber++ ) ); - item.SetProperty( Actor::Property::POSITION, position + imageSize * 0.5f ); - item.SetProperty( Actor::Property::SIZE, imageSize ); - item.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - item.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - item.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK ); - item.SetProperty( TextLabel::Property::PIXEL_SIZE, textPixelSize ); - item.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER ); - item.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER ); - item.SetProperty( TextLabel::Property::OUTLINE, Property::Map{ { "width", 2 }, { "color", Color::WHITE } } ); - 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 ) ); + const Vector3 position(DISTANCE_BETWEEN_IMAGES * 0.5f + (imageSize.x + DISTANCE_BETWEEN_IMAGES) * column - pageSize.width * 0.5f, + DISTANCE_BETWEEN_IMAGES * 0.5f + (imageSize.y + DISTANCE_BETWEEN_IMAGES) * row - pageSize.height * 0.5f, + 0.0f); + + Control item = TextLabel::New(std::to_string(textNumber++)); + item.SetProperty(Actor::Property::POSITION, position + imageSize * 0.5f); + item.SetProperty(Actor::Property::SIZE, imageSize); + item.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + item.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + item.SetProperty(TextLabel::Property::TEXT_COLOR, Color::BLACK); + item.SetProperty(TextLabel::Property::PIXEL_SIZE, textPixelSize); + item.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER); + item.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER); + item.SetProperty(TextLabel::Property::OUTLINE, Property::Map{{"width", 2}, {"color", Color::WHITE}}); + 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)); page.Add(item); } } @@ -152,7 +150,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -163,9 +161,9 @@ private: Application& mApplication; ///< Application instance }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); ExampleController test(app); app.MainLoop(); return 0;