Ensured some examples work well in landscape 08/273508/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 6 Apr 2022 15:49:06 +0000 (16:49 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 6 Apr 2022 15:49:06 +0000 (16:49 +0100)
Change-Id: I471f5cf47e8e8582b40d63be2b5d40c2b5393993

examples/bezier-curve/bezier-curve-example.cpp
examples/drag-and-drop/drag-and-drop-example.cpp
examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp
examples/rendering-basic-light/rendering-basic-light-example.cpp
examples/rendering-cube/rendering-cube.cpp
examples/rendering-textured-cube/rendering-textured-cube.cpp
examples/text-label/text-label-example.cpp

index 3f5425c..d2c285d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -123,6 +123,22 @@ public:
   {
     Window window = mApplication.GetWindow();
     window.KeyEventSignal().Connect(this, &BezierCurveExample::OnKeyEvent);
+    const Vector2 windowSize = window.GetSize();
+    const bool orientationPortrait = windowSize.width < windowSize.height;
+
+    unsigned int tableViewRows = 5;
+    unsigned int tableViewColumns = 1;
+    unsigned int rowPositionAdder = 1;
+    TableView::CellPosition gridPosition{1,0};
+
+    // Change layout if we're in landscape mode
+    if(!orientationPortrait)
+    {
+      tableViewRows = 4;
+      tableViewColumns = 2;
+      rowPositionAdder = 0;
+      gridPosition = {0,1,4,1};
+    }
 
     CreateBackground(window);
 
@@ -135,8 +151,7 @@ public:
     mContentLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
     window.Add(mContentLayer);
 
-    // 6 rows: title, grid, coords, play, anim1, anim2
-    TableView contentLayout = TableView::New(5, 1);
+    TableView contentLayout = TableView::New(tableViewRows, tableViewColumns);
     contentLayout.SetProperty(Dali::Actor::Property::NAME, "contentLayout");
     contentLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
     contentLayout.SetCellPadding(Size(30, 30));
@@ -161,7 +176,7 @@ public:
     mGrid.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
     mGrid.SetBackgroundColor(GRID_BACKGROUND_COLOR);
 
-    contentLayout.Add(mGrid);
+    contentLayout.AddChild(mGrid, gridPosition);
     contentLayout.SetCellAlignment(1, HorizontalAlignment::CENTER, VerticalAlignment::CENTER);
     CreateCubic(mGrid);
     CreateControlPoints(mGrid); // Control points constrained to double height of grid
@@ -175,7 +190,7 @@ public:
 
     contentLayout.Add(mCoefficientLabel);
     SetLabel(Vector2(0, 0), Vector2(1, 1));
-    contentLayout.SetCellAlignment(2, HorizontalAlignment::CENTER, VerticalAlignment::CENTER);
+    contentLayout.SetCellAlignment(1 + rowPositionAdder, HorizontalAlignment::CENTER, VerticalAlignment::CENTER);
     contentLayout.SetFitHeight(2);
 
     // Setup Play button and 2 icons to show off current anim and linear anim
@@ -187,8 +202,8 @@ public:
     play.ClickedSignal().Connect(this, &BezierCurveExample::OnPlayClicked);
 
     contentLayout.Add(play);
-    contentLayout.SetCellAlignment(3, HorizontalAlignment::CENTER, VerticalAlignment::CENTER);
-    contentLayout.SetFitHeight(3);
+    contentLayout.SetCellAlignment(2 + rowPositionAdder, HorizontalAlignment::CENTER, VerticalAlignment::CENTER);
+    contentLayout.SetFitHeight(2 + rowPositionAdder);
 
     auto animContainer = Control::New();
     animContainer.SetProperty(Dali::Actor::Property::NAME, "AnimationContainer");
@@ -203,7 +218,7 @@ public:
     animContainer.Add(animRail);
 
     contentLayout.Add(animContainer);
-    contentLayout.SetFixedHeight(4, 150);
+    contentLayout.SetFixedHeight(3 + rowPositionAdder, 150);
 
     mAnimIcon1 = ImageView::New(CIRCLE1_IMAGE);
     mAnimIcon1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
index 85e2d0b..96ebeb4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -73,6 +73,7 @@ public:
   {
     auto window = application.GetWindow();
     window.SetBackgroundColor(Color::WHITE);
+    const auto windowHeight = window.GetSize().GetHeight();
 
     mDragAndDropDetector = Dali::Toolkit::DragAndDropDetector::New();
 
@@ -80,14 +81,19 @@ public:
     window.KeyEventSignal().Connect(this, &DragAndDropExample::OnKeyEvent);
 
     TextLabel hintText = TextLabel::New("please drag one textlabel, move and drop on other textlabel");
-    hintText.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 700.0f));
-    hintText.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
-    hintText.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+    hintText.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT);
+    hintText.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT);
     hintText.SetProperty(TextLabel::Property::MULTI_LINE, true);
     window.Add(hintText);
 
     for(unsigned int i = 0; i < TEXT_LABEL_NUM; i++)
     {
+      // Should be able to fit this and another more so if the height is less, then just stop adding new text labels
+      if((TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * (i + 2)) >= windowHeight)
+      {
+        break;
+      }
+
       std::string str = "textlabel ";
       mTextLabel[i]   = TextLabel::New(str + std::to_string(i));
       mTextLabel[i].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
index ef05f6f..190a590 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -49,6 +49,9 @@ private:
     // Get a handle to the window
     Window window = application.GetWindow();
     window.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent);
