Commit 037f576518a62e16e998d4d9d3b86cb929f12cd0

Authored by agnelo vaz
Committed by Adeel Kazmi
1 parent c66c70d8

Extending Layout tester demo

Pressing "Change layout" will show another test example.

Pressing Change button toggles padding on/off for second ImageView
First Image View has a margin applied.

Issues
TogglePadding button is not unparented from stage

Change-Id: I728071af85540df0a8fd27b7e78349e4f2370d2b
examples/layouting/layouting-examples.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2018 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 <string>
  19 +#include "shared/view.h"
  20 +#include "linear-example.h"
  21 +#include "padding-example.h"
  22 +#include <dali/dali.h>
  23 +#include <dali-toolkit/dali-toolkit.h>
  24 +#include <dali-toolkit/devel-api/controls/control-devel.h>
  25 +
  26 +using namespace Dali;
  27 +using namespace Dali::Toolkit;
  28 +
  29 +namespace
  30 +{
  31 +
  32 +const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" );
  33 +const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
  34 +
  35 +const char* APPLICATION_TITLE( "Layout tester" );
  36 +
  37 +} // namespace
  38 +
  39 +class LayoutingExample: public ConnectionTracker
  40 +{
  41 + public:
  42 +
  43 + LayoutingExample( Application& application )
  44 + : mApplication( application ),
  45 + mLinearExample(),
  46 + mPaddedExample(),
  47 + mLayoutIndex( 0 )
  48 + {
  49 + // Connect to the Application's Init signal
  50 + mApplication.InitSignal().Connect( this, &LayoutingExample::Create );
  51 + }
  52 +
  53 + ~LayoutingExample()
  54 + {
  55 + // Nothing to do here
  56 + }
  57 +
  58 + void Create( Application& application )
  59 + {
  60 + // The Init signal is received once (only) during the Application lifetime
  61 +
  62 + auto stage = Stage::GetCurrent();
  63 +
  64 + auto bg = ImageView::New( BACKGROUND_IMAGE );
  65 + bg.SetParentOrigin( ParentOrigin::CENTER );
  66 + stage.Add( bg );
  67 + auto toolbar = ImageView::New( TOOLBAR_IMAGE );
  68 + toolbar.SetParentOrigin( ParentOrigin::TOP_CENTER );
  69 + toolbar.SetAnchorPoint( AnchorPoint::TOP_CENTER );
  70 + toolbar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
  71 + toolbar.SetProperty( Actor::Property::SIZE_HEIGHT, 50.0f);
  72 +
  73 + stage.Add( toolbar );
  74 +
  75 + auto title = TextLabel::New( APPLICATION_TITLE );
  76 + title.SetParentOrigin( ParentOrigin::CENTER );
  77 + title.SetAnchorPoint( AnchorPoint::CENTER );
  78 + title.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
  79 + title.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::LEFT );
  80 + toolbar.Add( title );
  81 +
  82 + mNextLayout = PushButton::New();
  83 + mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "change layout");
  84 + mNextLayout.ClickedSignal().Connect( this, &LayoutingExample::ChangeLayout );
  85 + mNextLayout.SetParentOrigin( ParentOrigin::TOP_RIGHT );
  86 + mNextLayout.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
  87 + mNextLayout.SetSize(175, 50);
  88 + toolbar.Add( mNextLayout );
  89 +
  90 + mLinearExample.Demo::LinearExample::Create();
  91 + }
  92 +
  93 + bool ChangeLayout( Button button )
  94 + {
  95 + mLayoutIndex++;
  96 +
  97 + switch( mLayoutIndex )
  98 + {
  99 + case 1 :
  100 + {
  101 + mLinearExample.Remove();
  102 + mPaddedExample.Create();
  103 + break;
  104 + }
  105 + case 2 :
  106 + {
  107 + mPaddedExample.Remove();
  108 + mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "end of test");
  109 + mNextLayout.SetProperty( Toolkit::Button::Property::DISABLED, true );
  110 + break;
  111 + }
  112 + default :
  113 + {
  114 + break;
  115 + }
  116 + }
  117 +
  118 + return true;
  119 + }
  120 +
  121 +private:
  122 + /**
  123 + * Main key event handler
  124 + */
  125 + void OnKeyEvent(const KeyEvent& event)
  126 + {
  127 + if(event.state == KeyEvent::Down)
  128 + {
  129 + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
  130 + {
  131 + mApplication.Quit();
  132 + }
  133 + }
  134 + }
  135 +
  136 +
  137 +private:
  138 + Application& mApplication;
  139 + Demo::LinearExample mLinearExample;
  140 + Demo::PaddingExample mPaddedExample;
  141 + PushButton mNextLayout;
  142 + unsigned int mLayoutIndex;
  143 +};
  144 +
  145 +int DALI_EXPORT_API main( int argc, char **argv )
  146 +{
  147 + Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
  148 + LayoutingExample test( application );
  149 + application.MainLoop();
  150 + return 0;
  151 +};
