Commit b90419f6915253b19e0b8387a1da4e98aadf3964

Authored by Anton Obzhirov
1 parent f20d329f

Add LinearLayout weigth usage in LinearExample.

Change-Id: I7b0d3f3af5d8ff49f44e5c01b8ee2dcc966f93ec
examples/layouting/linear-example.cpp
@@ -42,6 +42,9 @@ const char* ROTATE_CLOCKWISE_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-reset-selected @@ -42,6 +42,9 @@ const char* ROTATE_CLOCKWISE_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-reset-selected
42 const char* ALIGN_IMAGE( DEMO_IMAGE_DIR "icon-replace.png" ); 42 const char* ALIGN_IMAGE( DEMO_IMAGE_DIR "icon-replace.png" );
43 const char* ALIGN_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-replace-selected.png" ); 43 const char* ALIGN_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-replace-selected.png" );
44 44
  45 +const char* WEIGHT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-grid.png" );
  46 +const char* WEIGHT_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-grid-selected.png" );
  47 +
45 // Child image filenames 48 // Child image filenames
46 const char* IMAGE_PATH[] = { 49 const char* IMAGE_PATH[] = {
47 DEMO_IMAGE_DIR "application-icon-101.png", 50 DEMO_IMAGE_DIR "application-icon-101.png",
@@ -61,8 +64,8 @@ void CreateChildImageView( ImageView& imageView, const char* filename, Size size @@ -61,8 +64,8 @@ void CreateChildImageView( ImageView& imageView, const char* filename, Size size
61 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename; 64 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename;
62 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width; 65 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
63 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height; 66 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height;
64 - imageView.SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );  
65 - imageView.SetName("ImageView"); 67 + imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imagePropertyMap );
  68 + imageView.SetName( "ImageView" );
66 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT ); 69 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
67 imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); 70 imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
68 } 71 }
@@ -74,7 +77,8 @@ namespace Demo @@ -74,7 +77,8 @@ namespace Demo
74 77
75 LinearExample::LinearExample() 78 LinearExample::LinearExample()
76 : Example( TITLE ), 79 : Example( TITLE ),
77 - mLTRDirection(true) 80 + mLTRDirection(true),
  81 + mImagesWeighted (false )
78 { 82 {
79 } 83 }
80 84
@@ -86,30 +90,38 @@ void LinearExample::Create() @@ -86,30 +90,38 @@ void LinearExample::Create()
86 mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE ); 90 mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE );
87 mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE ); 91 mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE );
88 mDirectionButton.ClickedSignal().Connect( this, &LinearExample::OnDirectionClicked ); 92 mDirectionButton.ClickedSignal().Connect( this, &LinearExample::OnDirectionClicked );
89 - mDirectionButton.SetParentOrigin( Vector3(0.33f, 1.0f, 0.5f ) ); 93 + mDirectionButton.SetParentOrigin( Vector3( 0.2f, 1.0f, 0.5f ) );
90 mDirectionButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); 94 mDirectionButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
91 - mDirectionButton.SetSize(75, 75); 95 + mDirectionButton.SetSize( 75, 75 );
92 stage.Add( mDirectionButton ); 96 stage.Add( mDirectionButton );
93 97
94 - mRotateButton = PushButton::New();  
95 - mRotateButton.SetProperty( PushButton::Property::UNSELECTED_ICON, ROTATE_CLOCKWISE_IMAGE );  
96 - mRotateButton.SetProperty( PushButton::Property::SELECTED_ICON, ROTATE_CLOCKWISE_SELECTED_IMAGE );  
97 - mRotateButton.ClickedSignal().Connect( this, &LinearExample::OnRotateClicked );  
98 - mRotateButton.SetParentOrigin( Vector3(0.66f, 1.0f, 0.5f ));  
99 - mRotateButton.SetAnchorPoint( Vector3(0.5f, 1.0f, 0.5f));  
100 - mRotateButton.SetSize(75, 75);  
101 - stage.Add( mRotateButton );  
102 -  
103 mAlignmentButton = PushButton::New(); 98 mAlignmentButton = PushButton::New();
104 mAlignmentButton.SetProperty( PushButton::Property::UNSELECTED_ICON, ALIGN_IMAGE ); 99 mAlignmentButton.SetProperty( PushButton::Property::UNSELECTED_ICON, ALIGN_IMAGE );
105 mAlignmentButton.SetProperty( PushButton::Property::SELECTED_ICON, ALIGN_SELECTED_IMAGE ); 100 mAlignmentButton.SetProperty( PushButton::Property::SELECTED_ICON, ALIGN_SELECTED_IMAGE );
106 mAlignmentButton.ClickedSignal().Connect( this, &LinearExample::OnAlignmentClicked ); 101 mAlignmentButton.ClickedSignal().Connect( this, &LinearExample::OnAlignmentClicked );
107 - mAlignmentButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); 102 + mAlignmentButton.SetParentOrigin( Vector3( 0.4f, 1.0f, 0.5f ) );
108 mAlignmentButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); 103 mAlignmentButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
109 - mAlignmentButton.SetSize(75, 75);  
110 - 104 + mAlignmentButton.SetSize( 75, 75 );
111 stage.Add( mAlignmentButton ); 105 stage.Add( mAlignmentButton );
112 106
  107 + mWeightButton = Toolkit::PushButton::New();
  108 + mWeightButton.SetProperty( PushButton::Property::UNSELECTED_ICON, WEIGHT_IMAGE );
  109 + mWeightButton.SetProperty( PushButton::Property::SELECTED_ICON, WEIGHT_SELECTED_IMAGE );
  110 + mWeightButton.ClickedSignal().Connect( this, &LinearExample::OnWeightClicked );
  111 + mWeightButton.SetParentOrigin( Vector3( 0.6f, 1.0f, 0.5f ) );
  112 + mWeightButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  113 + mWeightButton.SetSize( 75, 75 );
  114 + stage.Add( mWeightButton );
  115 +
  116 + mRotateButton = PushButton::New();
  117 + mRotateButton.SetProperty( PushButton::Property::UNSELECTED_ICON, ROTATE_CLOCKWISE_IMAGE );
  118 + mRotateButton.SetProperty( PushButton::Property::SELECTED_ICON, ROTATE_CLOCKWISE_SELECTED_IMAGE );
  119 + mRotateButton.ClickedSignal().Connect( this, &LinearExample::OnRotateClicked );
  120 + mRotateButton.SetParentOrigin( Vector3( 0.8f, 1.0f, 0.5f ) );
  121 + mRotateButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  122 + mRotateButton.SetSize( 75, 75 );
  123 + stage.Add( mRotateButton );
  124 +
