init menu
This commit is contained in:
parent
a52ff707fe
commit
43c16a1643
|
@ -31,6 +31,10 @@ function UI.display(arg1, options)
|
||||||
widget:lock()
|
widget:lock()
|
||||||
elseif option == 'visible' then
|
elseif option == 'visible' then
|
||||||
widget:setVisible(value)
|
widget:setVisible(value)
|
||||||
|
elseif option == 'x' then
|
||||||
|
widget:setX(value)
|
||||||
|
elseif option == 'y' then
|
||||||
|
widget:setY(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,4 +16,5 @@ Module
|
||||||
importStyles 'styles/items.otui'
|
importStyles 'styles/items.otui'
|
||||||
importStyles 'styles/creatures.otui'
|
importStyles 'styles/creatures.otui'
|
||||||
importStyles 'styles/comboboxes.otui'
|
importStyles 'styles/comboboxes.otui'
|
||||||
|
importStyles 'styles/popupmenus.otui'
|
||||||
return true
|
return true
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 227 B |
|
@ -51,17 +51,3 @@ TopButton < UIButton
|
||||||
$disabled:
|
$disabled:
|
||||||
background-color: #ffffff66
|
background-color: #ffffff66
|
||||||
|
|
||||||
MenuButton < UIButton
|
|
||||||
color: white
|
|
||||||
size: 40 18
|
|
||||||
text-align: center
|
|
||||||
border-image:
|
|
||||||
source: /core_styles/images/menu.png
|
|
||||||
size: 64 24
|
|
||||||
|
|
||||||
$hover:
|
|
||||||
border-image:
|
|
||||||
source: /core_styles/images/menu.png
|
|
||||||
offset: 0 24
|
|
||||||
size: 64 24
|
|
||||||
color: black
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ RectPanel < UIWidget
|
||||||
FlatPanel < Panel
|
FlatPanel < Panel
|
||||||
border-image:
|
border-image:
|
||||||
source: /core_styles/images/panel_flat.png
|
source: /core_styles/images/panel_flat.png
|
||||||
border: 4
|
border: 1
|
||||||
|
|
||||||
TopPanel < Panel
|
TopPanel < Panel
|
||||||
height: 36
|
height: 36
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
PopupMenuButton < UIButton
|
||||||
|
font: verdana-11px-antialised
|
||||||
|
background-color: alpha
|
||||||
|
color: #aaaaaa
|
||||||
|
height: 18
|
||||||
|
margin-left: 3
|
||||||
|
margin-right: 3
|
||||||
|
|
||||||
|
image:
|
||||||
|
source: /core_styles/images/empty_rect.png
|
||||||
|
repeated: true
|
||||||
|
|
||||||
|
$hover:
|
||||||
|
color: #ffffff
|
||||||
|
background-color: #ffffff44
|
||||||
|
|
||||||
|
$disabled:
|
||||||
|
color: #555555
|
||||||
|
|
||||||
|
PopupMenuFirstButton < PopupMenuButton
|
||||||
|
margin-top: 3
|
||||||
|
|
||||||
|
PopupMenuLastButton < PopupMenuButton
|
||||||
|
margin-bottom: 3
|
||||||
|
|
||||||
|
PopupMenuSeparator < UIWidget
|
||||||
|
margin-left: 2
|
||||||
|
margin-right: 2
|
||||||
|
image:
|
||||||
|
source: /core_styles/images/menubox.png
|
||||||
|
repeated: true
|
||||||
|
coords: 3 0 26 3
|
||||||
|
height: 3
|
||||||
|
phantom: true
|
||||||
|
|
||||||
|
PopupMenu < UIPopupMenu
|
||||||
|
width: 100
|
||||||
|
border-image:
|
||||||
|
source: /core_styles/images/menubox.png
|
||||||
|
border: 3
|
|
@ -7,5 +7,6 @@ Module
|
||||||
onLoad: |
|
onLoad: |
|
||||||
require 'tooltip/tooltip'
|
require 'tooltip/tooltip'
|
||||||
require 'messagebox/messagebox'
|
require 'messagebox/messagebox'
|
||||||
require 'uicombobox/uicombobox'
|
require 'uicombobox'
|
||||||
|
require 'uipopupmenu'
|
||||||
return true
|
return true
|
|
@ -0,0 +1,34 @@
|
||||||
|
-- extends UIWidget
|
||||||
|
UIPopupMenu = extends(UIWidget)
|
||||||
|
|
||||||
|
-- public functions
|
||||||
|
function UIPopupMenu.create()
|
||||||
|
local menu = UIPopupMenu.internalCreate()
|
||||||
|
local layout = UIVerticalLayout.create(menu)
|
||||||
|
layout:setFitParent(true)
|
||||||
|
menu:setLayout(layout)
|
||||||
|
return menu
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIPopupMenu.display(otui, pos)
|
||||||
|
local menu = UI.display(otui, {x = pos.x, y = pos.y})
|
||||||
|
return menu
|
||||||
|
end
|
||||||
|
|
||||||
|
-- hooked events
|
||||||
|
local function onWidgetStyleApply(widget, style)
|
||||||
|
if style and style.popupmenu then
|
||||||
|
widget.popupmenu = style.popupmenu
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onWidgetMousePress(widget, mousePos, mouseButton)
|
||||||
|
if widget.popupmenu and mouseButton == MouseRightButton then
|
||||||
|
UIPopupMenu.display(widget.popupmenu, mousePos)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
connect(UIWidget, { onStyleApply = onWidgetStyleApply,
|
||||||
|
onMousePress = onWidgetMousePress })
|
|
@ -1,3 +1,6 @@
|
||||||
|
InvetoryItem < Item
|
||||||
|
popupmenu: /game_inventory/itempopupmenu.otui
|
||||||
|
|
||||||
UIWindow
|
UIWindow
|
||||||
width: 192
|
width: 192
|
||||||
margin-top: 10
|
margin-top: 10
|
||||||
|
@ -5,63 +8,62 @@ UIWindow
|
||||||
margin-right: 6
|
margin-right: 6
|
||||||
move-policy: free updated
|
move-policy: free updated
|
||||||
|
|
||||||
Item
|
InvetoryItem
|
||||||
id: head
|
id: head
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
popup menu: /inventory/itempopupmenu.otui
|
|
||||||
|
|
||||||
Item
|
InvetoryItem
|
||||||
id: armor
|
id: armor
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
Item
|
InvetoryItem
|
||||||
id: legs
|
id: legs
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
Item
|
InvetoryItem
|
||||||
id: feet
|
id: feet
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
Item
|
InvetoryItem
|
||||||
id: necklace
|
id: necklace
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.right: head.left
|
anchors.right: head.left
|
||||||
margin-top: 10
|
margin-top: 10
|
||||||
margin-right: 5
|
margin-right: 5
|
||||||
|
|
||||||
Item
|
InvetoryItem
|
||||||
id: left
|
id: left
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
Item
|
InvetoryItem
|
||||||
id: ring
|
id: ring
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
Item
|
InvetoryItem
|
||||||
id: backpack
|
id: backpack
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.left: head.right
|
anchors.left: head.right
|
||||||
margin-top: 10
|
margin-top: 10
|
||||||
margin-left: 5
|
margin-left: 5
|
||||||
|
|
||||||
Item
|
InvetoryItem
|
||||||
id: right
|
id: right
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
margin-top: 5
|
margin-top: 5
|
||||||
|
|
||||||
Item
|
InvetoryItem
|
||||||
id: ammo
|
id: ammo
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.horizontalCenter: prev.horizontalCenter
|
anchors.horizontalCenter: prev.horizontalCenter
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
Panel
|
PopupMenu
|
||||||
layout: verticalBox
|
PopupMenuFirstButton
|
||||||
size: 64 48
|
text: Look
|
||||||
|
PopupMenuLastButton
|
||||||
MenuButton
|
text: Use
|
||||||
text: Foo
|
|
||||||
|
|
||||||
MenuButton
|
|
||||||
text: Quit
|
|
||||||
@onClick: exit()
|
|
|
@ -45,7 +45,7 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("setPhantom", &UIWidget::setPhantom);
|
g_lua.bindClassMemberFunction<UIWidget>("setPhantom", &UIWidget::setPhantom);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("setStyle", &UIWidget::setStyle);
|
g_lua.bindClassMemberFunction<UIWidget>("setStyle", &UIWidget::setStyle);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("setStyleFromNode", &UIWidget::setStyleFromNode);
|
g_lua.bindClassMemberFunction<UIWidget>("setStyleFromNode", &UIWidget::setStyleFromNode);
|
||||||
//g_lua.bindClassMemberFunction<UIWidget>("setLayout", &UIWidget::setLayout);
|
g_lua.bindClassMemberFunction<UIWidget>("setLayout", &UIWidget::setLayout);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("setParent", &UIWidget::setParent);
|
g_lua.bindClassMemberFunction<UIWidget>("setParent", &UIWidget::setParent);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("setRect", &UIWidget::setRect);
|
g_lua.bindClassMemberFunction<UIWidget>("setRect", &UIWidget::setRect);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("setX", &UIWidget::setX);
|
g_lua.bindClassMemberFunction<UIWidget>("setX", &UIWidget::setX);
|
||||||
|
@ -89,7 +89,7 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild);
|
g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getId", &UIWidget::getId);
|
g_lua.bindClassMemberFunction<UIWidget>("getId", &UIWidget::getId);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getChildCount", &UIWidget::getChildCount);
|
g_lua.bindClassMemberFunction<UIWidget>("getChildCount", &UIWidget::getChildCount);
|
||||||
//g_lua.bindClassMemberFunction<UIWidget>("getLayout", &UIWidget::getLayout);
|
g_lua.bindClassMemberFunction<UIWidget>("getLayout", &UIWidget::getLayout);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getParent", &UIWidget::getParent);
|
g_lua.bindClassMemberFunction<UIWidget>("getParent", &UIWidget::getParent);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getRootParent", &UIWidget::getRootParent);
|
g_lua.bindClassMemberFunction<UIWidget>("getRootParent", &UIWidget::getRootParent);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getPosition", &UIWidget::getPosition);
|
g_lua.bindClassMemberFunction<UIWidget>("getPosition", &UIWidget::getPosition);
|
||||||
|
@ -141,6 +141,26 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("updateStyle", &UIWidget::updateStyle);
|
g_lua.bindClassMemberFunction<UIWidget>("updateStyle", &UIWidget::updateStyle);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("applyStyle", &UIWidget::applyStyle);
|
g_lua.bindClassMemberFunction<UIWidget>("applyStyle", &UIWidget::applyStyle);
|
||||||
|
|
||||||
|
// UILayout
|
||||||
|
g_lua.registerClass<UILayout>();
|
||||||
|
g_lua.bindClassMemberFunction<UILayout>("applyStyle", &UILayout::applyStyle);
|
||||||
|
g_lua.bindClassMemberFunction<UILayout>("update", &UILayout::update);
|
||||||
|
g_lua.bindClassMemberFunction<UILayout>("addWidget", &UILayout::addWidget);
|
||||||
|
g_lua.bindClassMemberFunction<UILayout>("removeWidget", &UILayout::removeWidget);
|
||||||
|
g_lua.bindClassMemberFunction<UILayout>("getParentWidget", &UILayout::getParentWidget);
|
||||||
|
|
||||||
|
// UIVerticalLayout
|
||||||
|
g_lua.registerClass<UIVerticalLayout, UILayout>();
|
||||||
|
g_lua.bindClassStaticFunction<UILayout>("create", &UIVerticalLayout::create);
|
||||||
|
g_lua.bindClassMemberFunction<UIVerticalLayout>("setFitParent", &UIVerticalLayout::setFitParent);
|
||||||
|
|
||||||
|
// UIAnchorLayout
|
||||||
|
g_lua.registerClass<UIAnchorLayout, UILayout>();
|
||||||
|
g_lua.bindClassStaticFunction<UIAnchorLayout>("create", &UIAnchorLayout::create);
|
||||||
|
g_lua.bindClassMemberFunction<UIAnchorLayout>("removeAnchors", &UIAnchorLayout::removeAnchors);
|
||||||
|
g_lua.bindClassMemberFunction<UIAnchorLayout>("centerIn", &UIAnchorLayout::centerIn);
|
||||||
|
g_lua.bindClassMemberFunction<UIAnchorLayout>("fill", &UIAnchorLayout::fill);
|
||||||
|
|
||||||
// UILabel
|
// UILabel
|
||||||
g_lua.registerClass<UILabel, UIWidget>();
|
g_lua.registerClass<UILabel, UIWidget>();
|
||||||
g_lua.bindClassStaticFunction<UILabel>("create", &UIWidget::create<UILabel>);
|
g_lua.bindClassStaticFunction<UILabel>("create", &UIWidget::create<UILabel>);
|
||||||
|
|
|
@ -445,7 +445,7 @@ int LuaInterface::protectedCall(int numArgs, int requestedResults)
|
||||||
}
|
}
|
||||||
pop(numArgs + 1); // pops the table of function and arguments
|
pop(numArgs + 1); // pops the table of function and arguments
|
||||||
|
|
||||||
if(requestedResults == -1 || requestedResults == 1) {
|
if(requestedResults == 1) {
|
||||||
numRets = 1;
|
numRets = 1;
|
||||||
pushBoolean(done);
|
pushBoolean(done);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "declarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
/// All OTML errors throw this exception
|
/// All OTML errors throw this exception
|
||||||
class OTMLException : public std::exception
|
class OTMLException : public Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OTMLException(const OTMLNodePtr& node, const std::string& error);
|
OTMLException(const OTMLNodePtr& node, const std::string& error);
|
||||||
|
|
|
@ -32,5 +32,8 @@
|
||||||
#include "uiframecounter.h"
|
#include "uiframecounter.h"
|
||||||
#include "uiprogressbar.h"
|
#include "uiprogressbar.h"
|
||||||
#include "uicheckbox.h"
|
#include "uicheckbox.h"
|
||||||
|
#include "uilayout.h"
|
||||||
|
#include "uiverticallayout.h"
|
||||||
|
#include "uianchorlayout.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -62,6 +62,7 @@ class UIAnchorLayout : public UILayout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UIAnchorLayout(UIWidgetPtr parentWidget) : UILayout(parentWidget) { }
|
UIAnchorLayout(UIWidgetPtr parentWidget) : UILayout(parentWidget) { }
|
||||||
|
static UIAnchorLayoutPtr create(UIWidgetPtr parentWidget) { return UIAnchorLayoutPtr(new UIAnchorLayout(parentWidget)); }
|
||||||
|
|
||||||
void addAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge,
|
void addAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge,
|
||||||
const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge);
|
const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge);
|
||||||
|
|
|
@ -108,14 +108,17 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
boost::trim(base);
|
boost::trim(base);
|
||||||
|
|
||||||
// TODO: styles must be searched by widget scopes, in that way this warning could be fixed
|
// TODO: styles must be searched by widget scopes, in that way this warning could be fixed
|
||||||
// disable this warning because many ppl was complening about it
|
// this warning is disabled because many ppl was complening about it
|
||||||
/*
|
/*
|
||||||
auto it = m_styles.find(name);
|
auto it = m_styles.find(name);
|
||||||
if(it != m_styles.end())
|
if(it != m_styles.end())
|
||||||
logWarning("style '", name, "' is being redefined");
|
logWarning("style '", name, "' is being redefined");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
OTMLNodePtr style = getStyle(base)->clone();
|
OTMLNodePtr originalStyle = getStyle(base);
|
||||||
|
if(!originalStyle)
|
||||||
|
Fw::throwException("base style '", base, "' is not defined");
|
||||||
|
OTMLNodePtr style = originalStyle->clone();
|
||||||
style->merge(styleNode);
|
style->merge(styleNode);
|
||||||
style->setTag(name);
|
style->setTag(name);
|
||||||
m_styles[name] = style;
|
m_styles[name] = style;
|
||||||
|
@ -123,19 +126,18 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
|
|
||||||
OTMLNodePtr UIManager::getStyle(const std::string& styleName)
|
OTMLNodePtr UIManager::getStyle(const std::string& styleName)
|
||||||
{
|
{
|
||||||
|
auto it = m_styles.find(styleName);
|
||||||
|
if(it != m_styles.end())
|
||||||
|
return m_styles[styleName];
|
||||||
|
|
||||||
|
// styles starting with UI are automatically defined
|
||||||
if(boost::starts_with(styleName, "UI")) {
|
if(boost::starts_with(styleName, "UI")) {
|
||||||
OTMLNodePtr node = OTMLNode::create();
|
OTMLNodePtr node = OTMLNode::create();
|
||||||
node->writeAt("__widgetType", styleName);
|
node->writeAt("__widgetType", styleName);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = m_styles.find(styleName);
|
|
||||||
if(it == m_styles.end()) {
|
|
||||||
logError("Unable to retrive style '", styleName, "': not a defined style");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
return m_styles[styleName];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent)
|
UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent)
|
||||||
|
@ -165,7 +167,11 @@ UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent
|
||||||
|
|
||||||
UIWidgetPtr UIManager::loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent)
|
UIWidgetPtr UIManager::loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent)
|
||||||
{
|
{
|
||||||
OTMLNodePtr styleNode = getStyle(widgetNode->tag())->clone();
|
OTMLNodePtr originalStyleNode = getStyle(widgetNode->tag());
|
||||||
|
if(!originalStyleNode)
|
||||||
|
Fw::throwException("'", widgetNode->tag(), "' is not a defined style");
|
||||||
|
|
||||||
|
OTMLNodePtr styleNode = originalStyleNode->clone();
|
||||||
styleNode->merge(widgetNode);
|
styleNode->merge(widgetNode);
|
||||||
|
|
||||||
std::string widgetType = styleNode->valueAt("__widgetType");
|
std::string widgetType = styleNode->valueAt("__widgetType");
|
||||||
|
@ -183,7 +189,7 @@ UIWidgetPtr UIManager::loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const U
|
||||||
loadWidgetFromOTML(childNode, widget);
|
loadWidgetFromOTML(childNode, widget);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
logError("Unable to create widget of type '", widgetType, "'");
|
Fw::throwException("unable to create widget of type '", widgetType, "'");
|
||||||
|
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ UIVerticalLayout::UIVerticalLayout(UIWidgetPtr parentWidget)
|
||||||
: UILayout(parentWidget)
|
: UILayout(parentWidget)
|
||||||
{
|
{
|
||||||
m_alignBottom = false;
|
m_alignBottom = false;
|
||||||
m_padding = 0;
|
m_fitParent = false;
|
||||||
|
m_spacing = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
|
void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
|
||||||
|
@ -37,9 +38,11 @@ void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
|
||||||
|
|
||||||
for(const OTMLNodePtr& node : styleNode->children()) {
|
for(const OTMLNodePtr& node : styleNode->children()) {
|
||||||
if(node->tag() == "align-bottom")
|
if(node->tag() == "align-bottom")
|
||||||
m_alignBottom = node->value<bool>();
|
setAlignBottom(node->value<bool>());
|
||||||
else if(node->tag() == "padding")
|
else if(node->tag() == "spacing")
|
||||||
m_padding = node->value<int>();
|
setSpacing(node->value<int>());
|
||||||
|
else if(node->tag() == "fit-parent")
|
||||||
|
setFitParent(node->value<bool>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,24 +55,41 @@ void UIVerticalLayout::update()
|
||||||
std::reverse(widgets.begin(), widgets.end());
|
std::reverse(widgets.begin(), widgets.end());
|
||||||
|
|
||||||
Point pos = (m_alignBottom) ? parentWidget->getRect().bottomLeft() : parentWidget->getPosition();
|
Point pos = (m_alignBottom) ? parentWidget->getRect().bottomLeft() : parentWidget->getPosition();
|
||||||
|
int prefferedHeight = 0;
|
||||||
|
int gap;
|
||||||
|
|
||||||
for(const UIWidgetPtr& widget : widgets) {
|
for(const UIWidgetPtr& widget : widgets) {
|
||||||
if(!widget->isExplicitlyVisible())
|
if(!widget->isExplicitlyVisible())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Size size = widget->getSize();
|
Size size = widget->getSize();
|
||||||
pos.y += (m_alignBottom) ? -(widget->getMarginBottom()+widget->getHeight()) : widget->getMarginTop();
|
|
||||||
|
gap = (m_alignBottom) ? -(widget->getMarginBottom()+widget->getHeight()) : widget->getMarginTop();
|
||||||
|
pos.y += gap;
|
||||||
|
prefferedHeight += gap;
|
||||||
|
|
||||||
if(widget->isSizeFixed()) {
|
if(widget->isSizeFixed()) {
|
||||||
|
// center it
|
||||||
pos.x = parentWidget->getX() + (parentWidget->getWidth() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
|
pos.x = parentWidget->getX() + (parentWidget->getWidth() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
|
||||||
pos.x = std::max(pos.x, parentWidget->getX());
|
pos.x = std::max(pos.x, parentWidget->getX());
|
||||||
} else {
|
} else {
|
||||||
|
// expand width
|
||||||
size.setWidth(parentWidget->getWidth() - (widget->getMarginLeft() + widget->getMarginRight()));
|
size.setWidth(parentWidget->getWidth() - (widget->getMarginLeft() + widget->getMarginRight()));
|
||||||
pos.x = std::max(pos.x, parentWidget->getX() + (parentWidget->getWidth() - size.width())/2);
|
pos.x = parentWidget->getX() + (parentWidget->getWidth() - size.width())/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
widget->setRect(Rect(pos, size));
|
widget->setRect(Rect(pos, size));
|
||||||
pos.y += (m_alignBottom) ? -widget->getMarginTop() : (widget->getHeight() + widget->getMarginBottom());
|
|
||||||
pos.y += m_padding;
|
gap = (m_alignBottom) ? -widget->getMarginTop() : (widget->getHeight() + widget->getMarginBottom());
|
||||||
|
gap += m_spacing;
|
||||||
|
pos.y += gap;
|
||||||
|
prefferedHeight += gap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefferedHeight -= m_spacing;
|
||||||
|
|
||||||
|
if(m_fitParent && prefferedHeight != parentWidget->getHeight())
|
||||||
|
parentWidget->setHeight(prefferedHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIVerticalLayout::addWidget(const UIWidgetPtr& widget)
|
void UIVerticalLayout::addWidget(const UIWidgetPtr& widget)
|
||||||
|
@ -81,3 +101,22 @@ void UIVerticalLayout::removeWidget(const UIWidgetPtr& widget)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIVerticalLayout::setAlignBottom(bool aliginBottom)
|
||||||
|
{
|
||||||
|
m_alignBottom = aliginBottom;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIVerticalLayout::setSpacing(int spacing)
|
||||||
|
{
|
||||||
|
m_spacing = spacing;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIVerticalLayout::setFitParent(bool fitParent)
|
||||||
|
{
|
||||||
|
m_fitParent = fitParent;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,15 +29,21 @@ class UIVerticalLayout : public UILayout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UIVerticalLayout(UIWidgetPtr parentWidget);
|
UIVerticalLayout(UIWidgetPtr parentWidget);
|
||||||
|
static UIVerticalLayoutPtr create(UIWidgetPtr parentWidget) { return UIVerticalLayoutPtr(new UIVerticalLayout(parentWidget)); }
|
||||||
|
|
||||||
virtual void applyStyle(const OTMLNodePtr& styleNode);
|
virtual void applyStyle(const OTMLNodePtr& styleNode);
|
||||||
virtual void update();
|
virtual void update();
|
||||||
virtual void addWidget(const UIWidgetPtr& widget);
|
virtual void addWidget(const UIWidgetPtr& widget);
|
||||||
virtual void removeWidget(const UIWidgetPtr& widget);
|
virtual void removeWidget(const UIWidgetPtr& widget);
|
||||||
|
|
||||||
|
void setAlignBottom(bool aliginBottom);
|
||||||
|
void setSpacing(int spacing);
|
||||||
|
void setFitParent(bool fitParent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_alignBottom;
|
bool m_alignBottom;
|
||||||
int m_padding;
|
bool m_fitParent;
|
||||||
|
int m_spacing;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -142,8 +142,10 @@ void UIWidget::setFocusable(bool focusable)
|
||||||
void UIWidget::setStyle(const std::string& styleName)
|
void UIWidget::setStyle(const std::string& styleName)
|
||||||
{
|
{
|
||||||
OTMLNodePtr styleNode = g_ui.getStyle(styleName);
|
OTMLNodePtr styleNode = g_ui.getStyle(styleName);
|
||||||
if(!styleNode)
|
if(!styleNode) {
|
||||||
|
logTraceError("unable to retrive style '", styleName, "': not a defined style");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
applyStyle(styleNode);
|
applyStyle(styleNode);
|
||||||
m_style = styleNode;
|
m_style = styleNode;
|
||||||
updateStyle();
|
updateStyle();
|
||||||
|
@ -372,7 +374,7 @@ void UIWidget::addChild(const UIWidgetPtr& child)
|
||||||
|
|
||||||
// create default layout
|
// create default layout
|
||||||
if(!m_layout)
|
if(!m_layout)
|
||||||
m_layout = UILayoutPtr(new UIAnchorLayout(asUIWidget()));
|
m_layout = UIAnchorLayout::create(asUIWidget());
|
||||||
|
|
||||||
// add to layout and updates it
|
// add to layout and updates it
|
||||||
m_layout->addWidget(child);
|
m_layout->addWidget(child);
|
||||||
|
@ -404,7 +406,7 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child)
|
||||||
|
|
||||||
// create default layout if needed
|
// create default layout if needed
|
||||||
if(!m_layout)
|
if(!m_layout)
|
||||||
m_layout = UILayoutPtr(new UIAnchorLayout(asUIWidget()));
|
m_layout = UIAnchorLayout::create(asUIWidget());
|
||||||
|
|
||||||
// add to layout and updates it
|
// add to layout and updates it
|
||||||
m_layout->addWidget(child);
|
m_layout->addWidget(child);
|
||||||
|
@ -869,26 +871,25 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
|
||||||
}
|
}
|
||||||
// layouts
|
// layouts
|
||||||
else if(node->tag() == "layout") {
|
else if(node->tag() == "layout") {
|
||||||
// layout is set only once
|
|
||||||
assert(!m_layout);
|
|
||||||
|
|
||||||
std::string layoutType;
|
std::string layoutType;
|
||||||
if(node->hasValue())
|
if(node->hasValue())
|
||||||
layoutType = node->value();
|
layoutType = node->value();
|
||||||
else
|
else
|
||||||
layoutType = node->valueAt("type");
|
layoutType = node->valueAt<std::string>("type", "");
|
||||||
|
|
||||||
|
if(!layoutType.empty()) {
|
||||||
UILayoutPtr layout;
|
UILayoutPtr layout;
|
||||||
if(layoutType == "verticalBox")
|
if(layoutType == "verticalBox")
|
||||||
layout = UILayoutPtr(new UIVerticalLayout(asUIWidget()));
|
layout = UIVerticalLayout::create(asUIWidget());
|
||||||
else if(layoutType == "anchor")
|
else if(layoutType == "anchor")
|
||||||
layout = UILayoutPtr(new UIAnchorLayout(asUIWidget()));
|
layout = UIAnchorLayout::create(asUIWidget());
|
||||||
else
|
else
|
||||||
throw OTMLException(node, "cannot determine layout type");
|
throw OTMLException(node, "cannot determine layout type");
|
||||||
|
setLayout(layout);
|
||||||
|
}
|
||||||
|
|
||||||
if(node->hasChildren())
|
if(node->hasChildren())
|
||||||
layout->applyStyle(node);
|
m_layout->applyStyle(node);
|
||||||
setLayout(layout);
|
|
||||||
}
|
}
|
||||||
// anchors
|
// anchors
|
||||||
else if(boost::starts_with(node->tag(), "anchors.")) {
|
else if(boost::starts_with(node->tag(), "anchors.")) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ for line in io.lines(cppclassheader) do
|
||||||
elseif line:match('private:') or line:match('protected:') then
|
elseif line:match('private:') or line:match('protected:') then
|
||||||
publicmethods = false
|
publicmethods = false
|
||||||
elseif publicmethods then
|
elseif publicmethods then
|
||||||
funcname, args = line:match('^ *[%w <>&\*:_]* ([%w_]+)%(([^%)]*%))[%w ]*[;{].*$')
|
funcname, args = line:match('^ *[%w <>&\*:_]* ([%w_]+)%(([^%)]*%))[%w ]*[;{=].*$')
|
||||||
if funcname then
|
if funcname then
|
||||||
if funcname ~= cppclassname and funcname ~= 'create' then
|
if funcname ~= cppclassname and funcname ~= 'create' then
|
||||||
numargs = args:matchcount('[^,)]+[,)]')
|
numargs = args:matchcount('[^,)]+[,)]')
|
||||||
|
|
Loading…
Reference in New Issue