From 01a9d6b1c5854f3842ade24c08eb424002682213 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 29 Jan 2016 22:20:06 +0100 Subject: [PATCH] [DEV] better test tools for widget --- lutin_ewol-tools-visual-test.py | 1 + tools/visual_test/appl/MainWindows.cpp | 159 ++++++++++++++----------- tools/visual_test/appl/MainWindows.h | 2 + tools/visual_test/data/gui.xml | 59 +++++++++ 4 files changed, 150 insertions(+), 71 deletions(-) create mode 100644 tools/visual_test/data/gui.xml diff --git a/lutin_ewol-tools-visual-test.py b/lutin_ewol-tools-visual-test.py index 53d66440..b40773e1 100755 --- a/lutin_ewol-tools-visual-test.py +++ b/lutin_ewol-tools-visual-test.py @@ -49,6 +49,7 @@ def create(target, module_name): my_module.copy_path('tools/visual_test/data/stone*','') my_module.copy_path('tools/visual_test/data/sphere.png','') my_module.copy_path('tools/visual_test/data/sphere.obj','') + my_module.copy_path('tools/visual_test/data/gui.xml','') my_module.add_path(os.path.join(tools.get_current_path(__file__), "tools/visual_test/")) diff --git a/tools/visual_test/appl/MainWindows.cpp b/tools/visual_test/appl/MainWindows.cpp index 8efb886c..d748392b 100644 --- a/tools/visual_test/appl/MainWindows.cpp +++ b/tools/visual_test/appl/MainWindows.cpp @@ -31,6 +31,7 @@ #include #include #include +#include static const char * l_eventChangeTheme = "event-change-theme"; @@ -49,6 +50,19 @@ appl::MainWindows::MainWindows() : void appl::MainWindows::init() { ewol::widget::Windows::init(); + + m_composer = ewol::widget::Composer::create(ewol::widget::Composer::file, "DATA:gui.xml"); + setSubWidget(m_composer); + externSubBind(m_composer, ewol::widget::Button, "appl-theme-toggle", signalValue, shared_from_this(), &appl::MainWindows::onCallbackThemeChange); + externSubBind(m_composer, ewol::widget::Button, "appl-previous-widget", signalPressed, shared_from_this(), &appl::MainWindows::onCallbackWidgetChange, -1); + externSubBind(m_composer, ewol::widget::Button, "appl-next-widget", signalPressed, shared_from_this(), &appl::MainWindows::onCallbackWidgetChange, 1); + + m_sizerVert = std::dynamic_pointer_cast(m_composer->getSubObjectNamed("appl-upper-test-widget")); + m_sizerDynamic = std::dynamic_pointer_cast(m_composer->getSubObjectNamed("appl-dynamic-config")); + m_subWidget = std::dynamic_pointer_cast(m_composer->getSubObjectNamed("[TEST]TO-TEST")); + m_testName = std::dynamic_pointer_cast(m_composer->getSubObjectNamed("appl-label-test")); + + /* std::shared_ptr mySizerHori; std::shared_ptr mySizerVert; std::shared_ptr myButton; @@ -107,6 +121,17 @@ void appl::MainWindows::init() { mySizerHori->setFill(bvec2(true,true)); mySizerHori->lockExpand(bvec2(true,true)); mySizerVert->subWidgetAdd(mySizerHori); + + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + m_sizerDynamic = ewol::widget::Sizer::create(ewol::widget::Sizer::modeVert); if (m_sizerDynamic == nullptr) { APPL_ERROR("Allocation error mySizerHori"); @@ -134,6 +159,7 @@ void appl::MainWindows::init() { return; } mySizerHori->subWidgetAdd(m_sizerVert); + */ } void appl::MainWindows::onCallbackThemeChange(const bool& _value) { @@ -149,79 +175,57 @@ void appl::MainWindows::onCallbackThemeChange(const bool& _value) { void appl::MainWindows::onCallbackWidgetChange(int32_t _increment) { m_idWidget += _increment; - - if (m_subWidget != nullptr) { - m_subWidget->destroy(); - // in theory it must be removed ... - m_subWidget.reset(); - } + std::shared_ptr oldWidget = m_subWidget; + std::string tmpDescription; + std::string tmpConstruct; switch(m_idWidget) { case 0: - m_subWidget = appl::TestButton::create(); - if (m_subWidget != nullptr) { - m_sizerVert->subWidgetAdd(m_subWidget); - } - if (m_testName!=nullptr) { - m_testName->setLabel("TestButton"); - }; + tmpConstruct = std::string() + + "\n"; + tmpDescription = "TestButton"; + break; + case 1: + tmpConstruct = ""; + tmpDescription = "TestButtonColor"; + break; + case 2: + tmpConstruct = "\n"; + tmpDescription = "TestLabel"; + break; + case 3: + tmpConstruct = "\n"; + tmpDescription = "TestImage"; + break; + case 4: + tmpConstruct = "\n"; + tmpDescription = "TestCheckbox"; + break; + default: + tmpConstruct = "\n"; + tmpDescription = "Test Label"; + m_idWidget = -1; + break; + /* break; case 1: m_subWidget = TestDistanceField::create(); if (m_subWidget != nullptr) { m_sizerVert->subWidgetAdd(m_subWidget); } - if (m_testName != nullptr) { - m_testName->setLabel("Test Distance Field"); - }; - break; - case 2: - m_subWidget = TestButtonColor::create(); - if (m_subWidget != nullptr) { - m_sizerVert->subWidgetAdd(m_subWidget); - } - if (m_testName != nullptr) { - m_testName->setLabel("TestButtonColor"); - }; - break; - case 3: - m_subWidget = TestLabel::create(); - if (m_subWidget != nullptr) { - m_sizerVert->subWidgetAdd(m_subWidget); - } - if (m_testName != nullptr) { - m_testName->setLabel("TestLabel"); - }; - break; - case 4: - m_subWidget = TestImage::create(); - if (m_subWidget != nullptr) { - m_sizerVert->subWidgetAdd(m_subWidget); - } - if (m_testName != nullptr) { - m_testName->setLabel("TestImage"); - }; - break; - case 5: - m_subWidget = appl::TestCheckBox::create(); - if (m_subWidget != nullptr) { - m_sizerVert->subWidgetAdd(m_subWidget); - } - if (m_testName != nullptr) { - m_testName->setLabel("TestCheckbox"); - }; - break; - default: - m_subWidget = ewol::widget::Label::create("Test software for EWOL"); - if (m_subWidget != nullptr) { - m_subWidget->setExpand(bvec2(true,true)); - m_sizerVert->subWidgetAdd(m_subWidget); - } - if (m_testName != nullptr) { - m_testName->setLabel("Label"); - }; - m_idWidget = -1; + tmpDescription = "Test Distance Field"; + */ break; } + // create the widget with a xml generator (readable for test ...): + m_subWidget = ewol::widget::composerGenerate(ewol::widget::Composer::String, tmpConstruct); + if (m_subWidget != nullptr) { + m_sizerVert->subWidgetReplace(oldWidget, m_subWidget); + } + if (m_testName!=nullptr) { + m_testName->setLabel("TestButton"); + }; updateProperty(); } @@ -317,7 +321,16 @@ void appl::MainWindows::updateProperty() { return; } APPL_INFO("set parameter : X name=" << param->getName() << " value=" << _value); - //m_subWidget->parameterSet(param->getName(), etk::to_string(_value)); + ewol::parameter::Parameter* param = m_subWidget->getParameterRaw(iii); + ewol::parameter::Value* paramValue = dynamic_cast*>(param); + if (paramValue == nullptr) { + APPL_ERROR("nullptr... 2 "); + return; + } + std::string lastValue = m_subWidget->parameterGet(param->getName()); + bvec2 lastValueInterpreted = paramValue->get(); + lastValueInterpreted.setX(_value); + paramValue->set(lastValueInterpreted); return; }); std::shared_ptr widgetLabel = ewol::widget::Label::create("x"); @@ -331,7 +344,16 @@ void appl::MainWindows::updateProperty() { return; } APPL_INFO("set parameter : Y name=" << param->getName() << " value=" << _value); - //m_subWidget->parameterSet(param->getName(), etk::to_string(_value)); + ewol::parameter::Parameter* param = m_subWidget->getParameterRaw(iii); + ewol::parameter::Value* paramValue = dynamic_cast*>(param); + if (paramValue == nullptr) { + APPL_ERROR("nullptr... 2 "); + return; + } + std::string lastValue = m_subWidget->parameterGet(param->getName()); + bvec2 lastValueInterpreted = paramValue->get(); + lastValueInterpreted.setY(_value); + paramValue->set(lastValueInterpreted); return; }); widgetLabel = ewol::widget::Label::create("y"); @@ -384,14 +406,9 @@ void appl::MainWindows::updateProperty() { mySpacer->setExpand(bvec2(true,false)); mySpacer->setFill(bvec2(true,false)); mySpacer->setMinSize(vec2(3,3)); - mySpacer->setColor(0x000000AA); + mySpacer->setColor(etk::color::blue); m_sizerDynamic->subWidgetAddStart(mySpacer); } } - mySpacer = ewol::widget::Spacer::create(); - if (mySpacer != nullptr) { - mySpacer->setExpand(bvec2(true,true)); - m_sizerDynamic->subWidgetAddStart(mySpacer); - } } diff --git a/tools/visual_test/appl/MainWindows.h b/tools/visual_test/appl/MainWindows.h index 86e60943..ad4c88b8 100644 --- a/tools/visual_test/appl/MainWindows.h +++ b/tools/visual_test/appl/MainWindows.h @@ -16,9 +16,11 @@ #include #include #include +#include namespace appl { class MainWindows : public ewol::widget::Windows { private: + std::shared_ptr m_composer; std::shared_ptr m_sizerVert; std::shared_ptr m_sizerDynamic; std::shared_ptr m_subWidget; diff --git a/tools/visual_test/data/gui.xml b/tools/visual_test/data/gui.xml new file mode 100644 index 00000000..9217b333 --- /dev/null +++ b/tools/visual_test/data/gui.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +