Commit 03175ecc2e82d4845f84c9033e00d09636576538
1 parent
ecd5edf4
Minor demo improvements.
*The primitive shapes demo has had the buttons scaled down slightly to fit on two lines. *The text editor demo has had a label added to the color change button, which has itself received a border to highlight the less-visible colours. Change-Id: I16a69bd381ef0c8c980c0c3681cc47117b2d2786
Showing
8 changed files
with
39 additions
and
16 deletions
examples/text-editor/text-editor-example.cpp
| ... | ... | @@ -40,7 +40,7 @@ const float TOOLBAR_BUTTON_PERCENTAGE = 0.1f; ///< The but |
| 40 | 40 | const float TOOLBAR_TITLE_PERCENTAGE = 0.7f; ///< The title's width as a percentage of the toolbar's width. |
| 41 | 41 | const float TOOLBAR_HEIGHT_PERCENTAGE = 0.05f; ///< The toolbar's height as a percentage of the stage's height. |
| 42 | 42 | const float TOOLBAR_PADDING = 4.f; ///< The padding in pixels. |
| 43 | -const Vector3 BUTTON_PERCENTAGE( 0.8f, 0.8f, 1.f ); ///< The button's width as a percentage of the space for the buttons in the toolbar. | |
| 43 | +const float BUTTON_PERCENTAGE = 0.8f; ///< The button's height as a percentage of the space for the buttons in the toolbar. | |
| 44 | 44 | const Vector3 TEXT_EDITOR_RELATIVE_SIZE( 1.f, 0.45f, 1.0f ); ///< The size of the text editor as a percentage of the stage's size. |
| 45 | 45 | const Vector4 TEXT_EDITOR_BACKGROUND_COLOR( 1.f, 1.f, 1.f, 0.15f ); ///< The background color of the text editor. |
| 46 | 46 | |
| ... | ... | @@ -108,17 +108,46 @@ public: |
| 108 | 108 | "", |
| 109 | 109 | viewStyle ); |
| 110 | 110 | |
| 111 | + // Create a label for the color selection button. | |
| 112 | + // The button will be a child of this, so as to be placed next to it. | |
| 113 | + TextLabel colorLabel = TextLabel::New( "Text Color: " ); | |
| 114 | + colorLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); | |
| 115 | + colorLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); | |
| 116 | + colorLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); | |
| 117 | + | |
| 118 | + // Create a container for the color button, to layout the drop-down list below it. | |
| 119 | + mColorContainer = Control::New(); | |
| 120 | + mColorContainer.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH ); | |
| 121 | + mColorContainer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT ); | |
| 122 | + mColorContainer.SetSizeModeFactor( Vector3( 0.0f, BUTTON_PERCENTAGE, 0.0f ) ); | |
| 123 | + | |
| 124 | + // Place to right of parent. | |
| 125 | + mColorContainer.SetParentOrigin( ParentOrigin::CENTER_RIGHT ); | |
| 126 | + mColorContainer.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); | |
| 127 | + colorLabel.Add( mColorContainer ); | |
| 128 | + | |
| 129 | + // Add border to highlight harder-to-see colors. | |
| 130 | + // We use a color rather than border visual as the container will always be behind the button. | |
| 131 | + Property::Map colorMap; | |
| 132 | + colorMap.Insert( Visual::Property::TYPE, Visual::COLOR); | |
| 133 | + colorMap.Insert( ColorVisual::Property::MIX_COLOR, Color::BLACK ); | |
| 134 | + mColorContainer.SetProperty( Control::Property::BACKGROUND, colorMap ); | |
| 135 | + | |
| 111 | 136 | // Create a 'select color' button. |
| 112 | 137 | mColorButtonOption = Toolkit::PushButton::New(); |
| 113 | 138 | mColorButtonOption.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); |
| 114 | - mColorButtonOption.SetSizeModeFactor( BUTTON_PERCENTAGE ); | |
| 139 | + mColorButtonOption.SetSizeModeFactor( Vector3( 0.9f, 0.9f, 0.0f ) ); // Smaller than container to show border. | |
| 140 | + mColorButtonOption.SetParentOrigin( ParentOrigin::CENTER ); | |
| 141 | + mColorButtonOption.SetAnchorPoint( AnchorPoint::CENTER ); | |
| 115 | 142 | |
| 116 | 143 | mColorButtonOption.SetProperty( Button::Property::UNSELECTED_COLOR, Color::BLACK ); |
| 117 | 144 | mColorButtonOption.SetProperty( Button::Property::SELECTED_COLOR, Color::BLACK ); |
| 118 | 145 | |
| 119 | 146 | mColorButtonOption.ClickedSignal().Connect( this, &TextEditorExample::OnChangeColorButtonClicked ); |
| 147 | + mColorContainer.Add( mColorButtonOption ); | |
| 120 | 148 | |
| 121 | - mToolBar.AddControl( mColorButtonOption, viewStyle.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); | |
| 149 | + //Add label to toolbar, which will also add the color button next to it. | |
| 150 | + mToolBar.AddControl( colorLabel, viewStyle.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); | |
| 122 | 151 | |
| 123 | 152 | // Create the text editor. |
| 124 | 153 | mEditor = TextEditor::New(); |
| ... | ... | @@ -159,21 +188,14 @@ public: |
| 159 | 188 | void CreateButtonContainer() |
| 160 | 189 | { |
| 161 | 190 | mButtonContainer = Toolkit::TableView::New( NUMBER_OF_COLORS, 1u ); |
| 162 | - mButtonContainer.SetParentOrigin( ParentOrigin::TOP_LEFT ); | |
| 163 | - mButtonContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | |
| 164 | - | |
| 165 | - Stage stage = Stage::GetCurrent(); | |
| 166 | - const Vector2 stageSize = stage.GetSize(); | |
| 167 | - const float toolBarHeight = TOOLBAR_HEIGHT_PERCENTAGE * stageSize.height; | |
| 168 | - mButtonContainer.SetPosition( TOOLBAR_PADDING, 2.f * TOOLBAR_PADDING + toolBarHeight, 0.f ); | |
| 169 | - | |
| 170 | 191 | mButtonContainer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); |
| 192 | + mButtonContainer.SetSizeModeFactor( Vector3( 1.0f, NUMBER_OF_COLORS, 1.0f ) ); | |
| 171 | 193 | |
| 172 | - const Vector3 containerPercentage( 0.8f * TOOLBAR_BUTTON_PERCENTAGE, NUMBER_OF_COLORS, 1.f ); | |
| 173 | - mButtonContainer.SetSizeModeFactor( containerPercentage ); | |
| 174 | - | |
| 175 | - Layer toolbarLayer = mToolBar.GetLayer(); | |
| 176 | - toolbarLayer.Add( mButtonContainer ); | |
| 194 | + // Place below color selection button. | |
| 195 | + mButtonContainer.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | |
| 196 | + mButtonContainer.SetAnchorPoint( AnchorPoint::TOP_CENTER ); | |
| 197 | + mButtonContainer.SetPosition( 0.0f, 2.f * TOOLBAR_PADDING, 0.f ); | |
| 198 | + mColorContainer.Add( mButtonContainer ); | |
| 177 | 199 | |
| 178 | 200 | const Vector3 buttonPercentage( 1.f, 0.8f / static_cast<float>( NUMBER_OF_COLORS ), 1.f ); |
| 179 | 201 | for( unsigned int index = 0u; index < NUMBER_OF_COLORS; ++index ) |
| ... | ... | @@ -260,6 +282,7 @@ private: |
| 260 | 282 | Toolkit::Control mView; |
| 261 | 283 | Toolkit::ToolBar mToolBar; |
| 262 | 284 | Toolkit::TextEditor mEditor; |
| 285 | + Toolkit::Control mColorContainer; | |
| 263 | 286 | Toolkit::PushButton mColorButtonOption; |
| 264 | 287 | Toolkit::TableView mButtonContainer; |
| 265 | 288 | }; | ... | ... |
resources/images/bevelled-cube-button.png
resources/images/cone-button.png
resources/images/conical-frustrum-button.png
resources/images/cube-button.png
resources/images/cylinder-button.png
resources/images/octahedron-button.png
resources/images/sphere-button.png