Commit 7f42b74b3ce34ea38d25620211abc55b64c94c7f
Committed by
Gerrit Code Review
Merge "TextView example." into tizen
Showing
5 changed files
with
213 additions
and
2 deletions
build/tizen/examples/Makefile.am
| @@ -33,7 +33,8 @@ bin_PROGRAMS = \ | @@ -33,7 +33,8 @@ bin_PROGRAMS = \ | ||
| 33 | dali-builder \ | 33 | dali-builder \ |
| 34 | builder.example \ | 34 | builder.example \ |
| 35 | image-scaling-irregular-grid.example \ | 35 | image-scaling-irregular-grid.example \ |
| 36 | - buttons.example | 36 | + buttons.example \ |
| 37 | + text-view.example | ||
| 37 | 38 | ||
| 38 | 39 | ||
| 39 | daliimagedir = $(appdatadir)/images/ | 40 | daliimagedir = $(appdatadir)/images/ |
| @@ -152,3 +153,8 @@ buttons_example_SOURCES = $(examples_src_dir)/buttons/buttons-example.cpp | @@ -152,3 +153,8 @@ buttons_example_SOURCES = $(examples_src_dir)/buttons/buttons-example.cpp | ||
| 152 | buttons_example_CXXFLAGS = $(EXAMPLE_CXXFLAGS) | 153 | buttons_example_CXXFLAGS = $(EXAMPLE_CXXFLAGS) |
| 153 | buttons_example_DEPENDENCIES = $(EXAMPLE_DEPS) | 154 | buttons_example_DEPENDENCIES = $(EXAMPLE_DEPS) |
| 154 | buttons_example_LDADD = $(EXAMPLE_LDADD) | 155 | buttons_example_LDADD = $(EXAMPLE_LDADD) |
| 156 | + | ||
| 157 | +text_view_example_SOURCES = $(examples_src_dir)/text-view/text-view-example.cpp | ||
| 158 | +text_view_example_CXXFLAGS = $(EXAMPLE_CXXFLAGS) | ||
| 159 | +text_view_example_DEPENDENCIES = $(EXAMPLE_DEPS) | ||
| 160 | +text_view_example_LDADD = $(EXAMPLE_LDADD) |
com.samsung.dali-demo.xml
| @@ -64,4 +64,7 @@ | @@ -64,4 +64,7 @@ | ||
| 64 | <ui-application appid="buttons.example" exec="/usr/apps/com.samsung.dali-demo/bin/buttons.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | 64 | <ui-application appid="buttons.example" exec="/usr/apps/com.samsung.dali-demo/bin/buttons.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 65 | <label>Radio Buttons</label> | 65 | <label>Radio Buttons</label> |
| 66 | </ui-application> | 66 | </ui-application> |
| 67 | + <ui-application appid="text-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | ||
| 68 | + <label>Text View</label> | ||
| 69 | + </ui-application> | ||
| 67 | </manifest> | 70 | </manifest> |
demo/dali-demo.cpp
| @@ -40,6 +40,7 @@ int main(int argc, char **argv) | @@ -40,6 +40,7 @@ int main(int argc, char **argv) | ||
| 40 | demo.AddExample(Example("shadow-bone-lighting.example", "Lights and shadows")); | 40 | demo.AddExample(Example("shadow-bone-lighting.example", "Lights and shadows")); |
| 41 | demo.AddExample(Example("builder.example", "Script Based UI")); | 41 | demo.AddExample(Example("builder.example", "Script Based UI")); |
| 42 | demo.AddExample(Example("image-scaling-irregular-grid.example", "Image Scaling Modes")); | 42 | demo.AddExample(Example("image-scaling-irregular-grid.example", "Image Scaling Modes")); |
| 43 | + demo.AddExample(Example("text-view.example", "Text View")); | ||
| 43 | app.MainLoop(); | 44 | app.MainLoop(); |
| 44 | 45 | ||
| 45 | return 0; | 46 | return 0; |
examples/shared/view.h
| @@ -59,7 +59,7 @@ float ScalePointSize(int pointSize) | @@ -59,7 +59,7 @@ float ScalePointSize(int pointSize) | ||
| 59 | { | 59 | { |
| 60 | Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi(); | 60 | Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi(); |
| 61 | float meanDpi = (dpi.height + dpi.width) * 0.5f; | 61 | float meanDpi = (dpi.height + dpi.width) * 0.5f; |
| 62 | - return (pointSize * 220.0f) / meanDpi; | 62 | + return pointSize * meanDpi / 220.0f; // 220 is the default horizontal DPI defined in adaptor Application |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | Dali::TextStyle& GetDefaultTextStyle() | 65 | Dali::TextStyle& GetDefaultTextStyle() |
examples/text-view/text-view-example.cpp
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2014 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 "../shared/view.h" | ||
| 19 | +#include <dali/dali.h> | ||
| 20 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 21 | + | ||
| 22 | +using namespace Dali; | ||
| 23 | + | ||
| 24 | +namespace | ||
| 25 | +{ | ||
| 26 | + | ||
| 27 | +const char* const BACKGROUND_IMAGE = DALI_IMAGE_DIR "background-gradient.jpg"; | ||
| 28 | +const char* const TOOLBAR_IMAGE = DALI_IMAGE_DIR "top-bar.png"; | ||
| 29 | + | ||
| 30 | +const char* const TOOLBAR_TITLE = "Text View"; | ||
| 31 | +const int TOOLBAR_HEIGHT = 80; | ||
| 32 | + | ||
| 33 | +const int NUM_TABLE_ROWS = 12; | ||
| 34 | +const int NUM_TABLE_COLUMNS = 12; | ||
| 35 | + | ||
| 36 | +} // namespace | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | + * Helper structs | ||
| 40 | + */ | ||
| 41 | +struct TableCell | ||
| 42 | +{ | ||
| 43 | + unsigned int row; | ||
| 44 | + unsigned int column; | ||
| 45 | + unsigned int rowSpan; | ||
| 46 | + unsigned int columnSpan; | ||
| 47 | +}; | ||
| 48 | + | ||
| 49 | +struct TableString | ||
| 50 | +{ | ||
| 51 | + std::string fontName; | ||
| 52 | + std::string fontStyle; | ||
| 53 | + float fontSize; | ||
| 54 | + Dali::TextStyle::Weight fontWeight; | ||
| 55 | + Vector4 fontColour; | ||
| 56 | + | ||
| 57 | + std::string text; | ||
| 58 | + | ||
| 59 | + Toolkit::Alignment::Type horizontalAlignment; | ||
| 60 | + Toolkit::Alignment::Type verticalAlignment; | ||
| 61 | + float padding; | ||
| 62 | + | ||
| 63 | + float orientation; | ||
| 64 | + | ||
| 65 | + TableCell cellPosition; | ||
| 66 | +}; | ||
| 67 | + | ||
| 68 | +namespace | ||
| 69 | +{ | ||
| 70 | +// Font Font style Font point size Font weight Text colour Text Horizontal alignment Vertical alignment Padding Orientation Table cell position and span | ||
| 71 | +const TableString TABLE_STRINGS[] = { { "HelveticaNue", "Regular", 8.0f, Dali::TextStyle::REGULAR, Vector4( 0.5f, 1.0f, 0.0f, 1.0f ), "Howdy", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 0, 0, 2, 4 } }, | ||
| 72 | + { "HelveticaNue", "Regular", 13.0f, Dali::TextStyle::EXTRABOLD, Vector4( 1.0f, 0.5f, 0.0f, 1.0f ), "Hello!", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 0, 4, 1, 4 } }, | ||
| 73 | + { "HelveticaNue", "Regular", 18.0f, Dali::TextStyle::REGULAR, Vector4( 1.0f, 0.75f, 0.25f, 1.0f ), "שלום!", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 1, 4, 1, 4 } }, | ||
| 74 | + { "HelveticaNue", "Regular", 8.0f, Dali::TextStyle::REGULAR, Vector4( 0.5f, 0.0f, 1.0f, 1.0f ), "Hi there", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalBottom, 10.0f, 0.0f, { 0, 8, 2, 4 } }, | ||
| 75 | + { "HelveticaNue", "Regular", 12.0f, Dali::TextStyle::REGULAR, Vector4( 0.5f, 1.0f, 1.0f, 1.0f ), "Hola", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 90.0f, { 2, 0, 4, 2 } }, | ||
| 76 | + { "HelveticaNue", "Regular", 18.0f, Dali::TextStyle::BOLD, Vector4( 0.5f, 1.0f, 0.5f, 1.0f ), "Bonjour", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 2, 2, 2, 4 } }, | ||
| 77 | + { "HelveticaNue", "Regular", 12.0f, Dali::TextStyle::REGULAR, Vector4( 1.0f, 1.0f, 0.5f, 1.0f ), "Ciao", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 2, 7, 2, 3 } }, | ||
| 78 | + { "HelveticaNue", "Regular", 26.0f, Dali::TextStyle::EXTRABLACK, Vector4( 0.5f, 0.0f, 0.0f, 1.0f ), "Hello", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 4, 2, 1, 6 } }, | ||
| 79 | + { "HelveticaNue", "Regular", 8.0f, Dali::TextStyle::DEMIBOLD, Vector4( 0.0f, 0.5f, 0.0f, 1.0f ), "Top of the morning to you", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 90.0f, { 4, 10, 8, 2 } }, | ||
| 80 | + { "HelveticaNue", "Regular", 13.0f, Dali::TextStyle::DEMIBOLD, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), "हैलो", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 6, 1, 1, 3 } }, | ||
| 81 | + { "HelveticaNue", "Regular", 8.0f, Dali::TextStyle::DEMIBOLD, Vector4( 1.0f, 1.0f, 0.0f, 1.0f ), "สวัสดี", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 90.0f, { 6, 5, 2, 1 } }, | ||
| 82 | + { "HelveticaNue", "Regular", 18.0f, Dali::TextStyle::REGULAR, Vector4( 0.0f, 1.0f, 1.0f, 1.0f ), "你好", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalBottom, 10.0f, 0.0f, { 6, 6, 1, 3 } }, | ||
| 83 | + { "HelveticaNue", "Regular", 34.0f, Dali::TextStyle::REGULAR, Vector4( 0.0f, 0.0f, 1.0f, 1.0f ), "G'day", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 7, 0, 2, 10 } }, | ||
| 84 | + { "HelveticaNue", "Regular", 16.0f, Dali::TextStyle::EXTRABLACK, Vector4( 0.0f, 0.5f, 1.0f, 1.0f ), "مرحبا", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 9, 1, 2, 4 } }, | ||
| 85 | + { "HelveticaNue", "Regular", 10.0f, Dali::TextStyle::EXTRABLACK, Vector4( 1.0f, 0.0f, 0.0f, 1.0f ), "こんにちは", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 10, 0, 2, 6 } }, | ||
| 86 | + { "HelveticaNue", "Regular", 14.0f, Dali::TextStyle::REGULAR, Vector4( 0.0f, 1.0f, 0.0f, 1.0f ), "aloha", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 10, 6, 2, 4 } } | ||
| 87 | + }; | ||
| 88 | + | ||
| 89 | +const int NUM_TABLE_STRINGS = sizeof( TABLE_STRINGS ) / sizeof( TABLE_STRINGS[0] ); | ||
| 90 | + | ||
| 91 | +} // namespace | ||
| 92 | + | ||
| 93 | +/** | ||
| 94 | + * This example shows the usage of TextView. | ||
| 95 | + */ | ||
| 96 | +class TextViewController: public ConnectionTracker | ||
| 97 | +{ | ||
| 98 | +public: | ||
| 99 | + | ||
| 100 | + TextViewController( Application& application ) | ||
| 101 | + : mApplication( application ) | ||
| 102 | + { | ||
| 103 | + // Connect to the Application's Init signal | ||
| 104 | + mApplication.InitSignal().Connect( this, &TextViewController::Create ); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + ~TextViewController() | ||
| 108 | + { | ||
| 109 | + // Nothing to do here | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + void Create( Application& application ) | ||
| 113 | + { | ||
| 114 | + // The Init signal is received once (only) during the Application lifetime | ||
| 115 | + | ||
| 116 | + Stage stage = Stage::GetCurrent(); | ||
| 117 | + | ||
| 118 | + // Respond to key events | ||
| 119 | + stage.KeyEventSignal().Connect(this, &TextViewController::OnKeyEvent); | ||
| 120 | + | ||
| 121 | + // Creates a default view with a default tool bar. | ||
| 122 | + // The view is added to the stage. | ||
| 123 | + mContentLayer = DemoHelper::CreateView( application, | ||
| 124 | + mView, | ||
| 125 | + mToolBar, | ||
| 126 | + BACKGROUND_IMAGE, | ||
| 127 | + TOOLBAR_IMAGE, | ||
| 128 | + TOOLBAR_TITLE ); | ||
| 129 | + | ||
| 130 | + // Create a table view the height of the stage | ||
| 131 | + Toolkit::TableView textContainer = Toolkit::TableView::New( NUM_TABLE_ROWS, NUM_TABLE_COLUMNS ); | ||
| 132 | + textContainer.SetParentOrigin( ParentOrigin::TOP_LEFT ); | ||
| 133 | + textContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | ||
| 134 | + textContainer.SetPosition( 0, TOOLBAR_HEIGHT ); | ||
| 135 | + textContainer.SetSize( stage.GetSize().width, stage.GetSize().height - TOOLBAR_HEIGHT ); | ||
| 136 | + | ||
| 137 | + mContentLayer.Add( textContainer ); | ||
| 138 | + | ||
| 139 | + // Add data | ||
| 140 | + for( int i = 0; i < NUM_TABLE_STRINGS; ++i ) | ||
| 141 | + { | ||
| 142 | + const TableString& tableString = TABLE_STRINGS[ i ]; | ||
| 143 | + | ||
| 144 | + Dali::TextStyle textStyle; | ||
| 145 | + textStyle.SetFontName( tableString.fontName ); | ||
| 146 | + textStyle.SetFontStyle( tableString.fontStyle ); | ||
| 147 | + textStyle.SetFontPointSize( Dali::PointSize( DemoHelper::ScalePointSize( tableString.fontSize ) ) ); | ||
| 148 | + textStyle.SetWeight( tableString.fontWeight ); | ||
| 149 | + textStyle.SetTextColor( tableString.fontColour ); | ||
| 150 | + | ||
| 151 | + Toolkit::TextView textView = Toolkit::TextView::New( tableString.text ); | ||
| 152 | + textView.SetStyleToCurrentText( textStyle ); | ||
| 153 | + textView.SetRotation( Dali::Degree( tableString.orientation ), Vector3( 0.0f, 0.0f, 1.0f ) ); | ||
| 154 | + | ||
| 155 | + Toolkit::Alignment alignmentContainer = Toolkit::Alignment::New( tableString.horizontalAlignment, tableString.verticalAlignment ); | ||
| 156 | + alignmentContainer.SetPadding( Toolkit::Alignment::Padding( tableString.padding, tableString.padding, tableString.padding, tableString.padding ) ); | ||
| 157 | + alignmentContainer.SetScaling( Toolkit::Alignment::ScaleToFill ); | ||
| 158 | + alignmentContainer.Add( textView ); | ||
| 159 | + | ||
| 160 | + textContainer.AddChild( alignmentContainer, Toolkit::TableView::CellPosition( tableString.cellPosition.row, tableString.cellPosition.column, tableString.cellPosition.rowSpan, tableString.cellPosition.columnSpan ) ); | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + void OnKeyEvent( const KeyEvent& event ) | ||
| 165 | + { | ||
| 166 | + if( event.state == KeyEvent::Down ) | ||
| 167 | + { | ||
| 168 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) | ||
| 169 | + { | ||
| 170 | + // Exit application when click back or escape. | ||
| 171 | + mApplication.Quit(); | ||
| 172 | + } | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | +private: | ||
| 177 | + | ||
| 178 | + Application& mApplication; | ||
| 179 | + Toolkit::View mView; ///< The View instance. | ||
| 180 | + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. | ||
| 181 | + Layer mContentLayer; ///< Content layer | ||
| 182 | + | ||
| 183 | +}; | ||
| 184 | + | ||
| 185 | +void RunTest( Application& application ) | ||
| 186 | +{ | ||
| 187 | + TextViewController test( application ); | ||
| 188 | + | ||
| 189 | + application.MainLoop(); | ||
| 190 | +} | ||
| 191 | + | ||
| 192 | +// Entry point for Linux & SLP applications | ||
| 193 | +// | ||
| 194 | +int main( int argc, char **argv ) | ||
| 195 | +{ | ||
| 196 | + Application application = Application::New( &argc, &argv ); | ||
| 197 | + | ||
| 198 | + RunTest( application ); | ||
| 199 | + | ||
| 200 | + return 0; | ||
| 201 | +} |