... ...
examples/layouting/layouting-example.cpp renamed to examples/layouting/linear-example.cpp
... ... @@ -16,9 +16,7 @@
16 16 */
17 17  
18 18 #include <string>
19   -#include "shared/view.h"
20   -#include <dali/dali.h>
21   -#include <dali-toolkit/dali-toolkit.h>
  19 +#include "linear-example.h"
22 20 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
23 21 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
24 22 #include <dali-toolkit/devel-api/controls/control-devel.h>
... ... @@ -31,9 +29,7 @@ using namespace Dali::Toolkit;
31 29 namespace
32 30 {
33 31  
34   -const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" );
35   -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
36   -
  32 +// Button file names
37 33 const char* LTR_IMAGE( DEMO_IMAGE_DIR "icon-play.png" );
38 34 const char* LTR_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-play-selected.png" );
39 35  
... ... @@ -43,180 +39,130 @@ const char* RTL_SELECTED_IMAGE( DEMO_IMAGE_DIR &quot;icon-reverse-selected.png&quot; );
43 39 const char* ROTATE_CLOCKWISE_IMAGE( DEMO_IMAGE_DIR "icon-reset.png" );
44 40 const char* ROTATE_CLOCKWISE_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-reset-selected.png" );
45 41  
46   -//const char* ROTATE_ANTICLOCKWISE_IMAGE( DEMO_IMAGE_DIR "icon-rotate-anticlockwise.png" );
47   -//const char* ROTATE_ANTICLOCKWISE_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-rotate-anticlockwise-selected.png" );
48   -
49   -
50   -const char* APPLICATION_TITLE( "Layout tester" );
51   -
  42 +// Child image filenames
52 43 const char* IMAGE_PATH[] = {
53 44 DEMO_IMAGE_DIR "application-icon-101.png",
54 45 DEMO_IMAGE_DIR "application-icon-102.png",
55 46 DEMO_IMAGE_DIR "application-icon-103.png",
56 47 DEMO_IMAGE_DIR "application-icon-104.png"
57 48 };
  49 +
58 50 const unsigned int NUMBER_OF_RESOURCES = sizeof(IMAGE_PATH) / sizeof(char*);
59 51  
  52 +// Helper function to create ImageViews with given filename and size.
  53 +void CreateChildImageView( ImageView& imageView, const char* filename, Size size )
  54 +{
  55 + imageView = ImageView::New();
  56 + Property::Map imagePropertyMap;
  57 + imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
  58 + imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename;
  59 + imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
  60 + imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height;
  61 + imageView.SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
  62 + imageView.SetName("ImageView");
  63 + imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
  64 + imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
  65 +}
  66 +
60 67 } // namespace
61 68  
62   -class LayoutingExample: public ConnectionTracker
  69 +namespace Demo
63 70 {
64   - public:
65 71  
66   - LayoutingExample( Application& application )
67   - : mApplication( application ),
68   - mDirection( false )
  72 +void LinearExample::Create()
  73 +{
  74 + // The Init signal is received once (only) during the Application lifetime
  75 + auto stage = Stage::GetCurrent();
  76 +
  77 + mDirectionButton = PushButton::New();
  78 + mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE );
  79 + mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE );
  80 + mDirectionButton.ClickedSignal().Connect( this, &LinearExample::OnDirectionClicked );
  81 + mDirectionButton.SetParentOrigin( Vector3(0.33f, 1.0f, 0.5f ) );
  82 + mDirectionButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  83 + mDirectionButton.SetSize(75, 75);
  84 + stage.Add( mDirectionButton );
  85 +
  86 + mRotateButton = PushButton::New();
  87 + mRotateButton.SetProperty( PushButton::Property::UNSELECTED_ICON, ROTATE_CLOCKWISE_IMAGE );
  88 + mRotateButton.SetProperty( PushButton::Property::SELECTED_ICON, ROTATE_CLOCKWISE_SELECTED_IMAGE );
  89 + mRotateButton.ClickedSignal().Connect( this, &LinearExample::OnRotateClicked );
  90 + mRotateButton.SetParentOrigin( Vector3(0.66f, 1.0f, 0.5f ));
  91 + mRotateButton.SetAnchorPoint( Vector3(0.5f, 1.0f, 0.5f));
  92 + mRotateButton.SetSize(75, 75);
  93 + stage.Add( mRotateButton );
  94 +
  95 + // Create a linear layout
  96 + mLinearContainer = Control::New();
  97 + mIsHorizontal = false;
  98 +
  99 + auto layout = VboxLayout::New();
  100 + layout.SetAnimateLayout(true);
  101 + DevelControl::SetLayout( mLinearContainer, layout );
  102 +
  103 + mLinearContainer.SetParentOrigin( ParentOrigin::CENTER );
  104 + mLinearContainer.SetAnchorPoint( AnchorPoint::CENTER );
  105 + mLinearContainer.SetName( "LinearExample" );
  106 + stage.Add( mLinearContainer );
  107 + mLinearContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
  108 + mLinearContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
  109 + mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT );
  110 +
  111 + for( unsigned int x = 0; x < NUMBER_OF_RESOURCES; ++x )