+    const Vector2 windowSize = window.GetSize();
+    const bool portraitOrientation = windowSize.width < windowSize.height;
+    const Property::Index positionProperty = portraitOrientation ? Actor::Property::POSITION_Y : Actor::Property::POSITION_X;
 
     auto  green0    = Vector4(0.f, 1.f, 0.f, 0.25f);
     auto  green1    = Vector4(0.f, 0.25f, 0.f, 0.25f);
@@ -59,7 +62,7 @@ private:
     Toolkit::ImageView imageView0 = CreateImageView(IMAGE_PATH);
     imageView0.SetProperty(Actor::Property::SIZE, Vector2(imageSize, imageSize));
     imageView0.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
-    imageView0.SetProperty(Actor::Property::POSITION_Y, -imageSize * 0.5f);
+    imageView0.SetProperty(positionProperty, -imageSize * 0.5f);
     window.Add(imageView0);
     Toolkit::ImageView imageView1 = CreateImageView(redGreen0);
     imageView1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
@@ -69,7 +72,7 @@ private:
     Toolkit::ImageView imageView2 = CreateImageView(IMAGE_PATH);
     imageView2.SetProperty(Actor::Property::SIZE, Vector2(imageSize, imageSize));
     imageView2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
-    imageView2.SetProperty(Actor::Property::POSITION_Y, imageSize * 0.5f);
+    imageView2.SetProperty(positionProperty, imageSize * 0.5f);
     window.Add(imageView2);
     Toolkit::ImageView imageView3 = CreateImageView(redGreen1);
     imageView3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
index e11ce15..0be89a7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -295,13 +295,14 @@ public:
   void CreateActor()
   {
     Window window = mApplication.GetWindow();
+    const auto windowSize = window.GetSize();
 
-    float quarterWindowWidth = window.GetSize().GetWidth() * 0.25f;
-    mActor                   = Actor::New();
+    const float quarterWindowSize = std::min(windowSize.GetWidth(), windowSize.GetHeight()) * 0.25f;
+    mActor                        = Actor::New();
     mActor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 1.0f, 0.6f, 1.0f));
     mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
     mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
-    mActor.SetProperty(Actor::Property::SIZE, Vector3(quarterWindowWidth, quarterWindowWidth, quarterWindowWidth));
+    mActor.SetProperty(Actor::Property::SIZE, Vector3(quarterWindowSize, quarterWindowSize, quarterWindowSize));
     mActor.AddRenderer(mRenderer);
     window.Add(mActor);
   }
index 89bd5c9..e09d3f3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -196,13 +196,14 @@ public:
   void CreateActor()
   {
     Window window = mApplication.GetWindow();
+    const auto windowSize = window.GetSize();
 
-    float quarterWindowWidth = window.GetSize().GetWidth() * 0.25f;
-    mActor                   = Actor::New();
+    float quarterWindowSize = std::min(windowSize.GetWidth(), windowSize.GetHeight()) * 0.25f;
+    mActor                  = Actor::New();
     mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
     mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
     mActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f));
-    mActor.SetProperty(Actor::Property::SIZE, Vector3(quarterWindowWidth, quarterWindowWidth, quarterWindowWidth));
+    mActor.SetProperty(Actor::Property::SIZE, Vector3(quarterWindowSize, quarterWindowSize, quarterWindowSize));
     mActor.AddRenderer(mRenderer);
     window.Add(mActor);
   }
index 32d323d..6e6299a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -218,13 +218,14 @@ public:
   void CreateActor()
   {
     Window window = mApplication.GetWindow();
+    const auto windowSize = window.GetSize();
 
-    float quarterWindowWidth = window.GetSize().GetWidth() * 0.25f;
-    mActor                   = Actor::New();
+    float quarterWindowSize = std::min(windowSize.GetWidth(), windowSize.GetHeight()) * 0.25f;
+    mActor                  = Actor::New();
     mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
     mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
     mActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f));
-    mActor.SetProperty(Actor::Property::SIZE, Vector3(quarterWindowWidth, quarterWindowWidth, quarterWindowWidth));
+    mActor.SetProperty(Actor::Property::SIZE, Vector3(quarterWindowSize, quarterWindowSize, quarterWindowSize));
     mActor.AddRenderer(mRenderer);
     window.Add(mActor);
   }
index f04d074..bc2765c 100644 (file)
@@ -207,7 +207,8 @@ public:
     mContainer = Control::New();
     mContainer.SetProperty(Dali::Actor::Property::NAME, "Container");
     mContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
-    mLayoutSize = Vector2(mWindowSize.width * 0.6f, mWindowSize.width * 0.6f);
+    auto size = std::min(mWindowSize.width, mWindowSize.height) * 0.6f;
+    mLayoutSize = Vector2(size, size);
     mContainer.SetProperty(Actor::Property::SIZE, mLayoutSize);
     window.Add(mContainer);