113 // Create a linear layout 125 // Create a linear layout
114 mLinearContainer = Control::New(); 126 mLinearContainer = Control::New();
115 auto layout = LinearLayout::New(); 127 auto layout = LinearLayout::New();
@@ -129,8 +141,9 @@ void LinearExample::Create() @@ -129,8 +141,9 @@ void LinearExample::Create()
129 for( unsigned int x = 0; x < NUMBER_OF_RESOURCES; ++x ) 141 for( unsigned int x = 0; x < NUMBER_OF_RESOURCES; ++x )
130 { 142 {
131 Toolkit::ImageView imageView; 143 Toolkit::ImageView imageView;
132 - CreateChildImageView( imageView, IMAGE_PATH[ x ], Size(100.0f, 100.0f) ); 144 + CreateChildImageView( imageView, IMAGE_PATH[ x ], Size( 100.0f, 100.0f ) );
133 mLinearContainer.Add( imageView ); 145 mLinearContainer.Add( imageView );
  146 + mImages.push_back( imageView );
134 } 147 }
135 } 148 }
136 149
@@ -140,8 +153,9 @@ void LinearExample::Remove() @@ -140,8 +153,9 @@ void LinearExample::Remove()
140 if ( mLinearContainer ) 153 if ( mLinearContainer )
141 { 154 {
142 UnparentAndReset( mDirectionButton ); 155 UnparentAndReset( mDirectionButton );
143 - UnparentAndReset( mRotateButton );  
144 UnparentAndReset( mAlignmentButton ); 156 UnparentAndReset( mAlignmentButton );
  157 + UnparentAndReset( mWeightButton );
  158 + UnparentAndReset( mRotateButton );
145 UnparentAndReset( mLinearContainer); 159 UnparentAndReset( mLinearContainer);
146 } 160 }
147 } 161 }
@@ -213,4 +227,25 @@ bool LinearExample::OnAlignmentClicked( Button button ) @@ -213,4 +227,25 @@ bool LinearExample::OnAlignmentClicked( Button button )
213 return true; 227 return true;
214 } 228 }
215 229
  230 +bool LinearExample::OnWeightClicked( Button button )
  231 +{
  232 + if( !mImagesWeighted )
  233 + {
  234 + for( auto&& iter : mImages )
  235 + {
  236 + iter.SetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT, 0.25f );
  237 + }
  238 + }
  239 + else
  240 + {
  241 + for( auto&& iter : mImages )
  242 + {
  243 + iter.SetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT, 0.0f );
  244 + }
  245 + }
  246 +
  247 + mImagesWeighted = !mImagesWeighted;
  248 + return true;
  249 +}
  250 +
216 } // namespace Demo 251 } // namespace Demo
examples/layouting/linear-example.h
@@ -56,12 +56,18 @@ private: @@ -56,12 +56,18 @@ private:
56 // Cycles through alignment options 56 // Cycles through alignment options
57 bool OnAlignmentClicked( Button button ); 57 bool OnAlignmentClicked( Button button );
58 58
  59 + // Justifies linear layout children using weight property
  60 + bool OnWeightClicked( Button button );
  61 +
59 private: 62 private:
60 PushButton mDirectionButton; 63 PushButton mDirectionButton;
61 - PushButton mRotateButton;  
62 PushButton mAlignmentButton; 64 PushButton mAlignmentButton;
  65 + PushButton mWeightButton;
  66 + PushButton mRotateButton;
  67 + std::vector< Toolkit::ImageView > mImages;
63 Control mLinearContainer; 68 Control mLinearContainer;
64 bool mLTRDirection; 69 bool mLTRDirection;
  70 + bool mImagesWeighted;
65 }; // class LinearContainer 71 }; // class LinearContainer
66 72
67 } // namespace Demo 73 } // namespace Demo