69 112 {
70   - // Connect to the Application's Init signal
71   - mApplication.InitSignal().Connect( this, &LayoutingExample::Create );
  113 + Toolkit::ImageView imageView;
  114 + CreateChildImageView( imageView, IMAGE_PATH[ x ], Size(100.0f, 100.0f) );
  115 + mLinearContainer.Add( imageView );
72 116 }
  117 +}
73 118  
74   - ~LayoutingExample()
  119 +// Remove controls added by this example from stage
  120 +void LinearExample::Remove()
  121 +{
  122 + if ( mLinearContainer )
75 123 {
76   - // Nothing to do here
  124 + UnparentAndReset( mDirectionButton );
  125 + UnparentAndReset( mRotateButton );
  126 + UnparentAndReset( mLinearContainer);
77 127 }
  128 +}
78 129  
79   - void Create( Application& application )
  130 +// Mirror items in layout
  131 +bool LinearExample::OnDirectionClicked( Button button )
  132 +{
  133 + if( mDirection )
80 134 {
81   - // The Init signal is received once (only) during the Application lifetime
82   - auto stage = Stage::GetCurrent();
83   -
84   - auto bg = ImageView::New( BACKGROUND_IMAGE );
85   - bg.SetParentOrigin( ParentOrigin::CENTER );
86   - stage.Add( bg );
87   - auto toolbar = ImageView::New( TOOLBAR_IMAGE );
88   - toolbar.SetParentOrigin( ParentOrigin::TOP_CENTER );
89   - toolbar.SetAnchorPoint( AnchorPoint::TOP_CENTER );
90   - toolbar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
91   - toolbar.SetProperty( Actor::Property::SIZE_HEIGHT, 50.0f);
92   -
93   - stage.Add( toolbar );
94   -
95   - auto title = TextLabel::New( APPLICATION_TITLE );
96   - title.SetParentOrigin( ParentOrigin::CENTER );
97   - title.SetAnchorPoint( AnchorPoint::CENTER );
98   - title.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
99   - title.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER );
100   - toolbar.Add( title );
101   -
102   - mDirectionButton = PushButton::New();
103   - mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE );
104   - mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE );
105   - mDirectionButton.ClickedSignal().Connect( this, &LayoutingExample::OnDirectionClicked );
106   - mDirectionButton.SetParentOrigin( Vector3(0.33f, 1.0f, 0.5f ) );
107   - mDirectionButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
108   - mDirectionButton.SetSize(75, 75);
109   - stage.Add( mDirectionButton );
110   -
111   - mRotateButton = PushButton::New();
112   - mRotateButton.SetProperty( PushButton::Property::UNSELECTED_ICON, ROTATE_CLOCKWISE_IMAGE );
113   - mRotateButton.SetProperty( PushButton::Property::SELECTED_ICON, ROTATE_CLOCKWISE_SELECTED_IMAGE );
114   - mRotateButton.ClickedSignal().Connect( this, &LayoutingExample::OnRotateClicked );
115   - mRotateButton.SetParentOrigin( Vector3(0.66f, 1.0f, 0.5f ));
116   - mRotateButton.SetAnchorPoint( Vector3(0.5f, 1.0f, 0.5f));
117   - mRotateButton.SetSize(75, 75);
118   - stage.Add( mRotateButton );
119   -
120   - // Create a hbox layout
121   - mLinearContainer = Control::New();
122   - mIsHorizontal = false;
123   -
124   - auto layout = VboxLayout::New();
125   - layout.SetAnimateLayout(true);
126   - DevelControl::SetLayout( mLinearContainer, layout );
127   -
128   - mLinearContainer.SetParentOrigin( ParentOrigin::CENTER );
129   - mLinearContainer.SetAnchorPoint( AnchorPoint::CENTER );
130   - mLinearContainer.SetName( "linearContainer" );
131   - stage.Add( mLinearContainer );
132   - mLinearContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
133   - mLinearContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
  135 + mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, LTR_IMAGE );
  136 + mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, LTR_SELECTED_IMAGE );
