move charlist selection with arrows

This commit is contained in:
Eduardo Bart 2011-08-28 23:18:13 -03:00
parent c6b9aad87d
commit 6206eeb562
4 changed files with 40 additions and 0 deletions

View File

@ -26,6 +26,17 @@ local function createCharactersWindow(characters, premDays)
local charactersList = charactersWindow:getChildById('charactersList') local charactersList = charactersWindow:getChildById('charactersList')
local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel') local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
function charactersWindow:onKeyPress(keyCode, keyChar, keyboardModifiers)
if keyboardModifiers == KeyboardNoModifier then
if keyCode == KeyUp or keyCode == KeyTab then
charactersList:focusPreviousChild(ActiveFocusReason)
elseif keyCode == KeyDown then
charactersList:focusNextChild(ActiveFocusReason)
end
end
return false
end
for i,characterInfo in ipairs(characters) do for i,characterInfo in ipairs(characters) do
local characterName = characterInfo[1] local characterName = characterInfo[1]
local worldName = characterInfo[2] local worldName = characterInfo[2]

View File

@ -69,6 +69,8 @@ void LuaInterface::registerFunctions()
g_lua.bindClassMemberFunction<UIWidget>("removeChild", &UIWidget::removeChild); g_lua.bindClassMemberFunction<UIWidget>("removeChild", &UIWidget::removeChild);
g_lua.bindClassMemberFunction<UIWidget>("addChild", &UIWidget::addChild); g_lua.bindClassMemberFunction<UIWidget>("addChild", &UIWidget::addChild);
g_lua.bindClassMemberFunction<UIWidget>("focusChild", &UIWidget::focusChild); g_lua.bindClassMemberFunction<UIWidget>("focusChild", &UIWidget::focusChild);
g_lua.bindClassMemberFunction<UIWidget>("focusNextChild", &UIWidget::focusNextChild);
g_lua.bindClassMemberFunction<UIWidget>("focusPreviousChild", &UIWidget::focusPreviousChild);
g_lua.bindClassMemberFunction<UIWidget>("lockChild", &UIWidget::lockChild); g_lua.bindClassMemberFunction<UIWidget>("lockChild", &UIWidget::lockChild);
g_lua.bindClassMemberFunction<UIWidget>("updateLayout", &UIWidget::updateLayout); g_lua.bindClassMemberFunction<UIWidget>("updateLayout", &UIWidget::updateLayout);
g_lua.bindClassMemberFunction<UIWidget>("updateParentLayout", &UIWidget::updateParentLayout); g_lua.bindClassMemberFunction<UIWidget>("updateParentLayout", &UIWidget::updateParentLayout);

View File

@ -410,6 +410,32 @@ void UIWidget::focusNextChild(Fw::FocusReason reason)
focusChild(toFocus, reason); focusChild(toFocus, reason);
} }
void UIWidget::focusPreviousChild(Fw::FocusReason reason)
{
UIWidgetPtr toFocus;
UIWidgetList rotatedChildren(m_children);
std::reverse(m_children.begin(), m_children.end());
if(m_focusedChild) {
auto focusedIt = std::find(rotatedChildren.begin(), rotatedChildren.end(), m_focusedChild);
if(focusedIt != rotatedChildren.end()) {
std::rotate(rotatedChildren.begin(), focusedIt, rotatedChildren.end());
rotatedChildren.pop_front();
}
}
// finds next child to focus
for(const UIWidgetPtr& child : rotatedChildren) {
if(child->isFocusable()) {
toFocus = child;
break;
}
}
if(toFocus)
focusChild(toFocus, reason);
}
void UIWidget::moveChildToTop(const UIWidgetPtr& child) void UIWidget::moveChildToTop(const UIWidgetPtr& child)
{ {
if(!child) if(!child)

View File

@ -128,6 +128,7 @@ public:
void removeChild(const UIWidgetPtr& child); void removeChild(const UIWidgetPtr& child);
void focusChild(const UIWidgetPtr& child, Fw::FocusReason reason); void focusChild(const UIWidgetPtr& child, Fw::FocusReason reason);
void focusNextChild(Fw::FocusReason reason); void focusNextChild(Fw::FocusReason reason);
void focusPreviousChild(Fw::FocusReason reason);
void moveChildToTop(const UIWidgetPtr& child); void moveChildToTop(const UIWidgetPtr& child);
void lockChild(const UIWidgetPtr& child); void lockChild(const UIWidgetPtr& child);
void unlockChild(const UIWidgetPtr& child); void unlockChild(const UIWidgetPtr& child);