[DEV] A basic version of the Select widget (need to be finished)'

This commit is contained in:
Edouard DUPIN 2016-02-09 22:47:30 +01:00
parent 3aece8d7b8
commit 7f3e0735f6
10 changed files with 260 additions and 63 deletions

View File

@ -1,7 +1,5 @@
{
entry-shaper:"{ewol}THEME:GUI:SelectEntry.json",
up-shaper:"{ewol}THEME:GUI:SelectUp.json",
up-data:"<label>Up</label>",
down-shaper:"{ewol}THEME:GUI:SelectDown.json",
down-data:"<label>Down</label>",
up-shaper:"{ewol}THEME:GUI:SelectBt.json",
up-data:"<label>*</label>",
}

View File

@ -3,7 +3,7 @@
display-outside:false,
padding-out-left:0,
padding-out-right:0,
padding-out-right:1,
padding-out-top:1,
padding-out-buttom:1,

View File

@ -1,23 +0,0 @@
{
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

@ -11,6 +11,7 @@
#include <ewol/widget/ContextMenu.h>
#include <ewol/compositing/Drawing.h>
#include <ewol/widget/Manager.h>
#include <ewol/widget/Windows.h>
#include <ewol/Padding.h>
#undef __class__
@ -226,6 +227,10 @@ std::shared_ptr<ewol::Widget> ewol::widget::ContextMenu::getWidgetAtPos(const ve
return std::dynamic_pointer_cast<ewol::Widget>(shared_from_this());
}
void ewol::widget::ContextMenu::setShaperName(const std::string& _shaperName) {
m_shaper.set(_shaperName);
}
void ewol::widget::ContextMenu::onParameterChangeValue(const ewol::parameter::Ref& _paramPointer) {
ewol::widget::Container::onParameterChangeValue(_paramPointer);
if (_paramPointer == m_shaper) {
@ -236,3 +241,24 @@ void ewol::widget::ContextMenu::onParameterChangeValue(const ewol::parameter::Re
markToRedraw();
}
}
void ewol::widget::ContextMenu::setPositionMarkAuto(const vec2& _origin, const vec2& _size) {
std::shared_ptr<ewol::widget::Windows> windows = getWindows();
vec2 globalSize = windows->getSize();
// TODO : Support left and right
float upperSize = globalSize.y() - (_origin.y() + _size.y());
float underSize = globalSize.y() - _origin.y();
if (underSize >= upperSize) {
vec2 pos = _origin + _size - vec2(_size.x()*0.5f, 0.0f);
setPositionMark(ewol::widget::ContextMenu::markButtom, pos);
} else {
vec2 pos = _origin + vec2(_size.x()*0.5f, 0.0f);
setPositionMark(ewol::widget::ContextMenu::markTop, pos);
}
}
void ewol::widget::ContextMenu::setPositionMark(enum markPosition _position, const vec2& _arrowPos) {
m_arrawBorder.set(_position);
m_arrowPos.set(_arrowPos);
}

View File

@ -42,9 +42,7 @@ namespace ewol {
* @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.set(_shaperName);
}
void setShaperName(const std::string& _shaperName);
private:
// TODO : Rework the displayer ....
ewol::compositing::Drawing m_compositing;
@ -55,10 +53,8 @@ namespace ewol {
ewol::parameter::Value<vec2> m_arrowPos;
ewol::parameter::List<enum markPosition> m_arrawBorder;
public:
void setPositionMark(enum markPosition _position, const vec2& _arrowPos) {
m_arrawBorder.set(_position);
m_arrowPos.set(_arrowPos);
}
void setPositionMarkAuto(const vec2& _origin, const vec2& _size);
void setPositionMark(enum markPosition _position, const vec2& _arrowPos);
protected: // Derived function
virtual void onDraw();
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);

View File

@ -8,19 +8,26 @@
#include <ewol/debug.h>
#include <ewol/ewol.h>
#include <ewol/widget/Select.h>
#include <ewol/widget/ContextMenu.h>
#include <ewol/widget/Label.h>
#include <ewol/widget/Windows.h>
#undef __class__
#define __class__ "Select"
#define __class__ "widget::Select::Element"
// DEFINE for the shader display system :
#define STATUS_UP (0)
#define STATUS_HOVER (2)
#define STATUS_PRESSED (1)
#define STATUS_DOWN (3)
ewol::widget::Select::Element::Element(int32_t _value, std::string _name, bool _selected):
m_value(_value),
m_name(_name),
m_selected(_selected) {
}
#undef __class__
#define __class__ "widget::Select"
ewol::widget::Select::Select() :
signalValueString(*this, "valueString", "select value change in a sring mode"),
signalValue(*this, "value", "Select value change"),
m_value(*this, "value", false, "Value of the Select") {
addObjectType("ewol::widget::Select");
@ -41,9 +48,66 @@ void ewol::widget::Select::onParameterChangeValue(const ewol::parameter::Ref& _p
ewol::widget::SpinBase::onParameterChangeValue(_paramPointer);
if (_paramPointer == m_value) {
markToRedraw();
if (m_widgetEntry == nullptr) {
EWOL_ERROR("Can not acces at entry ...");
return;
}
for (auto &it : m_listElement) {
if (it.m_value == m_value.get()) {
if (it.m_selected == false) {
it.m_selected = true;
m_widgetEntry->setValue(it.m_name);
signalValue.emit(m_value.get());
}
} else {
it.m_selected = false;
}
}
}
}
void ewol::widget::Select::optionSelectDefault() {
if (m_widgetEntry == nullptr) {
EWOL_ERROR("Can not acces at entry ...");
return;
}
for (auto &it : m_listElement) {
if (it.m_selected == true) {
return;
}
}
if (m_listElement.size() == 0) {
m_widgetEntry->setValue("");
}
m_widgetEntry->setValue(m_listElement[0].m_name);
}
void ewol::widget::Select::optionRemove(int32_t _value) {
for (auto it=m_listElement.begin(); it != m_listElement.end(); ++it) {
if (_value == it->m_value) {
EWOL_DEBUG("remove element: " << _value);
m_listElement.erase(it);
break;
}
}
optionSelectDefault();
}
void ewol::widget::Select::optionClear() {
m_listElement.clear();
optionSelectDefault();
}
void ewol::widget::Select::optionAdd(int32_t _value, std::string _data) {
for (auto &it : m_listElement) {
if (_value == it.m_value) {
EWOL_DEBUG("replace element: " << _value << " with: '" << _data << "'");
it.m_name = _data;
}
}
m_listElement.push_back(ewol::widget::Select::Element(_value, _data, false));
}
bool ewol::widget::Select::loadXML(const std::shared_ptr<const exml::Element>& _node) {
if (_node == nullptr) {
return false;
@ -66,9 +130,87 @@ bool ewol::widget::Select::loadXML(const std::shared_ptr<const exml::Element>& _
std::string valId = pNode->getAttribute("id");
std::string valIsSelected = pNode->getAttribute("select");
std::string valText = pNode->getText();
int32_t id = etk::string_to_int32_t(valId);
int32_t select = etk::string_to_bool(valIsSelected);
optionAdd(id, valText);
if (select == true) {
setValue(id);
}
EWOL_WARNING("Add option : id='" << valId << "' select='" << valIsSelected << "' text='" << valText << "'");
}
return true;
}
void ewol::widget::Select::updateGui() {
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::Select::onCallbackOpenMenu);
}
}
void ewol::widget::Select::onCallbackLabelPressed(int32_t _value) {
EWOL_VERBOSE("User select:" << _value);
setValue(_value);
}
void ewol::widget::Select::onCallbackOpenMenu() {
// create a context menu:
std::shared_ptr<ewol::widget::ContextMenu> tmpContext = ewol::widget::ContextMenu::create();
if (tmpContext == nullptr) {
EWOL_ERROR("Allocation Error");
return;
}
// auto-select mark position:
tmpContext->setPositionMarkAuto(m_origin, m_size);
std::shared_ptr<ewol::widget::Sizer> mySizer;
mySizer = ewol::widget::Sizer::create(widget::Sizer::modeVert);
if (mySizer == nullptr) {
EWOL_ERROR("Allocation Error or sizer");
return;
}
mySizer->lockExpand(vec2(true,true));
mySizer->setFill(vec2(true,true));
// set it in the pop-up-system:
tmpContext->setSubWidget(mySizer);
for (auto &it : m_listElement) {
std::shared_ptr<ewol::widget::Label> myLabel;
if (it.m_selected == true) {
myLabel = ewol::widget::Label::create(std::string("<b>") + it.m_name + "</b>");
} else {
myLabel = ewol::widget::Label::create(it.m_name);
}
if (myLabel == nullptr) {
EWOL_ERROR("Allocation Error");
continue;
}
myLabel->setExpand(bvec2(true,true));
myLabel->setFill(bvec2(true,true));
// set callback
myLabel->signalPressed.bind(shared_from_this(), &ewol::widget::Select::onCallbackLabelPressed, it.m_value);
myLabel->signalPressed.bind(tmpContext, &ewol::widget::ContextMenu::destroy);
// add it in the widget list
mySizer->subWidgetAddStart(myLabel);
}
std::shared_ptr<ewol::widget::Windows> currentWindows = getWindows();
if (currentWindows == nullptr) {
EWOL_ERROR("Can not get the curent Windows...");
} else {
currentWindows->popUpWidgetPush(tmpContext);
}
}
void ewol::widget::Select::setValue(int32_t _val) {
m_value.set(_val);
}
bool ewol::widget::Select::getValue() const {
return m_value;
};

View File

@ -7,6 +7,7 @@
*/
#pragma once
#include <vector>
#include <etk/types.h>
#include <ewol/widget/meta/SpinBase.h>
@ -19,7 +20,6 @@ namespace ewol {
class Select : public ewol::widget::SpinBase {
public:
// Event list of properties
ewol::Signal<std::string> signalValueString;
ewol::Signal<int32_t> signalValue;
protected:
/**
@ -41,6 +41,21 @@ namespace ewol {
void setShaperName(const std::string& _shaperName) {
//m_shaper.setString(_shaperName);
}
protected:
class Element {
public:
int32_t m_value;
std::string m_name;
bool m_selected;
public:
Element(int32_t _value, std::string _name, bool _selected=false);
};
std::vector<ewol::widget::Select::Element> m_listElement;
public:
void optionSelectDefault();
void optionRemove(int32_t _value);
void optionClear();
void optionAdd(int32_t _value, std::string _name);
protected:
ewol::parameter::Value<int32_t> m_value; //!< Current state of the Select.
public:
@ -49,19 +64,20 @@ namespace ewol {
* @note Work only in toggle mode
* @param[in] _val New value of the Select
*/
void setValue(int32_t _val) {
m_value.set(_val);
}
void setValue(int32_t _val);
/**
* @brief get the current Select value.
* @return True : The Select is pressed.
* @return false : The Select is released.
*/
bool getValue() const {
return m_value;
};
bool getValue() const;
protected:
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);
virtual bool loadXML(const std::shared_ptr<const exml::Element>& _node);
virtual void updateGui();
protected:
void onCallbackOpenMenu();
void onCallbackLabelPressed(int32_t _value);
};
};
};