134 137 mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT );
135   -
136   - for( unsigned int x = 0; x < NUMBER_OF_RESOURCES; ++x )
137   - {
138   - mImageViews[x] = Toolkit::ImageView::New();
139   - Property::Map imagePropertyMap;
140   - imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
141   - imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = IMAGE_PATH[ x ];
142   - imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 100.0f;
143   - imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 100.0f;
144   -
145   - mImageViews[x].SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
146   - mImageViews[x].SetName("ImageView");
147   - mImageViews[x].SetAnchorPoint( AnchorPoint::TOP_LEFT );
148   - mImageViews[x].SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
149   - mLinearContainer.Add( mImageViews[x] );
150   - }
151   -
152   - Stage::GetCurrent().KeyEventSignal().Connect(this, &LayoutingExample::OnKeyEvent);
153 138 }
154   -
155   -private:
156   - /**
157   - * Main key event handler
158   - */
159   - void OnKeyEvent(const KeyEvent& event)
  139 + else
160 140 {
161   - if(event.state == KeyEvent::Down)
162   - {
163   - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
164   - {
165   - mApplication.Quit();
166   - }
167   - }
  141 + mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE );
  142 + mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE );
  143 + mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
168 144 }
  145 + mDirection = !mDirection;
  146 + return true;
  147 +}
169 148  
170   - bool OnDirectionClicked( Button button )
  149 +// Rotate layout by changing layout
  150 +bool LinearExample::OnRotateClicked( Button button )
  151 +{
  152 + mIsHorizontal = !mIsHorizontal;
  153 + if( mIsHorizontal )
171 154 {
172   - if( mDirection )
173   - {
174   - mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, LTR_IMAGE );
175   - mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, LTR_SELECTED_IMAGE );
176   - mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT );
177   - }
178   - else
179   - {
180   - mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE );
181   - mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE );
182   - mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
183   - }
184   - mDirection = !mDirection;
185   - return true;
  155 + auto hboxLayout = HboxLayout::New();
  156 + hboxLayout.SetAnimateLayout(true);
  157 + DevelControl::SetLayout( mLinearContainer, hboxLayout );
186 158 }
187   -
188   - bool OnRotateClicked( Button button )
  159 + else
189 160 {
190   - mIsHorizontal = !mIsHorizontal;
191   - if( mIsHorizontal )
192   - {
193   - auto hboxLayout = HboxLayout::New();
194   - hboxLayout.SetAnimateLayout(true);
195   - DevelControl::SetLayout( mLinearContainer, hboxLayout );
196   - }
197   - else
198   - {
199   - auto vboxLayout = VboxLayout::New();
200   - vboxLayout.SetAnimateLayout(true);
201   - DevelControl::SetLayout( mLinearContainer, vboxLayout );
202   - }
203   - return true;
  161 + auto vboxLayout = VboxLayout::New();
  162 + vboxLayout.SetAnimateLayout(true);
  163 + DevelControl::SetLayout( mLinearContainer, vboxLayout );
204 164 }
205   -
206   -private:
207   - Application& mApplication;
208   - Toolkit::ImageView mImageViews[ NUMBER_OF_RESOURCES ];
209   - PushButton mDirectionButton;
210   - PushButton mRotateButton;
211   - Control mLinearContainer;
212   - bool mDirection;
213   - bool mIsHorizontal = true;
214   -};
215   -
216   -int DALI_EXPORT_API main( int argc, char **argv )
217   -{
218   - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
219   - LayoutingExample test( application );
220   - application.MainLoop();
221   - return 0;
  165 + return true;
222 166 }
  167 +
  168 +} // namespace Demo
