sel_index = i;
focus_index = i;
items[sel_index]->set_active(true);
- set_input_focus(items[focus_index]);
+ if(state&FOCUS)
+ set_input_focus(items[focus_index]);
signal_item_selected.emit(sel_index);
}
}
void List::focus_in()
{
- if(focus_index<0)
- focus_index = sel_index;
-
- if(focus_index>=0)
- {
- scroll_to_focus();
+ if(focus_index>=0 && items[focus_index]->is_visible())
set_input_focus(items[focus_index]);
+ else
+ {
+ if(sel_index>=0 && items[sel_index]->is_visible())
+ set_focus_index(sel_index);
+ else if(!items.empty())
+ set_focus_index(first);
}
}
bool List::navigate(Navigation nav)
{
- if(nav==NAV_UP)
+ if(nav==NAV_UP && !items.empty())
{
- if(focus_index<0 && !items.empty())
- focus_index = items.size()-1;
- else if(focus_index>0)
- --focus_index;
- else
- return false;
-
- scroll_to_focus();
- set_input_focus(items[focus_index]);
+ if(focus_index>0)
+ set_focus_index(focus_index-1);
}
- else if(nav==NAV_DOWN)
+ else if(nav==NAV_DOWN && !items.empty())
{
- if(focus_index<0 && !items.empty())
- focus_index = 0;
- else if(static_cast<unsigned>(focus_index+1)<items.size())
- ++focus_index;
- else
- return false;
-
- scroll_to_focus();
- set_input_focus(items[focus_index]);
+ if(static_cast<unsigned>(focus_index+1)<items.size())
+ set_focus_index(focus_index+1);
}
else if(nav==NAV_ACTIVATE)
set_selected_index(focus_index);
return true;
}
+void List::set_focus_index(int i)
+{
+ focus_index = i;
+ if(focus_index>=0)
+ {
+ scroll_to_focus();
+ if(state&FOCUS)
+ set_input_focus(items[focus_index]);
+ }
+}
+
void List::item_autosize_changed(Item *item)
{
item->autosize();
virtual void button_press(int, int, unsigned);
virtual void focus_in();
virtual bool navigate(Navigation);
-
private:
+ void set_focus_index(int);
+
void item_autosize_changed(Item *);
unsigned last_to_first(unsigned) const;
void check_view_range();