[DEV] add widget Spin (not finished)

This commit is contained in:
Edouard DUPIN 2016-02-10 21:12:48 +01:00
parent 7f3e0735f6
commit 287815eaa6
14 changed files with 388 additions and 16 deletions

View File

@ -0,0 +1,7 @@
{
entry-shaper:"{ewol}THEME:GUI:SpinEntry.json",
up-shaper:"{ewol}THEME:GUI:SpinUp.json",
up-data:"<label>+</label>",
down-shaper:"{ewol}THEME:GUI:SpinDown.json",
down-data:"<label>-</label>",
}

View File

@ -0,0 +1,23 @@
{
mode:2,
display-outside:false,
padding-out-left:0,
padding-out-right:0,
padding-out-top:1,
padding-out-buttom:1,
border-left:1,
border-right:0,
border-top:1,
border-buttom:1,
padding-in-left:1,
padding-in-right:1,
padding-in-top:1,
padding-in-buttom:1,
change-time:356,
program:"{ewol}THEME:GUI:Button.prog",
color:"{ewol}THEME:COLOR:Button.json"
}

View File

@ -0,0 +1,23 @@
{
mode:2,
display-outside:false,
padding-out-left:0,
padding-out-right:0,
padding-out-top:1,
padding-out-buttom:1,
border-left:1,
border-right:0,
border-top:1,
border-buttom:1,
padding-in-left:2,
padding-in-right:2,
padding-in-top:1,
padding-in-buttom:1,
change-time:356,
program:"{ewol}THEME:GUI:Entry.prog",
color:"{ewol}THEME:COLOR:Entry.json"
}

View File

@ -0,0 +1,23 @@
{
mode:2,
display-outside:false,
padding-out-left:0,
padding-out-right:0,
padding-out-top:1,
padding-out-buttom:1,
border-left:1,
border-right:1,
border-top:1,
border-buttom:1,
padding-in-left:1,
padding-in-right:1,
padding-in-top:1,
padding-in-buttom:1,
change-time:356,
program:"{ewol}THEME:GUI:Button.prog",
color:"{ewol}THEME:COLOR:Button.json"
}

View File

