185 views
in GUI Development by

I have created a class Application::OpModeList, which contains a Core::HorizontalList and a Core::KeyPressHandler as members.

My goal is to highlight/focus one element at a time by pressing the left/right keys (Core::KeyCode.Left and Core::KeyCode.Right).

If the list is empty, no element is to be shown/focused. If the list contains only one element, it is to be focused. If the list contains more than one element, the first one (index 0) is to be focused (initial state).

The number of list elements is queried via the Device Interface.

The list's ItemClass is a custom class "Application::ListTile".

The Hor. List is dynamically populated in the OnLoadItem() slot method.

Now when I want to focus a list item in the cursor key handler's "OnPress" slot, an exception is thrown "The view does not belong to this group":

if (mCursorKeyHandler.Code == Core::KeyCode.Left)
  if (mHorList.Item > 0)
    Focus = mHorList.GetViewForItem(mHorList.Item - 1);

callstack:

In the simple example "using-key-press-handler-2" provided in the EmWi documentation, the focused objects, for example "Slider", are members/attributes of the (parent) class which sets the "Focus" property:

Focus = Slider1;

However, this use case is too simple and not applicable for me, as I never know how many elements my list will contain.

So what is the correct way to focus the elements of a dynamically populated HorizontalList?

Thank You,

zeetrap

 

1 Answer

+1 vote
by

Hello zeetrap,

simply assign the number of the item you want to focus to the lists's property Selected. See also the section Select an item within the list. Also interesting for you would be the next following section Implement keyboard navigation. It demonstrates how to navigate (select/focus) items in response to key events.

I hope it helps you further.

Best regards

Paul Banach

Embedded Wizard Website | Privacy Policy | Imprint

...