add menu example in playerground module
This commit is contained in:
parent
0fa61333fa
commit
ce3b02fa09
Binary file not shown.
After Width: | Height: | Size: 262 B |
|
@ -0,0 +1,10 @@
|
|||
Panel
|
||||
layout: verticalBox
|
||||
size: 64 48
|
||||
|
||||
MenuButton
|
||||
text: New
|
||||
|
||||
MenuButton
|
||||
text: Quit
|
||||
onClick: exit()
|
|
@ -0,0 +1,29 @@
|
|||
MenuButton < UIButton
|
||||
color: white
|
||||
size: 40 18
|
||||
align: center
|
||||
border-image:
|
||||
source: /core_styles/images/menu.png
|
||||
size: 64 24
|
||||
|
||||
state.hover:
|
||||
border-image:
|
||||
source: /core_styles/images/menu.png
|
||||
offset: 0 24
|
||||
size: 64 24
|
||||
color: black
|
||||
|
||||
TopMenuButton < MenuButton
|
||||
onMousePress: |
|
||||
function(self, mousePos, mouseButton)
|
||||
local popupMenu = UI.loadAndDisplay(self:getStyle()['popup menu'])
|
||||
if popupMenu then
|
||||
popupMenu:moveTo({ x = self:getX(), y = self:getY() + self:getHeight()})
|
||||
popupMenu.onMouseRelease = function(self) self:destroy() end
|
||||
end
|
||||
end
|
||||
|
||||
TopMenuButton
|
||||
text: File
|
||||
position: 80 0
|
||||
popup menu: /playground/filemenu.otui
|
|
@ -1 +1,10 @@
|
|||
-- place any code for testing purposes here
|
||||
-- place any code for testing purposes here
|
||||
|
||||
function displayMenuPopup(file, parent)
|
||||
end
|
||||
|
||||
local function init()
|
||||
UI.loadAndDisplay('/playground/menubar.otui')
|
||||
end
|
||||
|
||||
addEvent(init)
|
|
@ -48,6 +48,8 @@ void LuaInterface::registerFunctions()
|
|||
g_lua.bindClassMemberFunction<UIWidget>("getSize", &UIWidget::getSize);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setSize", &UIWidget::resize);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getPosition", &UIWidget::getPosition);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getX", &UIWidget::getX);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getY", &UIWidget::getY);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("moveTo", &UIWidget::moveTo);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("moveChildToIndex", &UIWidget::moveChildToIndex);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getParent", &UIWidget::getParent);
|
||||
|
@ -59,6 +61,7 @@ void LuaInterface::registerFunctions()
|
|||
g_lua.bindClassMemberFunction<UIWidget>("getOpacity", &UIWidget::getOpacity);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setOpacity", &UIWidget::setOpacity);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setStyle", &UIWidget::setStyle);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("applyStyle", &UIWidget::applyStyle);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getStyle", &UIWidget::getStyle);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getMarginTop", &UIWidget::getMarginTop);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setMarginTop", &UIWidget::setMarginTop);
|
||||
|
|
|
@ -252,6 +252,29 @@ void push_luavalue(const OTMLNodePtr& node)
|
|||
g_lua.pushNil();
|
||||
}
|
||||
|
||||
bool luavalue_cast(int index, OTMLNodePtr& node)
|
||||
{
|
||||
node = OTMLNode::create();
|
||||
node->setUnique(true);
|
||||
if(g_lua.isTable(index)) {
|
||||
g_lua.pushNil();
|
||||
while(g_lua.next(index < 0 ? index-1 : index)) {
|
||||
std::string cnodeName = g_lua.toString(-2);
|
||||
if(g_lua.isTable()) {
|
||||
OTMLNodePtr cnode;
|
||||
if(luavalue_cast(-1, node)) {
|
||||
cnode->setTag(cnodeName);
|
||||
node->addChild(cnode);
|
||||
}
|
||||
} else
|
||||
node->writeAt(cnodeName, g_lua.toString());
|
||||
g_lua.pop();
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// object ptr
|
||||
bool luavalue_cast(int index, LuaObjectPtr& obj) {
|
||||
if(g_lua.isUserdata(index)) {
|
||||
|
|
|
@ -70,6 +70,7 @@ bool luavalue_cast(int index, Size& size);
|
|||
|
||||
// otml nodes
|
||||
void push_luavalue(const OTMLNodePtr& node);
|
||||
bool luavalue_cast(int index, OTMLNodePtr& node);
|
||||
|
||||
// enum
|
||||
template<class T>
|
||||
|
|
|
@ -75,8 +75,10 @@ void UIWidget::setup()
|
|||
void UIWidget::destroy()
|
||||
{
|
||||
// remove itself from parent
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->removeChild(asUIWidget());
|
||||
if(UIWidgetPtr parent = getParent()) {
|
||||
if(parent->hasChild(asUIWidget()))
|
||||
parent->removeChild(asUIWidget());
|
||||
}
|
||||
setVisible(false);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
@ -680,10 +682,10 @@ void UIWidget::updateState(Fw::WidgetState state)
|
|||
|
||||
updateStyle();
|
||||
|
||||
if(state == Fw::FocusState)
|
||||
onFocusChange(newStatus, m_lastFocusReason);
|
||||
else if(state == Fw::HoverState)
|
||||
onHoverChange(newStatus);
|
||||
if(state == Fw::FocusState) {
|
||||
g_dispatcher.addEvent(std::bind(&UIWidget::onFocusChange, asUIWidget(), newStatus, m_lastFocusReason));
|
||||
} else if(state == Fw::HoverState)
|
||||
g_dispatcher.addEvent(std::bind(&UIWidget::onHoverChange, asUIWidget(), newStatus));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -884,6 +886,7 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
|
|||
anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge);
|
||||
}
|
||||
} else if(node->tag() == "onClick" ||
|
||||
node->tag() == "onMousePress" ||
|
||||
node->tag() == "onHoverChange") {
|
||||
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
|
||||
luaSetField(node->tag());
|
||||
|
|
Loading…
Reference in New Issue