View File

@ -44,6 +44,7 @@ void ewol::widget::SpinBase::init(enum ewol::widget::spinPosition _mode,
m_confIdDownData = m_config->request("down-data");
}
m_spinMode = _mode;
setGravity(gravity_center);
updateGui();
}
@ -65,17 +66,21 @@ void ewol::widget::SpinBase::updateGui() {
markToRedraw();
requestUpdateSize();
if (m_widgetEntry == nullptr) {
// TODO : Check shaper pointer
std::string shaper = m_config->getString(m_confIdEntryShaper);
std::string shaper;
if (m_config != nullptr) {
shaper = m_config->getString(m_confIdEntryShaper);
}
m_widgetEntry = ewol::widget::Entry::create("", shaper);
if (m_widgetEntry != nullptr) {
m_widgetEntry->setExpand(bvec2(true,false));
m_widgetEntry->setFill(bvec2(true,true));
// TODO : Connect
}
}
if (m_widgetButtonDown == nullptr) {
std::string shaper = m_config->getString(m_confIdDownShaper);
std::string shaper;
if (m_config != nullptr) {
shaper = m_config->getString(m_confIdDownShaper);
}
m_widgetButtonDown = ewol::widget::Button::create(shaper);
if (m_widgetButtonDown != nullptr) {
m_widgetButtonDown->setExpand(bvec2(false,false));
@ -83,11 +88,13 @@ void ewol::widget::SpinBase::updateGui() {
std::string data = m_config->getString(m_confIdDownData);
std::shared_ptr<ewol::Widget> widget = ewol::widget::composerGenerate(ewol::widget::Composer::String, data);
m_widgetButtonDown->setSubWidget(widget);
// TODO : Connect
}
}
if (m_widgetButtonUp == nullptr) {
std::string shaper = m_config->getString(m_confIdUpShaper);
std::string shaper;
if (m_config != nullptr) {
shaper = m_config->getString(m_confIdUpShaper);
}
m_widgetButtonUp = ewol::widget::Button::create(shaper);
if (m_widgetButtonUp != nullptr) {
m_widgetButtonUp->setExpand(bvec2(false,false));
@ -95,7 +102,6 @@ void ewol::widget::SpinBase::updateGui() {
std::string data = m_config->getString(m_confIdUpData);
std::shared_ptr<ewol::Widget> widget = ewol::widget::composerGenerate(ewol::widget::Composer::String, data);
m_widgetButtonUp->setSubWidget(widget);
// TODO : Connect
}
}
switch (m_spinMode) {

View File

@ -106,7 +106,7 @@ namespace ewol {
std::shared_ptr<ewol::widget::Entry> m_widgetEntry;
std::shared_ptr<ewol::widget::Button> m_widgetButtonDown;
std::shared_ptr<ewol::widget::Button> m_widgetButtonUp;
void updateGui();
virtual void updateGui();
public: // Derived function
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);
};

View File

@ -22,6 +22,7 @@
#include <ewol/widget/Menu.h>
#include <ewol/widget/meta/FileChooser.h>
#include <ewol/widget/meta/Parameter.h>
#include <ewol/widget/Select.h>
#include <ewol/widget/Manager.h>
#include <ewol/context/Context.h>
#include <appl/TestButton.h>
@ -124,30 +125,38 @@ void appl::MainWindows::onCallbackWidgetChange(int32_t _increment) {
+ " <option id='4'>plop 4</option>\n"
+ " <option id='5'>plop 5</option>\n"
+ "</select>\n";
tmpDescription = "TestButton";
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 = "TestButton";
tmpDescription = "Test ewol::widget::Button";
break;
case 2:
tmpConstruct = "<ButtonColor/>";
tmpDescription = "TestButtonColor";
tmpDescription = "Test ewol::widget::ButtonColor";
break;
case 3:
tmpConstruct = "<label>Simple string</label>\n";
tmpDescription = "TestLabel";
tmpDescription = "Test ewol::widget::Label";
break;
case 4:
tmpConstruct = "<image src='DATA:sphere.png'/>\n";
tmpDescription = "TestImage";
tmpDescription = "Test ewol::widget::Image";
break;
case 5:
tmpConstruct = "<checkbox><label>Simple string</label></checkbox>\n";
tmpDescription = "TestCheckbox";
tmpDescription = "Test ewol::widget::Checkbox";
break;
case 6:
tmpConstruct = "<entry/>\n";
tmpDescription = "Test ewol::widget::Entry";
break;
case 7:
tmpConstruct = "<slider/>\n";
tmpDescription = "Test ewol::widget::Entry";
break;
default:
tmpConstruct = "<label expand=false fill=false>Simple string</label>\n";
@ -329,6 +338,33 @@ void appl::MainWindows::updateProperty() {
type = "double";
} else if (type == typeid(enum ewol::gravity).name()) {
type = "enum ewol::gravity";
std::shared_ptr<ewol::widget::Select> widgetTmp = ewol::widget::Select::create();
widgetSizer->subWidgetAdd(widgetTmp);
widgetTmp->setExpand(bvec2(true,false));
widgetTmp->setFill(bvec2(true,false));
widgetTmp->optionAdd(int32_t(ewol::gravity_center), "Center");
widgetTmp->optionAdd(int32_t(ewol::gravity_top), "Top");
widgetTmp->optionAdd(int32_t(ewol::gravity_buttom), "Buttom");
widgetTmp->optionAdd(int32_t(ewol::gravity_right), "Right");
widgetTmp->optionAdd(int32_t(ewol::gravity_left), "Left");
widgetTmp->optionAdd(int32_t(ewol::gravity_topRight), "Top-right");
widgetTmp->optionAdd(int32_t(ewol::gravity_topLeft), "Top-left");
widgetTmp->optionAdd(int32_t(ewol::gravity_buttomRight), "Buttom-right");
widgetTmp->optionAdd(int32_t(ewol::gravity_buttomLeft), "Buttom-left");
ewol::parameter::Parameter* param = m_subWidget->getParameterRaw(iii);
ewol::parameter::List<ewol::gravity>* paramValue = dynamic_cast<ewol::parameter::List<ewol::gravity>*>(param);
if (paramValue == nullptr) {
APPL_ERROR("nullptr... 2 ");
return;
}
ewol::gravity value = paramValue->get();
widgetTmp->setValue(value);
widgetTmp->signalValue.connect([=](const int32_t& _value) {
enum ewol::gravity val = ewol::gravity(_value);
APPL_INFO("set parameter: gravity name=" << param->getName() << " value=" << val);
paramValue->set(val);
return;
});
}
}
std::shared_ptr<ewol::widget::Spacer> mySpacer = ewol::widget::Spacer::create();