223 169 \ No newline at end of file
... ...
examples/layouting/linear-example.h 0 → 100644
  1 +#ifndef DALI_DEMO_LINEAR_EXAMPLE_H
  2 +#define DALI_DEMO_LINEAR_EXAMPLE_H
  3 +
  4 +/*
  5 + * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  6 + *
  7 + * Licensed under the Apache License, Version 2.0 (the "License");
  8 + * you may not use this file except in compliance with the License.
  9 + * You may obtain a copy of the License at
  10 + *
  11 + * http://www.apache.org/licenses/LICENSE-2.0
  12 + *
  13 + * Unless required by applicable law or agreed to in writing, software
  14 + * distributed under the License is distributed on an "AS IS" BASIS,
  15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16 + * See the License for the specific language governing permissions and
  17 + * limitations under the License.
  18 + *
  19 + */
  20 +
  21 +#include <dali/dali.h>
  22 +#include <dali-toolkit/dali-toolkit.h>
  23 +
  24 +using namespace Dali;
  25 +using namespace Dali::Toolkit;
  26 +
  27 +namespace Demo
  28 +{
  29 +
  30 +/**
  31 + * @file linear-example.hcpp
  32 + * @brief Example of a Linear Layout with mirror feature and
  33 + * tranisition from horizontal to vertical.
  34 + */
  35 +class LinearExample: public ConnectionTracker
  36 +{
  37 +
  38 +public:
  39 +
  40 + // Creates a Linear Layout Example and displays it.
  41 + void Create();
  42 +
  43 + // Remove and destroy this layout
  44 + void Remove();
  45 +
  46 +private:
  47 +
  48 + // Changes the direction of the items.
  49 + bool OnDirectionClicked( Button button );
  50 +
  51 + // Alternates the linear layout from horizontal to vertical
  52 + bool OnRotateClicked( Button button );
  53 +
  54 +private:
  55 + PushButton mDirectionButton;
  56 + PushButton mRotateButton;
  57 + Control mLinearContainer;
  58 + bool mDirection;
  59 + bool mIsHorizontal = true;
  60 +}; // class LinearContainer
  61 +
  62 +} // namespace Demo
  63 +
  64 +#endif //DALI_DEMO_LINEAR_CONTAINER_H
0 65 \ No newline at end of file
... ...
examples/layouting/padding-example.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 <string>
  19 +#include "padding-example.h"
  20 +#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
  21 +#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
  22 +#include <dali-toolkit/devel-api/controls/control-devel.h>
  23 +#include <dali-toolkit/devel-api/layouting/hbox-layout.h>
  24 +
  25 +using namespace Dali;
  26 +using namespace Dali::Toolkit;
  27 +
  28 +
  29 +namespace
  30 +{
  31 +
  32 +// Helper function to create ImageViews with given filename and size.
  33 +void CreateChildImageView( ImageView& imageView, const char* filename, Size size )
  34 +{
  35 + imageView = ImageView::New();
  36 + Property::Map imagePropertyMap;
  37 + imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
  38 + imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename;
  39 + imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
  40 + imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height;
  41 + imageView.SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
  42 + imageView.SetName("ImageView");
  43 + imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
  44 + imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
  45 +}
  46 +
  47 +}
  48 +
  49 +namespace Demo
  50 +{
  51 +
  52 +void PaddingExample::Create()
  53 +{
  54 + // The Init signal is received once (only) during the Application lifetime
  55 +
  56 + // Creates a default view with a default tool bar.
  57 + // The view is added to the stage.
  58 + auto stage = Stage::GetCurrent();
  59 + // Create a table view to show a pair of buttons above each image.
  60 + mHorizontalBox = Control::New();
  61 +
  62 + // Create HBoxLayout for this control.
  63 + auto hboxLayout = HboxLayout::New();
  64 + DevelControl::SetLayout( mHorizontalBox, hboxLayout );
  65 + mHorizontalBox.SetName("HBox");
  66 +
  67 + mHorizontalBox.SetAnchorPoint( AnchorPoint::CENTER );
  68 + mHorizontalBox.SetParentOrigin( ParentOrigin::CENTER );
  69 +
  70 + stage.Add( mHorizontalBox );
  71 +
  72 + for( unsigned int x = 0; x < NUMBER_OF_IMAGE_VIEWS; x++ )
  73 + {
  74 + mToggleButton = Toolkit::PushButton::New();
  75 + mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Toggle Padding on #2" );
  76 + mToggleButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  77 + mToggleButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  78 + mToggleButton.ClickedSignal().Connect( this, &Demo::PaddingExample::ChangePaddingClicked );
  79 + mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
  80 + mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
  81 +
  82 + stage.Add( mToggleButton );
  83 +
  84 + CreateChildImageView( mImageViews[x], DEMO_IMAGE_DIR "gallery-small-23.jpg" , Size(100.0f, 100.0f) );
  85 +
  86 + // Set Padding for second ImageView
  87 + if( 1 == x )
  88 + {
  89 + mImageViews[x].SetProperty(Toolkit::Control::Property::PADDING, Extents(10.0f,10.0f,5.0f, 5.0f));
  90 + }
  91 +
  92 + // Set margin for first ImageView
  93 + if( 0 == x )
  94 + {
  95 + mImageViews[x].SetProperty(Toolkit::Control::Property::MARGIN, Extents(10.0f,10.0f,0.0f, 0.0f));
  96 + }
  97 +
  98 + mHorizontalBox.Add( mImageViews[x] );
  99 +
  100 + mImageViewToggleStatus[ x ] = true;
  101 + }
  102 +}
  103 +
  104 +void PaddingExample::Remove()
  105 +{
  106 + UnparentAndReset( mToggleButton );
  107 + UnparentAndReset( mHorizontalBox );
  108 +}
  109 +
  110 +bool PaddingExample::ChangePaddingClicked( Toolkit::Button button )
  111 +{
  112 + if ( true == mImageViewToggleStatus[ 1 ] )
  113 + {
  114 + mImageViews[1].SetProperty(Toolkit::Control::Property::PADDING, Extents( .0f, .0f, .0f, .0f));
  115 + mImageViews[1].SetProperty(Actor::Property::COLOR_ALPHA, 0.5f);
  116 + mImageViewToggleStatus[ 1 ] = false;
  117 + }
  118 + else
  119 + {
  120 + mImageViews[1].SetProperty(Toolkit::Control::Property::PADDING, Extents( 10.0f, 10.0f, 5.0f, 5.0f));
  121 + mImageViews[1].SetProperty(Actor::Property::COLOR_ALPHA, 1.0f);
  122 + mImageViewToggleStatus[ 1 ] = true;
  123 + }
  124 +
  125 + return true;
  126 +}
  127 +
  128 +} // namespace Demo
