enable enter/escape actions for windows

This commit is contained in:
Eduardo Bart 2011-08-28 23:03:31 -03:00
parent d3cd4feee5
commit f54fd34cb3
8 changed files with 33 additions and 13 deletions

1
TODO
View File

@ -4,3 +4,4 @@ hotkeys events in lua
make password text edit hidden
load modules from zip packages
ip/host/rsa configuration
review directories search

View File

@ -33,6 +33,8 @@ function MessageBox.create(title, text, flags)
box.onOk()
box:destroy()
end
window.onEnter = buttonRight.onClick
window.onEscape = buttonRight.onClick
elseif flags == MessageBoxCancel then
buttonRight:setText("Cancel")
box.onCancel = EmptyFunction
@ -40,6 +42,8 @@ function MessageBox.create(title, text, flags)
box.onCancel()
box:destroy()
end
window.onEnter = buttonRight.onClick
window.onEscape = buttonRight.onClick
end
box.window = window

View File

@ -16,6 +16,8 @@ MainWindow
id: charactersWindow
title: Charlist
size: 250 250
onEnter: EnterGame_characterWindow_okClicked()
onEscape: function(self) self:destroy() end
TextList
id: charactersList
@ -63,7 +65,4 @@ MainWindow
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
onClick: |
function(self)
self:getParent():destroy()
end
onClick: function(self) self:getParent():destroy() end

View File

@ -2,6 +2,8 @@ MainWindow
id: enterGameWindow
title: Enter Game
size: 236 160
onEnter: EnterGame_connectToLoginServer()
onEscape: function(self) self:destroy() end
LargerLabel
text: Account name

View File

@ -33,8 +33,6 @@ UILineEdit::UILineEdit()
m_startRenderPos = 0;
m_textHorizontalMargin = 3;
blinkCursor();
m_onAction = [this]() { this->callLuaField("onAction"); };
}
void UILineEdit::render()
@ -365,9 +363,6 @@ void UILineEdit::onStyleApply(const OTMLNodePtr& styleNode)
if(node->tag() == "text") {
setText(node->value());
setCursorPos(m_text.length());
} else if(node->tag() == "onAction") {
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
luaSetField(node->tag());
}
}
}
@ -406,9 +401,6 @@ bool UILineEdit::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
else if(keyCode == Fw::KeyTab) {
if(UIWidgetPtr parent = getParent())
parent->focusNextChild(Fw::TabFocusReason);
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
if(m_onAction)
m_onAction();
} else if(keyChar != 0)
appendCharacter(keyChar);
else

View File

@ -67,7 +67,6 @@ private:
int m_startRenderPos;
int m_cursorTicks;
int m_textHorizontalMargin;
SimpleCallback m_onAction;
std::vector<Rect> m_glyphsCoords;
std::vector<Rect> m_glyphsTexCoords;

View File

@ -85,6 +85,14 @@ void UIWindow::onStyleApply(const OTMLNodePtr& styleNode)
else if(node->tag() == "title") {
setTitle(node->value());
}
else if(node->tag() == "onEnter") {
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
luaSetField(node->tag());
}
else if(node->tag() == "onEscape") {
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
luaSetField(node->tag());
}
}
}
@ -145,3 +153,17 @@ bool UIWindow::onMouseMove(const Point& mousePos, const Point& mouseMoved)
}
return UIWidget::onMouseMove(mousePos, mouseMoved);
}
bool UIWindow::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
{
if(keyboardModifiers == Fw::KeyboardNoModifier) {
if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
if(callLuaField<bool>("onEnter"))
return true;
} else if(keyCode == Fw::KeyEscape) {
if(callLuaField<bool>("onEscape"))
return true;
}
}
return UIWidget::onKeyPress(keyCode, keyChar, keyboardModifiers);
}

View File

@ -41,6 +41,7 @@ protected:
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
virtual bool onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers);
private:
std::string m_title;