enable enter/escape actions for windows
This commit is contained in:
parent
d3cd4feee5
commit
f54fd34cb3
1
TODO
1
TODO
|
@ -4,3 +4,4 @@ hotkeys events in lua
|
||||||
make password text edit hidden
|
make password text edit hidden
|
||||||
load modules from zip packages
|
load modules from zip packages
|
||||||
ip/host/rsa configuration
|
ip/host/rsa configuration
|
||||||
|
review directories search
|
|
@ -33,6 +33,8 @@ function MessageBox.create(title, text, flags)
|
||||||
box.onOk()
|
box.onOk()
|
||||||
box:destroy()
|
box:destroy()
|
||||||
end
|
end
|
||||||
|
window.onEnter = buttonRight.onClick
|
||||||
|
window.onEscape = buttonRight.onClick
|
||||||
elseif flags == MessageBoxCancel then
|
elseif flags == MessageBoxCancel then
|
||||||
buttonRight:setText("Cancel")
|
buttonRight:setText("Cancel")
|
||||||
box.onCancel = EmptyFunction
|
box.onCancel = EmptyFunction
|
||||||
|
@ -40,6 +42,8 @@ function MessageBox.create(title, text, flags)
|
||||||
box.onCancel()
|
box.onCancel()
|
||||||
box:destroy()
|
box:destroy()
|
||||||
end
|
end
|
||||||
|
window.onEnter = buttonRight.onClick
|
||||||
|
window.onEscape = buttonRight.onClick
|
||||||
end
|
end
|
||||||
|
|
||||||
box.window = window
|
box.window = window
|
||||||
|
|
|
@ -16,6 +16,8 @@ MainWindow
|
||||||
id: charactersWindow
|
id: charactersWindow
|
||||||
title: Charlist
|
title: Charlist
|
||||||
size: 250 250
|
size: 250 250
|
||||||
|
onEnter: EnterGame_characterWindow_okClicked()
|
||||||
|
onEscape: function(self) self:destroy() end
|
||||||
|
|
||||||
TextList
|
TextList
|
||||||
id: charactersList
|
id: charactersList
|
||||||
|
@ -63,7 +65,4 @@ MainWindow
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
margin.bottom: 16
|
margin.bottom: 16
|
||||||
margin.right: 16
|
margin.right: 16
|
||||||
onClick: |
|
onClick: function(self) self:getParent():destroy() end
|
||||||
function(self)
|
|
||||||
self:getParent():destroy()
|
|
||||||
end
|
|
|
@ -2,6 +2,8 @@ MainWindow
|
||||||
id: enterGameWindow
|
id: enterGameWindow
|
||||||
title: Enter Game
|
title: Enter Game
|
||||||
size: 236 160
|
size: 236 160
|
||||||
|
onEnter: EnterGame_connectToLoginServer()
|
||||||
|
onEscape: function(self) self:destroy() end
|
||||||
|
|
||||||
LargerLabel
|
LargerLabel
|
||||||
text: Account name
|
text: Account name
|
||||||
|
|
|
@ -33,8 +33,6 @@ UILineEdit::UILineEdit()
|
||||||
m_startRenderPos = 0;
|
m_startRenderPos = 0;
|
||||||
m_textHorizontalMargin = 3;
|
m_textHorizontalMargin = 3;
|
||||||
blinkCursor();
|
blinkCursor();
|
||||||
|
|
||||||
m_onAction = [this]() { this->callLuaField("onAction"); };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UILineEdit::render()
|
void UILineEdit::render()
|
||||||
|
@ -365,9 +363,6 @@ void UILineEdit::onStyleApply(const OTMLNodePtr& styleNode)
|
||||||
if(node->tag() == "text") {
|
if(node->tag() == "text") {
|
||||||
setText(node->value());
|
setText(node->value());
|
||||||
setCursorPos(m_text.length());
|
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) {
|
else if(keyCode == Fw::KeyTab) {
|
||||||
if(UIWidgetPtr parent = getParent())
|
if(UIWidgetPtr parent = getParent())
|
||||||
parent->focusNextChild(Fw::TabFocusReason);
|
parent->focusNextChild(Fw::TabFocusReason);
|
||||||
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
|
|
||||||
if(m_onAction)
|
|
||||||
m_onAction();
|
|
||||||
} else if(keyChar != 0)
|
} else if(keyChar != 0)
|
||||||
appendCharacter(keyChar);
|
appendCharacter(keyChar);
|
||||||
else
|
else
|
||||||
|
|
|
@ -67,7 +67,6 @@ private:
|
||||||
int m_startRenderPos;
|
int m_startRenderPos;
|
||||||
int m_cursorTicks;
|
int m_cursorTicks;
|
||||||
int m_textHorizontalMargin;
|
int m_textHorizontalMargin;
|
||||||
SimpleCallback m_onAction;
|
|
||||||
|
|
||||||
std::vector<Rect> m_glyphsCoords;
|
std::vector<Rect> m_glyphsCoords;
|
||||||
std::vector<Rect> m_glyphsTexCoords;
|
std::vector<Rect> m_glyphsTexCoords;
|
||||||
|
|
|
@ -85,6 +85,14 @@ void UIWindow::onStyleApply(const OTMLNodePtr& styleNode)
|
||||||
else if(node->tag() == "title") {
|
else if(node->tag() == "title") {
|
||||||
setTitle(node->value());
|
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);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ protected:
|
||||||
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
|
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
|
||||||
virtual bool onMouseRelease(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 onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
||||||
|
virtual bool onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_title;
|
std::string m_title;
|
||||||
|
|
Loading…
Reference in New Issue