implement button tooltips on top menu

This commit is contained in:
Eduardo Bart
2011-11-03 17:07:07 -02:00
parent 5988867787
commit 1b9f9bbc7d
12 changed files with 123 additions and 5 deletions

View File

@@ -186,6 +186,16 @@ namespace luabinder
Tuple>(f);
}
template<typename Obj, typename Ret, typename... Args, typename... Holders>
LuaCppFunction bind_fun(const std::_Bind<std::_Mem_fn<Ret (Obj::*)(Args...) const>(Obj*, Holders...)>& f) {
typedef typename std::tuple<Args...> ArgsTuple;
typedef typename std::tuple<Holders...> HoldersTuple;
typedef typename get_holded_tuple<void, sizeof...(Holders), ArgsTuple, HoldersTuple>::type Tuple;
return bind_fun_specializer<typename remove_const_ref<Ret>::type,
decltype(f),
Tuple>(f);
}
/// Bind customized functions already bound by std::bind
template<typename Obj>
LuaCppFunction bind_fun(const std::_Bind<std::_Mem_fn<int (Obj::*)(LuaInterface*)>(Obj*, std::_Placeholder<1>)>& f) {

View File

@@ -26,6 +26,9 @@
#include <framework/net/protocol.h>
#include <framework/core/eventdispatcher.h>
#include <framework/core/configs.h>
#include <framework/platform/platform.h>
#include <framework/otml/otml.h>
#include <framework/graphics/graphics.h>
void LuaInterface::registerFunctions()
{
@@ -42,6 +45,10 @@ void LuaInterface::registerFunctions()
g_lua.bindClassMemberFunction<UIWidget>("setWidth", &UIWidget::setWidth);
g_lua.bindClassMemberFunction<UIWidget>("getHeight", &UIWidget::getHeight);
g_lua.bindClassMemberFunction<UIWidget>("setHeight", &UIWidget::setHeight);
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>("moveTo", &UIWidget::moveTo);
g_lua.bindClassMemberFunction<UIWidget>("getParent", &UIWidget::getParent);
g_lua.bindClassMemberFunction<UIWidget>("setParent", &UIWidget::setParent);
g_lua.bindClassMemberFunction<UIWidget>("getBackgroundColor", &UIWidget::getBackgroundColor);
@@ -51,6 +58,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>("getStyle", &UIWidget::getStyle);
g_lua.bindClassMemberFunction<UIWidget>("getMarginTop", &UIWidget::getMarginTop);
g_lua.bindClassMemberFunction<UIWidget>("setMarginTop", &UIWidget::setMarginTop);
g_lua.bindClassMemberFunction<UIWidget>("getMarginBottom", &UIWidget::getMarginBottom);
@@ -139,4 +147,6 @@ void LuaInterface::registerFunctions()
g_lua.bindGlobalFunction("getRootWidget", std::bind(&UIManager::getRootWidget, &g_ui));
g_lua.bindGlobalFunction("addEvent", std::bind(&EventDispatcher::addEvent, &g_dispatcher, _1, false));
g_lua.bindGlobalFunction("scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_dispatcher, _1, _2));
g_lua.bindGlobalFunction("getMouseCursorPos", std::bind(&Platform::getMouseCursorPos, &g_platform));
g_lua.bindGlobalFunction("getScreenSize", std::bind(&Graphics::getScreenSize, &g_graphics));
}

View File

@@ -199,6 +199,33 @@ bool luavalue_cast(int index, Point& point)
return true;
}
// size
void push_luavalue(const Size& size)
{
g_lua.newTable();
g_lua.pushInteger(size.width());
g_lua.setField("width");
g_lua.pushInteger(size.height());
g_lua.setField("height");
}
bool luavalue_cast(int index, Size& size)
{
if(g_lua.isTable(index)) {
g_lua.getField("width", index);
size.setWidth(g_lua.popInteger());
g_lua.getField("height", index);
size.setHeight(g_lua.popInteger());
return true;
} else if(g_lua.isString()) {
return Fw::cast(g_lua.toString(index), size);
} else if(g_lua.isNil()) {
size = Size();
return true;
}
return true;
}
// otml nodes
void push_luavalue(const OTMLNodePtr& node)
{

View File

@@ -53,9 +53,6 @@ void UIButton::onStyleApply(const OTMLNodePtr& styleNode)
m_textTranslate = node->value<Point>();
} else if(node->tag() == "text") {
m_text = node->value();
} else if(node->tag() == "onClick") {
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
luaSetField(node->tag());
}
}
}

View File

@@ -57,7 +57,7 @@ void UIVerticalLayout::update()
void UIVerticalLayout::addWidget(const UIWidgetPtr& widget)
{
// needed to be correcly sorted on update
// needed to be correctly sorted on the following update
widget->setY(9999);
update();
}

View File

@@ -841,6 +841,11 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge);
}
} else if(node->tag() == "onClick" ||
node->tag() == "onHoverChange") {
dump << node->tag();
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
luaSetField(node->tag());
}
}
}
@@ -858,6 +863,10 @@ void UIWidget::onFocusChange(bool focused, Fw::FocusReason reason)
void UIWidget::onHoverChange(bool hovered)
{
callLuaField("onHoverChange", hovered);
// check for new hovered elements when the current widget is removed
if(!hovered && !getParent())
g_ui.getRootWidget()->updateState(Fw::HoverState);
}
bool UIWidget::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)

View File

@@ -119,6 +119,7 @@ public:
int getMarginTop() const { return m_marginTop; }
int getMarginBottom() const { return m_marginBottom; }
Fw::FocusReason getLastFocusReason() const { return m_lastFocusReason; }
OTMLNodePtr getStyle() const { return m_style; }
UIWidgetList getChildren() const { return m_children; }
UIWidgetPtr getFocusedChild() const { return m_focusedChild; }