diff --git a/doc/tutorial/021_Resources.bb b/doc/tutorial/021_Resources.bb index 92ef19d6..efdfa00e 100644 --- a/doc/tutorial/021_Resources.bb +++ b/doc/tutorial/021_Resources.bb @@ -82,7 +82,7 @@ Then for basic resource: [code style=c++] #include namespace appl { - class MyResource : public ewol::Resource { + class MyResource : public gale::Resource { protected: //! @brief Constructor MyResource() : diff --git a/doc/tutorial/050_CreateCustomWidget.bb b/doc/tutorial/050_CreateCustomWidget.bb index c6dbd4eb..d8b653bd 100644 --- a/doc/tutorial/050_CreateCustomWidget.bb +++ b/doc/tutorial/050_CreateCustomWidget.bb @@ -12,20 +12,58 @@ The first things to do is to choice a methode to display you widget: #include namespace appl { class myWidget : public ewol::Widget { + private: + ewol::compositing::Drawing m_draw; //!< simple openGL drawing tool public: myWidget(void) {}; ~myWidget(void) {}; public: // herited function - void draw(void); + void onDraw(void); void onRegenerateDisplay(void); } } [/code] -We can show that we had two function, the first is call every time we render the widget (as the number of fps) "draw()". +We can show that we have two function, the first is call every time we render the widget (as the number of fps) "onDraw()". And the second that is call only when we need to redraw the widget (after the user call markToRedraw() ) "onRegenerateDisplay()". +===basic code=== + +we can define some basic functions: + +The constructor: +[code style=c++] +appl::myWidget::myWidget() { + addObjectType("appl::widget::VectorDisplay"); +} +[/code] + +The draw function: +[code style=c++] +void appl::myWidget::onDraw() { + m_draw.draw(); +} +[/code] + +The drawing area function (where we create the patern.). +[code style=c++] +void appl::myWidget::onRegenerateDisplay() { + //!< Check if we really need to redraw the display, if not needed, we redraw the previous data ... + if (needRedraw() == false) { + return; + } + // remove previous data + m_draw.clear(); + // set background + m_draw.setColor(etk::color::black); + m_draw.setPos(vec2(0,0)); + m_draw.rectangleWidth(m_size); + m_draw.setColor(etk::color::green); + m_draw.setPos(m_size*0.2); + m_draw.rectangleWidth(m_size*0.5); +} +[/code] - +A more complex sample is availlable in [b]"ewol-sample-CustomWidget"[/b] diff --git a/doc/tutorial/051_AddWidgetCustumInXML.bb b/doc/tutorial/051_AddWidgetCustumInXML.bb index 12370b6f..6d671334 100644 --- a/doc/tutorial/051_AddWidgetCustumInXML.bb +++ b/doc/tutorial/051_AddWidgetCustumInXML.bb @@ -5,11 +5,69 @@ Object can be declared in some XML, (like gui decription), then we need to decla === Declare Object === -The fist step is to add a methode to create the object +In your application "void onCreate(ewol::Context& _context) override" add the function: + +[code style=c++] + YourWidgetClass::createManagerWidget(_context.getWidgetManager()); +[/code] + +The simple question is: I does not define this function, where it is done ? + +The createManagerWidget is instancuate when you use the macro: + +[code style=c++] + DECLARE_WIDGET_FACTORY(YourWidgetClass, "YourWidgetClass"); +[/code] + +it create 2 function: "create(...)" and "createManagerWidget()" === Declare on XML and configuration === +in the xml instance simply request it like: + +[code style=xml] + + ... + +[/code] + +The xml attribute are automaticaly parsed to configure properties of you object (this is the reason of naming it). + === Special case SubParsing XML element === +If you want to parse sub-node of the xml just override the function member: + +[code style=c++] + bool loadXML(const std::shared_ptr& _node) override; +[/code] + +Many example are availlable in container widget. + +Simple example: + +[code style=c++] + if (_node == nullptr) { + return false; + } + // parse generic properties: + ewol::Widget::loadXML(_node); + // parse all the elements: + for (size_t iii=0; iii < _node->size(); iii++) { + std::shared_ptr pNode = _node->getElement(iii); + if (pNode == nullptr) { + // trash here all that is not element + continue; + } + // Get the sub-node name: + std::string widgetName = pNode->getValue(); + if (getWidgetManager().exist(widgetName) == false) { + APPL_ERROR("[" << getId() << "] (l "<getPos()<<") Unknown basic node='" << widgetName << "' not in : [" << getWidgetManager().list() << "]" ); + continue; + } + ... + } + return true; +[/code] + diff --git a/ewol/widget/meta/FileChooser.h b/ewol/widget/meta/FileChooser.h index 89f3b534..3b1f8def 100644 --- a/ewol/widget/meta/FileChooser.h +++ b/ewol/widget/meta/FileChooser.h @@ -39,11 +39,11 @@ namespace ewol { * // no need of this event watching ... * tmpWidget->signalCancel.connect(shared_from_this(), &****::onCallbackClosePopUp); * // set the title: - * tmpWidget->setTitle("Open files ..."); + * tmpWidget->propertyLabelTitle.set("Open files ..."); * // Set the validate Label: - * tmpWidget->setValidateLabel("Open"); + * tmpWidget->propertyLabelValidate.set("Open"); * // simply set a folder (by default this is the home folder) - * //tmpWidget->setFolder("/home/me"); + * //tmpWidget->propertyPath.set("/home/me"); * // add the widget as windows pop-up ... * ewol::widget::WindowsShared tmpWindows = getWindows(); * if (tmpWindows == nullptr) { @@ -67,14 +67,14 @@ namespace ewol { */ class FileChooser : public ewol::widget::Composer { public: // signals - esignal::ISignal<> signalCancel; - esignal::ISignal signalValidate; + esignal::ISignal<> signalCancel; //!< abort the display of the pop-up or press cancel button + esignal::ISignal signalValidate; //!< select file(s) public: // properties - eproperty::Value propertyPath; - eproperty::Value propertyFile; - eproperty::Value propertyLabelTitle; - eproperty::Value propertyLabelValidate; - eproperty::Value propertyLabelCancel; + eproperty::Value propertyPath; //!< Current path to explore + eproperty::Value propertyFile; //!< Selected file + eproperty::Value propertyLabelTitle; //!< Label of the pop-up (can use translation) + eproperty::Value propertyLabelValidate; //!< Label of validate button of the pop-up (can use translation) + eproperty::Value propertyLabelCancel; //!< Label of cancel/close button of the pop-up (can use translation) protected: FileChooser(); void init() override; diff --git a/sample/CustomWidgets/appl/widget/VectorDisplay.cpp b/sample/CustomWidgets/appl/widget/VectorDisplay.cpp index c7506705..6564aa63 100644 --- a/sample/CustomWidgets/appl/widget/VectorDisplay.cpp +++ b/sample/CustomWidgets/appl/widget/VectorDisplay.cpp @@ -22,6 +22,8 @@ appl::widget::VectorDisplay::VectorDisplay() : void appl::widget::VectorDisplay::init() { ewol::Widget::init(); markToRedraw(); + // set call all time (sample ...). + getObjectManager().periodicCall.connect(shared_from_this(), &appl::widget::VectorDisplay::periodicEvent); } @@ -37,10 +39,8 @@ void appl::widget::VectorDisplay::setValue(const std::vector& _data) { void appl::widget::VectorDisplay::ToggleAuto() { if (m_autoDisplay == false) { - periodicCallEnable(); m_autoDisplay = true; } else { - periodicCallDisable(); m_autoDisplay = false; } } @@ -79,7 +79,10 @@ void appl::widget::VectorDisplay::onRegenerateDisplay() { } } -void appl::widget::VectorDisplay::periodicCall(const ewol::event::Time& _event) { +void appl::widget::VectorDisplay::periodicEvent(const ewol::event::Time& _event) { + if (m_autoDisplay == false) { + return; + } for (size_t iii=0; iii 50) { m_data.erase(m_data.begin()); diff --git a/sample/CustomWidgets/appl/widget/VectorDisplay.h b/sample/CustomWidgets/appl/widget/VectorDisplay.h index 18790668..c0ac3fea 100644 --- a/sample/CustomWidgets/appl/widget/VectorDisplay.h +++ b/sample/CustomWidgets/appl/widget/VectorDisplay.h @@ -12,7 +12,7 @@ namespace appl { namespace widget { class VectorDisplay : public ewol::Widget { - private: + protected: ewol::compositing::Drawing m_draw; //!< drawing instance protected: //! @brief constructor @@ -22,21 +22,21 @@ namespace appl { DECLARE_WIDGET_FACTORY(VectorDisplay, "VectorDisplay"); //! @brief destructor virtual ~VectorDisplay(); - private: + protected: std::vector m_data; //!< data that might be displayed public: void setValue(const std::vector& _data); - private: + protected: bool m_autoDisplay; public: void ToggleAuto(); - private: + protected: float m_minVal; //!< display minimum value float m_maxVal; //!< display maximum value - public: // herited function - virtual void onDraw(); - virtual void onRegenerateDisplay(); - virtual void periodicCall(const ewol::event::Time& _event); + public: + void onDraw() override; + void onRegenerateDisplay() override; + void periodicEvent(const ewol::event::Time& _event); }; } }