void thorizontal_list::handle_key_right_arrow(SDLMod /*modifier*/, bool& handled) { if(get_selected_item_count() == 0) { return; } // NOTE maybe this should only work if we can select only one item... handled = true; for(size_t i = get_ordered_index(get_selected_item()) + 1; i < get_item_count(); ++i) { if(item(get_item_at_ordered(i)).get_visible() == twidget::tvisible::invisible || !get_item_shown(get_item_at_ordered(i))) { continue; } // NOTE we check the first widget to be active since grids have no // active flag. This method might not be entirely reliable. tcontrol* control = dynamic_cast<tcontrol*>(item(get_item_at_ordered(i)).widget(0, 0)); if(control && control->get_active()) { select_item(get_item_at_ordered(i), true); return; } } }
void tvertical_list::place(const tpoint& origin, const tpoint& size) { /* * - Set every item to its best size. * - The origin gets increased with the height of the last item. * - No item should be wider as the size. * - In the end the origin should be the sum or the origin and the wanted * height. */ tpoint current_origin = origin; for(size_t i = 0; i < get_item_count(); ++i) { tgrid& grid = item_ordered(i); if(grid.get_visible() == twidget::tvisible::invisible || !get_item_shown(get_item_at_ordered(i))) { continue; } tpoint best_size = grid.get_best_size(); assert(best_size.x <= size.x); // FIXME should we look at grow factors??? best_size.x = size.x; grid.place(current_origin, best_size); current_origin.y += best_size.y; } assert(current_origin.y == origin.y + size.y); }
/** Returns the visibility of all the items as a bit set. */ boost::dynamic_bitset<> get_items_shown() const { boost::dynamic_bitset<> items_shown(get_item_count()); for (unsigned int i = 0u; i < get_item_count(); ++i) { items_shown[i] = get_item_shown(i); } return items_shown; }
void tvertical_list::set_origin(const tpoint& origin) { tpoint current_origin = origin; for(size_t i = 0; i < get_item_count(); ++i) { tgrid& grid = item(i); if(grid.get_visible() == twidget::INVISIBLE || !get_item_shown(i)) { continue; } grid.set_origin(current_origin); current_origin.y += grid.get_height(); } }
const twidget* tvertical_list::find_at(const tpoint& coordinate, const bool must_be_active) const { assert(get_window()); for(size_t i = 0; i < get_item_count(); ++i) { const tgrid& grid = item(i); if(grid.get_visible() == twidget::INVISIBLE || !get_item_shown(i)) { continue; } const twidget* widget = grid.find_at(coordinate, must_be_active); if(widget) { return widget; } } return NULL; }
tpoint tvertical_list::calculate_best_size() const { // The best size is the sum of the heights and the greatest width. tpoint result(0, 0); for(size_t i = 0; i < get_item_count(); ++i) { const tgrid& grid = item(i); if(grid.get_visible() == twidget::INVISIBLE || !get_item_shown(i)) { continue; } const tpoint best_size = grid.get_best_size(); if(best_size.x > result.x) { result.x = best_size.x; } result.y += best_size.y; } return result; }