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 42 const char* ALIGN_IMAGE( DEMO_IMAGE_DIR "icon-replace.png" );
43 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 48 // Child image filenames
46 49 const char* IMAGE_PATH[] = {
47 50 DEMO_IMAGE_DIR "application-icon-101.png",
... ... @@ -61,8 +64,8 @@ void CreateChildImageView( ImageView& imageView, const char* filename, Size size
61 64 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename;
62 65 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
63 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 69 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
67 70 imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
68 71 }
... ... @@ -74,7 +77,8 @@ namespace Demo
74 77  
75 78 LinearExample::LinearExample()
76 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 90 mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE );
87 91 mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE );
88 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 94 mDirectionButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
91   - mDirectionButton.SetSize(75, 75);
  95 + mDirectionButton.SetSize( 75, 75 );
92 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 98 mAlignmentButton = PushButton::New();
104 99 mAlignmentButton.SetProperty( PushButton::Property::UNSELECTED_ICON, ALIGN_IMAGE );
105 100 mAlignmentButton.SetProperty( PushButton::Property::SELECTED_ICON, ALIGN_SELECTED_IMAGE );
106 101 mAlignmentButton.ClickedSignal().Connect( this, &LinearExample::OnAlignmentClicked );
107   - mAlignmentButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  102 + mAlignmentButton.SetParentOrigin( Vector3( 0.4f, 1.0f, 0.5f ) );
108 103 mAlignmentButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
109   - mAlignmentButton.SetSize(75, 75);
110   -
  104 + mAlignmentButton.SetSize( 75, 75 );
111 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 125 // Create a linear layout
114 126 mLinearContainer = Control::New();
115 127 auto layout = LinearLayout::New();
... ... @@ -129,8 +141,9 @@ void LinearExample::Create()
129 141 for( unsigned int x = 0; x < NUMBER_OF_RESOURCES; ++x )
130 142 {
131 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 145 mLinearContainer.Add( imageView );
  146 + mImages.push_back( imageView );
134 147 }
135 148 }
136 149  
... ... @@ -140,8 +153,9 @@ void LinearExample::Remove()
140 153 if ( mLinearContainer )
141 154 {
142 155 UnparentAndReset( mDirectionButton );
143   - UnparentAndReset( mRotateButton );
144 156 UnparentAndReset( mAlignmentButton );
  157 + UnparentAndReset( mWeightButton );
  158 + UnparentAndReset( mRotateButton );
145 159 UnparentAndReset( mLinearContainer);
146 160 }
147 161 }
... ... @@ -213,4 +227,25 @@ bool LinearExample::OnAlignmentClicked( Button button )
213 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 251 } // namespace Demo
... ...
examples/layouting/linear-example.h
... ... @@ -56,12 +56,18 @@ private:
56 56 // Cycles through alignment options
57 57 bool OnAlignmentClicked( Button button );
58 58  
  59 + // Justifies linear layout children using weight property
  60 + bool OnWeightClicked( Button button );
  61 +
59 62 private:
60 63 PushButton mDirectionButton;
61   - PushButton mRotateButton;
62 64 PushButton mAlignmentButton;
  65 + PushButton mWeightButton;
  66 + PushButton mRotateButton;
  67 + std::vector< Toolkit::ImageView > mImages;
63 68 Control mLinearContainer;
64 69 bool mLTRDirection;
  70 + bool mImagesWeighted;
65 71 }; // class LinearContainer
66 72  
67 73 } // namespace Demo
... ...