Commit 794a38e615c95caf64acf00acd8eeafd85b7f73b
1 parent
cfe02c3a
Add alignment button in LinearExample.
Change-Id: I1a1005f16497d57fe1df817b8d53e3d6fc81d75b
Showing
2 changed files
with
53 additions
and
1 deletions
examples/layouting/linear-example.cpp
| ... | ... | @@ -39,6 +39,9 @@ const char* RTL_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-reverse-selected.png" ); |
| 39 | 39 | const char* ROTATE_CLOCKWISE_IMAGE( DEMO_IMAGE_DIR "icon-reset.png" ); |
| 40 | 40 | const char* ROTATE_CLOCKWISE_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-reset-selected.png" ); |
| 41 | 41 | |
| 42 | +const char* ALIGN_IMAGE( DEMO_IMAGE_DIR "icon-replace.png" ); | |
| 43 | +const char* ALIGN_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-replace-selected.png" ); | |
| 44 | + | |
| 42 | 45 | // Child image filenames |
| 43 | 46 | const char* IMAGE_PATH[] = { |
| 44 | 47 | DEMO_IMAGE_DIR "application-icon-101.png", |
| ... | ... | @@ -97,11 +100,22 @@ void LinearExample::Create() |
| 97 | 100 | mRotateButton.SetSize(75, 75); |
| 98 | 101 | stage.Add( mRotateButton ); |
| 99 | 102 | |
| 103 | + mAlignmentButton = PushButton::New(); | |
| 104 | + mAlignmentButton.SetProperty( PushButton::Property::UNSELECTED_ICON, ALIGN_IMAGE ); | |
| 105 | + mAlignmentButton.SetProperty( PushButton::Property::SELECTED_ICON, ALIGN_SELECTED_IMAGE ); | |
| 106 | + mAlignmentButton.ClickedSignal().Connect( this, &LinearExample::OnAlignmentClicked ); | |
| 107 | + mAlignmentButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | |
| 108 | + mAlignmentButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); | |
| 109 | + mAlignmentButton.SetSize(75, 75); | |
| 110 | + | |
| 111 | + stage.Add( mAlignmentButton ); | |
| 112 | + | |
| 100 | 113 | // Create a linear layout |
| 101 | 114 | mLinearContainer = Control::New(); |
| 102 | 115 | auto layout = LinearLayout::New(); |
| 103 | 116 | layout.SetAnimateLayout(true); |
| 104 | - layout.SetOrientation( LinearLayout::Orientation::VERTICAL ); | |
| 117 | + layout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); | |
| 118 | + layout.SetAlignment( LinearLayout::Alignment::CENTER_VERTICAL ); | |
| 105 | 119 | DevelControl::SetLayout( mLinearContainer, layout ); |
| 106 | 120 | |
| 107 | 121 | mLinearContainer.SetParentOrigin( ParentOrigin::CENTER ); |
| ... | ... | @@ -127,6 +141,7 @@ void LinearExample::Remove() |
| 127 | 141 | { |
| 128 | 142 | UnparentAndReset( mDirectionButton ); |
| 129 | 143 | UnparentAndReset( mRotateButton ); |
| 144 | + UnparentAndReset( mAlignmentButton ); | |
| 130 | 145 | UnparentAndReset( mLinearContainer); |
| 131 | 146 | } |
| 132 | 147 | } |
| ... | ... | @@ -134,6 +149,8 @@ void LinearExample::Remove() |
| 134 | 149 | // Mirror items in layout |
| 135 | 150 | bool LinearExample::OnDirectionClicked( Button button ) |
| 136 | 151 | { |
| 152 | + auto layout = LinearLayout::DownCast( DevelControl::GetLayout( mLinearContainer ) ); | |
| 153 | + layout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); | |
| 137 | 154 | if( !mLTRDirection ) |
| 138 | 155 | { |
| 139 | 156 | mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, LTR_IMAGE ); |
| ... | ... | @@ -157,10 +174,41 @@ bool LinearExample::OnRotateClicked( Button button ) |
| 157 | 174 | if( layout.GetOrientation() == LinearLayout::Orientation::VERTICAL ) |
| 158 | 175 | { |
| 159 | 176 | layout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); |
| 177 | + layout.SetAlignment(LinearLayout::Alignment::CENTER_VERTICAL ); | |
| 160 | 178 | } |
| 161 | 179 | else |
| 162 | 180 | { |
| 163 | 181 | layout.SetOrientation( LinearLayout::Orientation::VERTICAL ); |
| 182 | + layout.SetAlignment( LinearLayout::Alignment::CENTER_HORIZONTAL ); | |
| 183 | + } | |
| 184 | + return true; | |
| 185 | +} | |
| 186 | + | |
| 187 | +bool LinearExample::OnAlignmentClicked( Button button ) | |
| 188 | +{ | |
| 189 | + auto layout = LinearLayout::DownCast( DevelControl::GetLayout( mLinearContainer ) ); | |
| 190 | + if ( layout.GetAlignment() == LinearLayout::Alignment::CENTER_VERTICAL ) { | |
| 191 | + layout.SetAlignment( LinearLayout::Alignment::BEGIN ); | |
| 192 | + } | |
| 193 | + else if ( layout.GetAlignment() == LinearLayout::Alignment::BEGIN ) | |
| 194 | + { | |
| 195 | + layout.SetAlignment( LinearLayout::Alignment::END ); | |
| 196 | + } | |
| 197 | + else if ( layout.GetAlignment() == LinearLayout::Alignment::END ) | |
| 198 | + { | |
| 199 | + layout.SetAlignment( LinearLayout::Alignment::CENTER_HORIZONTAL); | |
| 200 | + } | |
| 201 | + else if ( layout.GetAlignment() == LinearLayout::Alignment::CENTER_HORIZONTAL ) | |
| 202 | + { | |
| 203 | + layout.SetAlignment( LinearLayout::Alignment::TOP ); | |
| 204 | + } | |
| 205 | + else if ( layout.GetAlignment() == LinearLayout::Alignment::TOP ) | |
| 206 | + { | |
| 207 | + layout.SetAlignment( LinearLayout::Alignment::BOTTOM ); | |
| 208 | + } | |
| 209 | + else if ( layout.GetAlignment() == LinearLayout::Alignment::BOTTOM ) | |
| 210 | + { | |
| 211 | + layout.SetAlignment( LinearLayout::Alignment::CENTER_VERTICAL ); | |
| 164 | 212 | } |
| 165 | 213 | return true; |
| 166 | 214 | } | ... | ... |
examples/layouting/linear-example.h
| ... | ... | @@ -53,9 +53,13 @@ private: |
| 53 | 53 | // Alternates the linear layout from horizontal to vertical |
| 54 | 54 | bool OnRotateClicked( Button button ); |
| 55 | 55 | |
| 56 | + // Cycles through alignment options | |
| 57 | + bool OnAlignmentClicked( Button button ); | |
| 58 | + | |
| 56 | 59 | private: |
| 57 | 60 | PushButton mDirectionButton; |
| 58 | 61 | PushButton mRotateButton; |
| 62 | + PushButton mAlignmentButton; | |
| 59 | 63 | Control mLinearContainer; |
| 60 | 64 | bool mLTRDirection; |
| 61 | 65 | }; // class LinearContainer | ... | ... |