0 129 \ No newline at end of file
... ...
examples/layouting/padding-example.h 0 → 100644
  1 +#ifndef DALI_DEMO_PADDING_EXAMPLE_H
  2 +#define DALI_DEMO_PADDING_EXAMPLE_H
  3 +
  4 +/*
  5 + * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  6 + *
  7 + * Licensed under the Apache License, Version 2.0 (the "License");
  8 + * you may not use this file except in compliance with the License.
  9 + * You may obtain a copy of the License at
  10 + *
  11 + * http://www.apache.org/licenses/LICENSE-2.0
  12 + *
  13 + * Unless required by applicable law or agreed to in writing, software
  14 + * distributed under the License is distributed on an "AS IS" BASIS,
  15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16 + * See the License for the specific language governing permissions and
  17 + * limitations under the License.
  18 + *
  19 + */
  20 +
  21 +#include <string>
  22 +#include <dali/dali.h>
  23 +#include <dali-toolkit/dali-toolkit.h>
  24 +
  25 +using namespace Dali;
  26 +using namespace Dali::Toolkit;
  27 +
  28 +namespace Demo
  29 +{
  30 +
  31 +/**
  32 + * @file padding-example.hcpp
  33 + * @brief Example of a Linear Layout with padding applied, enables updating of padding values for
  34 + * one of the children.
  35 + */
  36 +class PaddingExample: public ConnectionTracker
  37 +{
  38 +public:
  39 +
  40 + static const unsigned int NUMBER_OF_IMAGE_VIEWS = 3;
  41 +
  42 + // Create a Linear layout of ImagesViews, one with a Margin, One with padding.
  43 + void Create();
  44 +
  45 + // Remove created Layout
  46 + void Remove();
  47 +
  48 +private:
  49 +
  50 + // Change Paddding callback
  51 + bool ChangePaddingClicked( Toolkit::Button button );
  52 +
  53 +private:
  54 +
  55 + Toolkit::Control mHorizontalBox;
  56 + Toolkit::ImageView mImageViews[ NUMBER_OF_IMAGE_VIEWS ];
  57 + bool mImageViewToggleStatus[ NUMBER_OF_IMAGE_VIEWS ];
  58 + Toolkit::PushButton mToggleButton;
  59 +
  60 +};
  61 +
  62 +} // namespace Demo
  63 +
  64 +#endif // DALI_DEMO_PADDING_EXAMPLE_H
... ...