More attempts at tweaking ribbon row-count decision formula
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8698 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
da85204faf
commit
255a9d5619
@ -53,6 +53,8 @@ DynamicRibbonWidget::DynamicRibbonWidget(const bool combo, const bool multi_row)
|
||||
m_selected_item[n] = -1;
|
||||
}
|
||||
m_selected_item[0] = 0; // only player 0 has a selection by default
|
||||
|
||||
m_item_count_hint = 0;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
DynamicRibbonWidget::~DynamicRibbonWidget()
|
||||
@ -75,7 +77,7 @@ DynamicRibbonWidget::~DynamicRibbonWidget()
|
||||
*/
|
||||
void estimateIconAreaFor(const int rowCount, const int wantedIconWidth,
|
||||
const int width, const int height,
|
||||
const float iconAspectRatio,
|
||||
const float iconAspectRatio, const int maxIcons,
|
||||
int* visibleItems, int* takenArea, int* itemHeight)
|
||||
{
|
||||
assert(height > 0);
|
||||
@ -87,7 +89,7 @@ void estimateIconAreaFor(const int rowCount, const int wantedIconWidth,
|
||||
|
||||
const int icons_per_row = std::min(int(width / icon_width), int(width / wantedIconWidth));
|
||||
|
||||
*visibleItems = icons_per_row * rowCount ;
|
||||
*visibleItems = std::min(maxIcons, icons_per_row * rowCount);
|
||||
*takenArea = int(*visibleItems * icon_width * icon_height);
|
||||
}
|
||||
|
||||
@ -216,9 +218,22 @@ void DynamicRibbonWidget::add()
|
||||
int visible_items;
|
||||
int taken_area;
|
||||
int item_height;
|
||||
estimateIconAreaFor(row_count, m_child_width, m_w, m_h - m_label_height,
|
||||
aspect_ratio, &visible_items, &taken_area, &item_height);
|
||||
|
||||
int item_count = m_item_count_hint;
|
||||
|
||||
if (item_count < 1)
|
||||
{
|
||||
item_count = m_items.size();
|
||||
}
|
||||
|
||||
if (item_count < 1)
|
||||
{
|
||||
// No idea so make assumptions
|
||||
item_count = 20;
|
||||
}
|
||||
|
||||
estimateIconAreaFor(row_count, m_child_width, m_w, m_h - m_label_height,
|
||||
aspect_ratio, item_count, &visible_items, &taken_area, &item_height);
|
||||
|
||||
// FIXME: this system to determine the best number of columns is really complicated!
|
||||
// the score is computed from taken screen area AND visible item count.
|
||||
|
@ -168,6 +168,8 @@ namespace GUIEngine
|
||||
|
||||
bool findItemInRows(const char* name, int* p_row, int* p_id);
|
||||
|
||||
int m_item_count_hint;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@ -270,6 +272,10 @@ namespace GUIEngine
|
||||
virtual void onSelectionChange(){}
|
||||
|
||||
virtual void update(float delta);
|
||||
|
||||
/** Set approximately how many items are expected to be in this ribbon; will help the layout
|
||||
* algorithm next time add() is called */
|
||||
void setItemCountHint(int hint) { m_item_count_hint = hint; }
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -916,6 +916,11 @@ void KartSelectionScreen::beforeAddingWidget()
|
||||
//I18N: name of the tab that will show tracks from all groups
|
||||
tabs->addTextChild( _("All") , ALL_KART_GROUPS_ID);
|
||||
}
|
||||
|
||||
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
|
||||
assert( w != NULL );
|
||||
|
||||
w->setItemCountHint( kart_properties_manager->getNumberOfKarts() );
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -210,6 +210,10 @@ void TracksScreen::beforeAddingWidget()
|
||||
//I18N: name of the tab that will show tracks from all groups
|
||||
tabs->addTextChild(_("All"), ALL_TRACK_GROUPS_ID );
|
||||
}
|
||||
|
||||
DynamicRibbonWidget* tracks_widget = this->getWidget<DynamicRibbonWidget>("tracks");
|
||||
assert( tracks_widget != NULL );
|
||||
tracks_widget->setItemCountHint( track_manager->getNumberOfTracks() );
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user