/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
+#include <dali/devel-api/adaptor-framework/style-monitor.h>
+
#include <iostream>
#include <stdlib.h>
#include <dali-toolkit-test-suite-utils.h>
test_return_value = TET_PASS;
}
-
int UtcDaliStyleManagerConstructorP(void)
{
ToolkitTestApplication application;
}
-int UtcDaliStyleManagerStyleChangedSignal(void)
+int UtcDaliStyleManagerStyleChangedSignalFontFamily(void)
{
- tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
+ tet_infoline("Test that the StyleChange signal is fired when the font family is altered" );
Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
defaultTheme );
Stage::GetCurrent().Add( label2 );
StyleChangedSignalChecker styleChangedSignalHandler;
- StyleMonitor styleMonitor = StyleMonitor::Get();
+ Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
StyleManager styleManager = StyleManager::Get();
styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
END_TEST;
}
+
+int UtcDaliStyleManagerStyleChangedSignalFontSize(void)
+{
+ tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
+
+ const char* defaultTheme =
+ "{\n"
+ " \"styles\":\n"
+ " {\n"
+ " \"textlabelFontSize0\":\n"
+ " {\n"
+ " \"pointSize\":10\n"
+ " },\n"
+ " \"textlabelFontSize1\":\n"
+ " {\n"
+ " \"pointSize\":10\n"
+ " },\n"
+ " \"textlabelFontSize2\":\n"
+ " {\n"
+ " \"pointSize\":12\n"
+ " },\n"
+ " \"textlabelFontSize3\":\n"
+ " {\n"
+ " \"pointSize\":14\n"
+ " },\n"
+ " \"textlabelFontSize4\":\n"
+ " {\n"
+ " \"pointSize\":16\n"
+ " }\n"
+ " }\n"
+ "}\n";
+
+ Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
+
+ ToolkitTestApplication application;
+
+ std::string labelStr("Label");
+ Toolkit::TextLabel label = Toolkit::TextLabel::New(labelStr);
+ Stage::GetCurrent().Add( label );
+
+ Toolkit::TextLabel label2 = Toolkit::TextLabel::New(labelStr);
+ Stage::GetCurrent().Add( label2 );
+
+ StyleChangedSignalChecker styleChangedSignalHandler;
+ StyleMonitor styleMonitor = StyleMonitor::Get();
+ StyleManager styleManager = StyleManager::Get();
+
+ label.SetProperty(TextLabel::Property::POINT_SIZE, 10.0f);
+
+ styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
+
+ Test::StyleMonitor::SetDefaultFontSize(2);
+ styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
+
+ tet_infoline("Test that the StyleChanged signal is received only once");
+ DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
+
+ tet_infoline("Test that the label's font size has been altered\n");
+ Property::Value pointSizeValue = label.GetProperty(TextLabel::Property::POINT_SIZE);
+ float pointSize;
+ pointSizeValue.Get( pointSize );
+
+ DALI_TEST_EQUALS( pointSize, 12.0f, 0.001, TEST_LOCATION );
+
+ styleChangedSignalHandler.signalCount = 0;
+
+ Test::StyleMonitor::SetDefaultFontSize(4);
+ styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
+
+ tet_infoline("Test that the StyleChanged signal is received only once");
+ DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
+
+ // Check that the label's font style has been altered
+ pointSizeValue = label.GetProperty(TextLabel::Property::POINT_SIZE);
+ pointSizeValue.Get( pointSize );
+
+ DALI_TEST_EQUALS( pointSize, 16.0f, 0.001, TEST_LOCATION );
+
+
+ END_TEST;
+}
+
+
+int UtcDaliStyleManagerStyleChangedSignalFontSizeTextField(void)
+{
+ tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
+
+ const char* defaultTheme =
+ "{\n"
+ " \"styles\":\n"
+ " {\n"
+ " \"textfieldFontSize0\":\n"
+ " {\n"
+ " \"pointSize\":8\n"
+ " },\n"
+ " \"textfieldFontSize1\":\n"
+ " {\n"
+ " \"pointSize\":10\n"
+ " },\n"
+ " \"textfieldFontSize2\":\n"
+ " {\n"
+ " \"pointSize\":12\n"
+ " },\n"
+ " \"textfieldFontSize3\":\n"
+ " {\n"
+ " \"pointSize\":14\n"
+ " },\n"
+ " \"textfieldFontSize4\":\n"
+ " {\n"
+ " \"pointSize\":16\n"
+ " }\n"
+ " }\n"
+ "}\n";
+
+ Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
+
+ ToolkitTestApplication application;
+
+ std::string fieldStr("Field");
+ Toolkit::TextField field = Toolkit::TextField::New();
+ field.SetProperty( Toolkit::TextField::Property::TEXT, fieldStr );
+ Stage::GetCurrent().Add( field );
+
+ Toolkit::TextField field2 = Toolkit::TextField::New();
+ Stage::GetCurrent().Add( field2 );
+ field2.SetProperty( Toolkit::TextField::Property::TEXT, fieldStr );
+
+ StyleChangedSignalChecker styleChangedSignalHandler;
+ StyleMonitor styleMonitor = StyleMonitor::Get();
+ StyleManager styleManager = StyleManager::Get();
+
+ field.SetProperty(TextField::Property::POINT_SIZE, 10.0f);
+
+ styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
+
+ Test::StyleMonitor::SetDefaultFontSize(2);
+ styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
+
+ tet_infoline("Test that the StyleChanged signal is received only once");
+ DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
+
+ tet_infoline("Test that the field's font size has been altered\n");
+ Property::Value pointSizeValue = field.GetProperty(TextField::Property::POINT_SIZE);
+ float pointSize;
+ pointSizeValue.Get( pointSize );
+
+ DALI_TEST_EQUALS( pointSize, 12.0f, 0.001, TEST_LOCATION );
+
+ styleChangedSignalHandler.signalCount = 0;
+
+ Test::StyleMonitor::SetDefaultFontSize(4);
+ styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
+
+ tet_infoline("Test that the StyleChanged signal is received only once");
+ DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
+
+ // Check that the field's font style has been altered
+ pointSizeValue = field.GetProperty(TextField::Property::POINT_SIZE);
+ pointSizeValue.Get( pointSize );
+
+ DALI_TEST_EQUALS( pointSize, 16.0f, 0.001, TEST_LOCATION );
+
+
+ END_TEST;
+}
+
+int UtcDaliStyleManagerStyleChangedSignalFontSizeTextEditor(void)
+{
+ tet_infoline("Test that the StyleChange signal is fired when the font size is altered" );
+
+ const char* defaultTheme =
+ "{\n"
+ " \"styles\":\n"
+ " {\n"
+ " \"texteditorFontSize0\":\n"
+ " {\n"
+ " \"pointSize\":10\n"
+ " },\n"
+ " \"texteditorFontSize1\":\n"
+ " {\n"
+ " \"pointSize\":12\n"
+ " },\n"
+ " \"texteditorFontSize2\":\n"
+ " {\n"
+ " \"pointSize\":14\n"
+ " },\n"
+ " \"texteditorFontSize3\":\n"
+ " {\n"
+ " \"pointSize\":18\n"
+ " },\n"
+ " \"texteditorFontSize4\":\n"
+ " {\n"
+ " \"pointSize\":25\n"
+ " }\n"
+ " }\n"
+ "}\n";
+
+ Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme );
+
+ ToolkitTestApplication application;
+
+ std::string editorStr("Editor");
+ Toolkit::TextEditor editor = Toolkit::TextEditor::New();
+ editor.SetProperty( Toolkit::TextEditor::Property::TEXT, editorStr );
+ Stage::GetCurrent().Add( editor );
+
+ Toolkit::TextEditor editor2 = Toolkit::TextEditor::New();
+ Stage::GetCurrent().Add( editor2 );
+ editor2.SetProperty( Toolkit::TextEditor::Property::TEXT, editorStr );
+
+ StyleChangedSignalChecker styleChangedSignalHandler;
+ StyleMonitor styleMonitor = StyleMonitor::Get();
+ StyleManager styleManager = StyleManager::Get();
+
+ editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.0f);
+
+ styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
+
+ Test::StyleMonitor::SetDefaultFontSize(2);
+ styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
+
+ tet_infoline("Test that the StyleChanged signal is received only once");
+ DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
+
+ tet_infoline("Test that the editor's font size has been altered\n");
+ Property::Value pointSizeValue = editor.GetProperty(TextEditor::Property::POINT_SIZE);
+ float pointSize;
+ pointSizeValue.Get( pointSize );
+
+ DALI_TEST_EQUALS( pointSize, 14.0f, 0.001, TEST_LOCATION );
+
+ styleChangedSignalHandler.signalCount = 0;
+
+ Test::StyleMonitor::SetDefaultFontSize(4);
+ styleMonitor.StyleChangeSignal().Emit( styleMonitor, StyleChange::DEFAULT_FONT_SIZE_CHANGE);
+
+ tet_infoline("Test that the StyleChanged signal is received only once");
+ DALI_TEST_EQUALS( styleChangedSignalHandler.signalCount, 1, TEST_LOCATION );
+
+ // Check that the editor's font style has been altered
+ pointSizeValue = editor.GetProperty(TextEditor::Property::POINT_SIZE);
+ pointSizeValue.Get( pointSize );
+
+ DALI_TEST_EQUALS( pointSize, 25.0f, 0.001, TEST_LOCATION );
+
+
+ END_TEST;
+}
### Font Styles
-Setting a font size programmatically is not ideal for applications which support multiple screen resolutions etc.
+Setting a font size programmatically is not ideal for applications which support multiple
+screen resolutions and platforms which support multiple logical font sizes. Also, any
+changes to the platform font settings will override any sizes that have been programmatically
+set.
+
A more flexible approach is to prepare various JSON stylesheets, and request a different style for each platform:
~~~{.cpp}
~~~
However the same pointSize is unlikely to be suitable for all text controls in an application.
-To set custom sizes simply set a "style name" for each case, and then provide a style override in JSON:
+To define custom styles for existing controls, simply set a style name for each case, and
+then provide a style override in JSON.
+
+To provide flexibility for the end user, the platform offers a mechanism to alter the logical
+font size between 0 and 4 inclusive. This logical size is mapped to a physical size using the
+stylesheets, by appending FontSizeN to the style name. These sections ("textlabelFontSizeN")
+in the style sheet are applied after the base section ("textlabel"), so take precedence.
~~~{.cpp}
// C++
~~~{.js}
// JavaScript
- label.styleName = "custom"';
+ label.styleName = "customLabel"';
~~~
~~~{.json}
{
"fontFamily":"FreeSerif",
"fontStyle":"{\"weight\":\"bold\",\"slant\":\"italic\"}",
+ },
+
+ "textlabelFontSize0":
+ {
"pointSize":8
},
+ "textlabelFontSize1":
+ {
+ "pointSize":10
+ },
+ "textlabelFontSize2":
+ {
+ "pointSize":15
+ },
+ "textlabelFontSize3":
+ {
+ "pointSize":19
+ },
+ "textlabelFontSize4":
+ {
+ "pointSize":25
+ },
- "custom":
+ "customLabel":
+ {
+ "fontFamily":"TimesNewRoman",
+ "fontStyle":"{\"weight\":\"regular\",\"slant\":\"regular\"}",
+ },
+ "customLabelFontSize0":
{
"pointSize":10
+ },
+ "customLabelFontSize1":
+ {
+ "pointSize":12
+ },
+ "customLabelFontSize2":
+ {
+ "pointSize":15
+ },
+ "customLabelFontSize3":
+ {
+ "pointSize":20
+ },
+ "customLabelFontSize4":
+ {
+ "pointSize":28
}
}
}
~~~
-In the example above, standard text labels will have pointSize 8, and "custom" labels will have pointSize 10.
+In the example above, at platform logical text size 0, standard text labels will have pointSize 8, and custom labels will have pointSize 10.
+
*/