@ -248,7 +248,7 @@ void ewol::widget::ContextMenu::setPositionMarkAuto(const vec2& _origin, const v
vec2 globalSize = windows->getSize();
// TODO : Support left and right
float upperSize = globalSize.y() - (_origin.y() + _size.y());
float underSize = globalSize.y() - _origin.y();
float underSize = _origin.y();
if (underSize >= upperSize) {
vec2 pos = _origin + _size - vec2(_size.x()*0.5f, 0.0f);
setPositionMark(ewol::widget::ContextMenu::markButtom, pos);

View File

@ -28,6 +28,7 @@
#include <ewol/widget/ListFileSystem.h>
#include <ewol/widget/Composer.h>
#include <ewol/widget/Select.h>
#include <ewol/widget/Spin.h>
#include <vector>
#undef __class__
@ -57,6 +58,7 @@ ewol::widget::Manager::Manager() :
ewol::widget::ListFileSystem::createManagerWidget(*this);
ewol::widget::Composer::createManagerWidget(*this);
ewol::widget::Select::createManagerWidget(*this);
ewol::widget::Spin::createManagerWidget(*this);
}
ewol::widget::Manager::~Manager() {

View File

@ -29,7 +29,7 @@ ewol::widget::Select::Element::Element(int32_t _value, std::string _name, bool _
ewol::widget::Select::Select() :
signalValue(*this, "value", "Select value change"),
m_value(*this, "value", false, "Value of the Select") {
m_value(*this, "value", -1, "Value of the Select") {
addObjectType("ewol::widget::Select");
}
@ -113,7 +113,7 @@ bool ewol::widget::Select::loadXML(const std::shared_ptr<const exml::Element>& _
return false;
}
// parse generic properties:
ewol::Widget::loadXML(_node);
ewol::widget::SpinBase::loadXML(_node);
// remove previous element:
//subWidgetRemove();
// parse all the elements:
@ -211,6 +211,6 @@ void ewol::widget::Select::onCallbackOpenMenu() {
void ewol::widget::Select::setValue(int32_t _val) {
m_value.set(_val);
}
bool ewol::widget::Select::getValue() const {
return m_value;
int32_t ewol::widget::Select::getValue() const {
return m_value.get();
};

View File

@ -70,7 +70,7 @@ namespace ewol {
* @return True : The Select is pressed.
* @return false : The Select is released.
*/
bool getValue() const;
int32_t getValue() const;
protected:
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);
virtual bool loadXML(const std::shared_ptr<const exml::Element>& _node);

136
ewol/widget/Spin.cpp Normal file
View File

@ -0,0 +1,136 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <ewol/debug.h>
#include <ewol/ewol.h>
#include <ewol/widget/Spin.h>
#include <ewol/widget/ContextMenu.h>
#include <ewol/widget/Label.h>
#include <ewol/widget/Windows.h>
#undef __class__
#define __class__ "widget::Spin"
ewol::widget::Spin::Spin() :
signalValue(*this, "value", "Spin value change"),
signalValueDouble(*this, "valueDouble", "Spin value change value in 'double'"),
m_value(*this, "value", 0, "Value of the Spin"),
m_min(*this, "min", -9999999999, "Minimum value of the spin"),
m_max(*this, "max", 9999999999, "Maximum value of the spin"),
m_increment(*this, "increment", 1, "Increment value at each button event or keybord event"),
m_mantis(*this, "mantis", 0, "fix-point mantis") {
addObjectType("ewol::widget::Spin");
}
void ewol::widget::Spin::init(enum ewol::widget::spinPosition _mode,
const std::string& _shaperName) {
EWOL_WARNING("init [START]");
ewol::widget::SpinBase::init(_mode, _shaperName);
markToRedraw();
EWOL_WARNING("init [STOP]");
}
ewol::widget::Spin::~Spin() {
}
void ewol::widget::Spin::onParameterChangeValue(const ewol::parameter::Ref& _paramPointer) {
ewol::widget::SpinBase::onParameterChangeValue(_paramPointer);
if (_paramPointer == m_value) {
markToRedraw();
if (m_widgetEntry == nullptr) {
EWOL_ERROR("Can not acces at entry ...");
return;
}
checkValue(m_value.get());
} else if (_paramPointer == m_min) {
checkValue(m_value.get());
} else if (_paramPointer == m_max) {
checkValue(m_value.get());
} else if (_paramPointer == m_increment) {
} else if (_paramPointer == m_mantis) {
}
}
void ewol::widget::Spin::updateGui() {
EWOL_WARNING("updateGui [START]");
ewol::widget::SpinBase::updateGui();
if (m_widgetEntry != nullptr) {
m_widgetEntry->signalUnBindAll(shared_from_this());
}
if (m_widgetButtonUp != nullptr) {
m_widgetButtonUp->signalUnBindAll(shared_from_this());
m_widgetButtonUp->signalPressed.bind(shared_from_this(), &ewol::widget::Spin::onCallbackUp);
}
if (m_widgetButtonDown != nullptr) {
m_widgetButtonDown->signalUnBindAll(shared_from_this());
m_widgetButtonDown->signalPressed.bind(shared_from_this(), &ewol::widget::Spin::onCallbackDown);
}
EWOL_WARNING("updateGui [STOP]");
}
void ewol::widget::Spin::checkValue(int64_t _value) {
_value = std::avg(m_min.get(), _value, m_max.get());
m_value.get() = _value;
m_widgetEntry->setValue(etk::to_string(_value));
}
void ewol::widget::Spin::onCallbackUp() {
int64_t value = m_value.get() + m_increment.get();
checkValue(value);
}
void ewol::widget::Spin::onCallbackDown() {
int64_t value = m_value.get() - m_increment.get();
checkValue(value);
}
void ewol::widget::Spin::setValue(int64_t _val) {
m_value.set(_val);
}
int64_t ewol::widget::Spin::getValue() const {
return m_value;
}
void ewol::widget::Spin::setMinimum(int64_t _val) {
m_min.set(_val);
}
int64_t ewol::widget::Spin::getMinimum() const {
return m_min;
}
void ewol::widget::Spin::setMaximum(int64_t _val) {
m_max.set(_val);
}
int64_t ewol::widget::Spin::getMaximum() const {
return m_max;
}
void ewol::widget::Spin::setIncrement(int64_t _val) {
m_increment.set(_val);
}
int64_t ewol::widget::Spin::getIncrement() const {
return m_increment;
}
void ewol::widget::Spin::setMantis(int8_t _val) {
m_mantis.set(_val);
}
int8_t ewol::widget::Spin::getMantis() const {
return m_mantis;
}

121
ewol/widget/Spin.h Normal file
View File

@ -0,0 +1,121 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <vector>
#include <etk/types.h>
#include <ewol/widget/meta/SpinBase.h>
namespace ewol {
namespace widget {
/**
* @brief a composed Spin is a Spin with an inside composed with the specify XML element
* ==> this permit to generate standard element simple
*/
class Spin : public ewol::widget::SpinBase {
public:
// Event list of properties
ewol::Signal<int64_t> signalValue;
ewol::Signal<double> signalValueDouble;
protected:
/**
* @brief Constructor
* @param[in] _mode mode to display the spin
* @param[in] _shaperName Shaper file properties
*/
Spin();
void init(enum ewol::widget::spinPosition _mode=ewol::widget::spinPosition_RightRight,
const std::string& _shaperName="{ewol}THEME:GUI:Spin.json");
public:
DECLARE_WIDGET_FACTORY(Spin, "Spin");
/**
* @brief Destructor
*/
virtual ~Spin();
/**
* @brief set the shaper name (use the contructer one this permit to not noad unused shaper)
* @param[in] _shaperName The new shaper filename
*/
void setShaperName(const std::string& _shaperName) {
//m_shaper.setString(_shaperName);
}
protected:
ewol::parameter::Value<int64_t> m_value; //!< Current value of the Spin.
public:
/**
* @brief set the current value of the Spin
* @param[in] _val New value to set
*/
void setValue(int64_t _val);
/**
* @brief get the current Spin value.
* @return The current spin value.
*/
int64_t getValue() const;
protected:
ewol::parameter::Value<int64_t> m_min; //!< Minimum value
public:
/**
* @brief set the minimum of the Spin
* @param[in] _val New minimum to set
*/
void setMinimum(int64_t _val);
/**
* @brief get the current Spin minimum.
* @return The current spin minimum.
*/
int64_t getMinimum() const;
protected:
ewol::parameter::Value<int64_t> m_max; //!< Maximum value
public:
/**
* @brief set the maxnimum of the Spin
* @param[in] _val New maxnimum to set
*/
void setMaximum(int64_t _val);
/**
* @brief get the current Spin maxnimum.
* @return The current spin maxnimum.
*/
int64_t getMaximum() const;
protected:
ewol::parameter::Value<int64_t> m_increment; //!< Increment value
public:
/**
* @brief set the increment value of the Spin
* @param[in] _val New increment to set
*/
void setIncrement(int64_t _val);
/**
* @brief get the current Spin increment.
* @return The current spin increment.
*/
int64_t getIncrement() const;
protected:
ewol::parameter::Value<int8_t> m_mantis; //!< number of value under '.' value
public:
/**
* @brief set the mantis value of the Spin
* @param[in] _val New mantis to set
*/
void setMantis(int8_t _val);
/**
* @brief get the current Spin mantis.
* @return The current spin mantis.
*/
int8_t getMantis() const;
protected:
virtual void checkValue(int64_t _value);
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);
virtual void updateGui();
protected:
void onCallbackUp();
void onCallbackDown();
};
};
};

View File

@ -11,6 +11,9 @@
#include <ewol/widget/Label.h>
#include <ewol/widget/Composer.h>
#undef __class__
#define __class__ "widget::SpinBase"
void ewol::widget::SpinBase::init(ewol::widget::Manager& _widgetManager) {
}
@ -62,6 +65,7 @@ void ewol::widget::SpinBase::onParameterChangeValue(const ewol::parameter::Ref&
void ewol::widget::SpinBase::updateGui() {
EWOL_WARNING("updateGui [START]");
subWidgetRemoveAll();
markToRedraw();
requestUpdateSize();
@ -69,6 +73,7 @@ void ewol::widget::SpinBase::updateGui() {
std::string shaper;
if (m_config != nullptr) {
shaper = m_config->getString(m_confIdEntryShaper);
EWOL_INFO("shaper entry : " << shaper);
}
m_widgetEntry = ewol::widget::Entry::create("", shaper);
if (m_widgetEntry != nullptr) {
@ -80,6 +85,7 @@ void ewol::widget::SpinBase::updateGui() {
std::string shaper;
if (m_config != nullptr) {
shaper = m_config->getString(m_confIdDownShaper);
EWOL_INFO("shaper button DOWN : " << shaper);
}
m_widgetButtonDown = ewol::widget::Button::create(shaper);
if (m_widgetButtonDown != nullptr) {
@ -94,6 +100,7 @@ void ewol::widget::SpinBase::updateGui() {
std::string shaper;
if (m_config != nullptr) {
shaper = m_config->getString(m_confIdUpShaper);
EWOL_INFO("shaper button UP : " << shaper);
}
m_widgetButtonUp = ewol::widget::Button::create(shaper);
if (m_widgetButtonUp != nullptr) {
@ -104,33 +111,56 @@ void ewol::widget::SpinBase::updateGui() {
m_widgetButtonUp->setSubWidget(widget);
}
}
EWOL_INFO("add ....");
switch (m_spinMode) {
case ewol::widget::spinPosition_noneNone:
EWOL_INFO("add Entry");
subWidgetAdd(m_widgetEntry);
break;
case ewol::widget::spinPosition_noneRight:
EWOL_INFO("add Entry");
subWidgetAdd(m_widgetEntry);
EWOL_INFO("add Up");
subWidgetAdd(m_widgetButtonUp);
break;
case ewol::widget::spinPosition_leftNone:
EWOL_INFO("add Down");
subWidgetAdd(m_widgetButtonDown);
EWOL_INFO("add Entry");
subWidgetAdd(m_widgetEntry);
break;
case ewol::widget::spinPosition_leftRight:
EWOL_INFO("add Down");
subWidgetAdd(m_widgetButtonDown);
EWOL_INFO("add Entry");
subWidgetAdd(m_widgetEntry);
EWOL_INFO("add Up");
subWidgetAdd(m_widgetButtonUp);
break;
case ewol::widget::spinPosition_leftLeft:
EWOL_INFO("add Down");
subWidgetAdd(m_widgetButtonDown);
EWOL_INFO("add Up");
subWidgetAdd(m_widgetButtonUp);
EWOL_INFO("add Entry");
subWidgetAdd(m_widgetEntry);
break;
case ewol::widget::spinPosition_RightRight:
EWOL_INFO("add Entry");
subWidgetAdd(m_widgetEntry);
EWOL_INFO("add Down");
subWidgetAdd(m_widgetButtonDown);
EWOL_INFO("add Up");
subWidgetAdd(m_widgetButtonUp);
break;
}
EWOL_WARNING("updateGui [STOP]");
}
bool ewol::widget::SpinBase::loadXML(const std::shared_ptr<const exml::Element>& _node) {
if (_node == nullptr) {
return false;
}
// parse generic properties: (we not parse the sizer property, it remove all subwidget)
return ewol::Widget::loadXML(_node);
}

View File

@ -81,8 +81,8 @@ namespace ewol {
* @param[in] _mode The mode to display the elements
*/
SpinBase();
void init(enum ewol::widget::spinPosition _mode=ewol::widget::spinPosition_RightRight,
const std::string& _shaperName="{ewol}THEME:GUI:Spin.json");
void init(enum ewol::widget::spinPosition _mode,
const std::string& _shaperName);
public:
/**
* @brief Destructor
@ -109,6 +109,7 @@ namespace ewol {
virtual void updateGui();
public: // Derived function
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);
virtual bool loadXML(const std::shared_ptr<const exml::Element>& _node);
};
}
}

View File

@ -201,6 +201,7 @@ def create(target, module_name):
'ewol/widget/WidgetScrolled.cpp',
'ewol/widget/Windows.cpp',
'ewol/widget/WSlider.cpp',
'ewol/widget/Spin.cpp',
])
my_module.add_header_file([
'ewol/widget/Menu.h',
@ -239,7 +240,8 @@ def create(target, module_name):
'ewol/widget/meta/FileChooser.h',
'ewol/widget/Image.h',
'ewol/widget/List.h',
'ewol/widget/Select.h'
'ewol/widget/Select.h',
'ewol/widget/Spin.h'
])
my_module.copy_path('data/theme/shape/square/*','theme/shape/square')

View File

@ -117,6 +117,10 @@ void appl::MainWindows::onCallbackWidgetChange(int32_t _increment) {
std::string tmpConstruct;
switch(m_idWidget) {
case 0:
tmpConstruct = "<spin/>\n";
tmpDescription = "Test ewol::widget::Spin";
break;
case 1:
tmpConstruct = std::string()
+ "<select>\n"
+ " <option id='1'>plop 1</option>\n"
@ -127,13 +131,6 @@ void appl::MainWindows::onCallbackWidgetChange(int32_t _increment) {
+ "</select>\n";
tmpDescription = "Test ewol::widget::Select";
break;
case 1:
tmpConstruct = std::string()
+ "<button name='[TEST]Button:TO-TEST' expand='false,false' fill='false,false' >\n"
+ " <label>My <font color='#FF0000'>Button</font> <br/> And Some under line<br/> plop <br/> and an other super long line ...</label>\n"
+ "</button>\n";
tmpDescription = "Test ewol::widget::Button";
break;
case 2:
tmpConstruct = "<ButtonColor/>";
tmpDescription = "Test ewol::widget::ButtonColor";
@ -158,6 +155,13 @@ void appl::MainWindows::onCallbackWidgetChange(int32_t _increment) {
tmpConstruct = "<slider/>\n";
tmpDescription = "Test ewol::widget::Entry";
break;
case 8:
tmpConstruct = std::string()
+ "<button name='[TEST]Button:TO-TEST' expand='false,false' fill='false,false' >\n"
+ " <label>My <font color='#FF0000'>Button</font> <br/> And Some under line<br/> plop <br/> and an other super long line ...</label>\n"
+ "</button>\n";
tmpDescription = "Test ewol::widget::Button";
break;
default:
tmpConstruct = "<label expand=false fill=false>Simple string</label>\n";
tmpDescription = "Test Label";