[DEV] update menu interface

This commit is contained in:
Edouard DUPIN 2014-08-28 21:51:55 +02:00
parent 6bf0c0f0cd
commit d8ddb85a82
3 changed files with 40 additions and 19 deletions

2
build

@ -1 +1 @@
Subproject commit 885a60f22ce3dfde99819d3471a86fdbd3836237
Subproject commit 92c552fd59009e30388d9762b1c9e618193c8d16

View File

@ -21,7 +21,7 @@
ewol::widget::Menu::Menu() :
signalSelect(*this, "select") {
addObjectType("ewol::widget::Menu");
m_staticId = 0;
m_staticId = 666;
}
void ewol::widget::Menu::init() {
@ -54,22 +54,36 @@ void ewol::widget::Menu::clear() {
m_listElement.clear();
}
int32_t ewol::widget::Menu::addTitle(std::string _label,
std::string _image,
const std::string _message) {
int32_t ewol::widget::Menu::addTitle(const std::string& _label,
const std::string& _image,
const std::string& _message) {
return add(-1, _label, _image, _message);
}
static const char* eventButtonPressed = "menu-local-pressed";
int32_t ewol::widget::Menu::get(const std::string& _label) {
for (auto &it : m_listElement) {
if (it.m_label == _label) {
return it.m_localId;
}
}
return -1;
}
int32_t ewol::widget::Menu::add(int32_t _parent,
std::string _label,
std::string _image,
const std::string _message) {
const std::string& _label,
const std::string& _image,
const std::string& _message) {
// try to find one already created :
int32_t previous = get(_label);
if (previous != -1) {
return previous;
}
ewol::widget::MenuElement tmpObject;
tmpObject.m_localId = m_staticId++;
tmpObject.m_parentId = _parent;
tmpObject.m_label = std::string("<left>") + _label + "</left>";
tmpObject.m_label = _label;
tmpObject.m_image = _image;
tmpObject.m_message = _message;
if (-1 == tmpObject.m_parentId) {
@ -85,13 +99,12 @@ int32_t ewol::widget::Menu::add(int32_t _parent,
} else {
composeString+=" <image src=\"" + tmpObject.m_image + "\" size=\"8,8mm\"/>\n";
}
composeString+=" <label>" + tmpObject.m_label + "</label>\n";
composeString+=" <label><left>" + tmpObject.m_label + "</left></label>\n";
composeString+="</sizer>\n";
myButton->setSubWidget(ewol::widget::Composer::create(widget::Composer::String, composeString));
} else {
myButton->setSubWidget(ewol::widget::Label::create(tmpObject.m_label) );
myButton->setSubWidget(ewol::widget::Label::create("<left>" + tmpObject.m_label + "</left>") );
}
// add it in the widget list
ewol::widget::Sizer::subWidgetAdd(myButton);
// keep the specific event ...
@ -102,8 +115,14 @@ int32_t ewol::widget::Menu::add(int32_t _parent,
return tmpObject.m_localId;
}
void ewol::widget::Menu::addSpacer() {
EWOL_TODO("NOT now...");
void ewol::widget::Menu::remove(int32_t _id) {
EWOL_TODO("NOT remove...");
}
int32_t ewol::widget::Menu::addSpacer() {
EWOL_TODO("NOT addSpacer...");
return -1;
}
void ewol::widget::Menu::onButtonPressed(std::weak_ptr<ewol::widget::Button> _button) {
@ -188,7 +207,7 @@ void ewol::widget::Menu::onButtonPressed(std::weak_ptr<ewol::widget::Button> _bu
} else {
composeString+=" <image src=\"" + it2->m_image + "\" size=\"8,8mm\"/>\n";
}
composeString+=" <label exand=\"true,true\" fill=\"true,true\">" + it2->m_label + "</label>\n";
composeString+=" <label exand=\"true,true\" fill=\"true,true\"><left>" + it2->m_label + "</left></label>\n";
composeString+=" </sizer>\n";
composeString+="</composer>\n";
myButton->setSubWidget(ewol::widget::Composer::create(widget::Composer::String, composeString));
@ -198,7 +217,7 @@ void ewol::widget::Menu::onButtonPressed(std::weak_ptr<ewol::widget::Button> _bu
std::string("<composer expand=\"true,false\" fill=\"true,true\">\n") +
" <sizer mode=\"hori\" expand=\"true,false\" fill=\"true,true\" lock=\"true\">\n"
" <spacer min-size=\"8,0mm\"/>\n"
" <label exand=\"true,true\" fill=\"true,true\"><![CDATA[" + it2->m_label + "]]></label>\n"
" <label exand=\"true,true\" fill=\"true,true\"><![CDATA[<left>" + it2->m_label + "</left>]]></label>\n"
" </sizer>\n"
"</composer>\n"));
} else {

View File

@ -50,11 +50,13 @@ namespace ewol {
std::vector<ewol::widget::MenuElement> m_listElement;
int32_t m_staticId; // unique ID for every element of the menu ...
std::weak_ptr<ewol::widget::ContextMenu> m_widgetContextMenu;
int32_t get(const std::string& _label);
public:
void clear();
int32_t addTitle(std::string _label, std::string _image="", const std::string _message = "");
int32_t add(int32_t _parent, std::string _label, std::string _image="", const std::string _message = "");
void addSpacer();
int32_t addTitle(const std::string& _label, const std::string& _image="", const std::string& _message = "");
int32_t add(int32_t _parent, const std::string& _label, const std::string& _image="", const std::string& _message = "");
int32_t addSpacer();
void remove(int32_t _id);
private:
void onButtonPressed(std::weak_ptr<ewol::widget::Button> _button);
};