MyGUI 3.2: Inject Key on MultiListBox

almondega

15-04-2012 23:10:15

Hi all, I'm trying to inject key press on a MultiListBox, to navigate the itens up or down.
This works fine for ListBox, but for MultiListBox I got no item selection at all.

Here is what I'm doing:

MyGUI::LayoutManager::getInstance().loadLayout("SpecialMenu.layout"); // TabControl with MultiLixBox
uiSpecialMenu = mGUI->findWidget<MyGUI::Window>("SpecialMenu"); // Getting the entire TabControl
uiSpecialMagic = uiSpecialMenu->findWidget("SpecialMagic")->castType<MyGUI::MultiListBox>(); // Getting the MultiLixBox
uiSpecialMagic->setIndexSelected(0);

...

MyGUI::InputManager::getInstance().setKeyFocusWidget(uiSpecialMagic); // This works
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::ArrowDown); // This doesn't work


Am I missing something?

Here is the layout:

<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout" version="3.2.0">
<Widget type="Window" skin="PanelEmpty" position="0 0 275 230" align="Center" layer="Main" name="SpecialMenu">
<Widget type="TabControl" skin="TabControl" position="0 0 275 230" name="Special">
<Property key="Alpha" value="0.8"/>
<Widget type="TabItem" skin="" position="2 24 269 202">
<Property key="Caption" value="Magic"/>
<Widget type="MultiListBox" skin="MultiListBox" position="5 5 260 195" align="Stretch" name="SpecialMagic">
<Property key="NeedKey" value="true"/>
<Widget type="MultiListItem" skin="" position="0 0 25 166" name="MagicTeste">
<Property key="ItemWidth" value="25"/>
<Property key="ItemResizingPolicy" value="Fixed"/>
</Widget>
<Widget type="MultiListItem" skin="" position="25 0 202 166">
<Property key="Caption" value="Name"/>
<Property key="ItemResizingPolicy" value="Fill"/>
</Widget>
<Widget type="MultiListItem" skin="" position="227 0 25 166">
<Property key="Caption" value="AP"/>
<Property key="ItemResizingPolicy" value="Fixed"/>
<Property key="ItemWidth" value="25"/>
</Widget>
</Widget>
</Widget>
<Widget type="TabItem" skin="" position="2 24 269 202">
<Property key="Caption" value="Skill"/>
<Widget type="MultiListBox" skin="MultiListBox" position="5 5 260 195" align="Stretch" name="SpecialSkill">
<Widget type="MultiListItem" skin="" position="0 0 25 166">
<Property key="ItemResizingPolicy" value="Fixed"/>
<Property key="ItemWidth" value="25"/>
</Widget>
<Widget type="MultiListItem" skin="" position="25 0 202 166">
<Property key="Caption" value="Name"/>
<Property key="ItemResizingPolicy" value="Fill"/>
</Widget>
<Widget type="MultiListItem" skin="" position="227 0 25 166">
<Property key="Caption" value="AP"/>
<Property key="ItemResizingPolicy" value="Fixed"/>
<Property key="ItemWidth" value="25"/>
</Widget>
</Widget>
</Widget>
</Widget>
</Widget>
</MyGUI>


Thanks.

Altren

16-04-2012 09:13:38

First of all you can use something like
if (uiSpecialMagic->getIndexSelected() != MyGUI::ITEM_NONE && uiSpecialMagic->getIndexSelected() < uiSpecialMagic->getItemCount() - 1)
uiSpecialMagic->setIndexSelected(uiSpecialMagic->getIndexSelected() + 1);

And what about pressing down - actually you need to focus inner part of Multilist, that's why injecting mouse down does nothing. Unfortunately it is not possible now. I guess we can change this behaviour to make inner part always have focus and react on pressed keys even if whole widget is focused.

almondega

17-04-2012 01:16:51

Thanks Altren!
I was hopping not to use IFs and Indexes to select the MultiListBox itens, but your suggestion worked fine, so I'm gonna use that for now :wink:

And what about pressing down - actually you need to focus inner part of Multilist, that's why injecting mouse down does nothing. Unfortunately it is not possible now. I guess we can change this behaviour to make inner part always have focus and react on pressed keys even if whole widget is focused.

Maybe in the next MyGUI update, since there are no reasons to focus a MultiListBox to get control on something else other than the MultiListItens.

Beside that, it't an amazing gui system, congratz!