Max number of rows in a ribbon grid is no more hardcoded, can now be specified ion XML.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4692 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
ca9bf74cba
commit
77c29ca276
@ -20,7 +20,7 @@
|
||||
|
||||
<box proportion="2" width="100%" layout="vertical-row">
|
||||
<ribbon_grid id="karts" proportion="1" square_items="true" width="100%" align="center"
|
||||
child_width="80" child_height="80"/>
|
||||
child_width="80" child_height="80" max_rows="3"/>
|
||||
</box>
|
||||
|
||||
<!-- Groups will be added dynamically at runtime -->
|
||||
|
@ -14,7 +14,8 @@
|
||||
|
||||
<box proportion="1" width="100%" layout="vertical-row">
|
||||
<ribbon_grid id="tracks" proportion="1" width="100%" square_items="true"
|
||||
label_location="bottom" align="center" child_width="160" child_height="120" />
|
||||
label_location="bottom" align="center" max_rows="4"
|
||||
child_width="160" child_height="120" />
|
||||
<spacer width="20" height="13" />
|
||||
</box>
|
||||
|
||||
|
@ -198,6 +198,9 @@ Currently only used by dynamic ribbons. Decides where the label is. Value can be
|
||||
(if ommitted, "none" is the default). "each" means that every item has its own label. "bottom" means there
|
||||
is a single label for all at the bottom, that displays the name of the current item.
|
||||
|
||||
PROP_MAX_ROWS "max_rows"
|
||||
Currently used for ribbon grids only. Indicates the maximum amount of rows this ribbon can have.
|
||||
|
||||
+--------------------------+
|
||||
+ Using the Engine in Code +
|
||||
+--------------------------+
|
||||
|
@ -130,15 +130,15 @@ void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_t
|
||||
}
|
||||
else if (!strcmp("ribbon_grid", xml->getNodeName()))
|
||||
{
|
||||
append_to.push_back(new DynamicRibbonWidget());
|
||||
append_to.push_back(new DynamicRibbonWidget(false /* combo */, true /* multi-row */));
|
||||
}
|
||||
else if (!strcmp("scrollable_ribbon", xml->getNodeName()))
|
||||
{
|
||||
append_to.push_back(new DynamicRibbonWidget(true, 1));
|
||||
append_to.push_back(new DynamicRibbonWidget(true /* combo */, false /* multi-row */));
|
||||
}
|
||||
else if (!strcmp("scrollable_toolbar", xml->getNodeName()))
|
||||
{
|
||||
append_to.push_back(new DynamicRibbonWidget(false, 1));
|
||||
append_to.push_back(new DynamicRibbonWidget(false /* combo */, false /* multi-row */));
|
||||
}
|
||||
else if (!strcmp("model", xml->getNodeName()))
|
||||
{
|
||||
@ -185,6 +185,7 @@ if(prop_name != NULL) widget.m_properties[prop_flag] = prop_name; else widget.m_
|
||||
READ_PROPERTY(max_height, PROP_MAX_HEIGHT);
|
||||
READ_PROPERTY(extend_label, PROP_EXTEND_LABEL);
|
||||
READ_PROPERTY(label_location, PROP_LABELS_LOCATION);
|
||||
READ_PROPERTY(max_rows, PROP_MAX_ROWS);
|
||||
#undef READ_PROPERTY
|
||||
|
||||
const char* text = xml->getAttributeValue( "text" );
|
||||
|
@ -79,7 +79,8 @@ namespace GUIEngine
|
||||
PROP_MAX_HEIGHT,
|
||||
PROP_SQUARE,
|
||||
PROP_EXTEND_LABEL,
|
||||
PROP_LABELS_LOCATION
|
||||
PROP_LABELS_LOCATION,
|
||||
PROP_MAX_ROWS
|
||||
};
|
||||
|
||||
bool isWithinATextBox();
|
||||
|
@ -34,21 +34,20 @@ namespace GUIEngine
|
||||
const char* NO_ITEM_ID = "?";
|
||||
}
|
||||
|
||||
DynamicRibbonWidget::DynamicRibbonWidget(const bool combo, const int max_rows)
|
||||
DynamicRibbonWidget::DynamicRibbonWidget(const bool combo, const bool multi_row)
|
||||
{
|
||||
m_scroll_offset = 0;
|
||||
m_needed_cols = 0;
|
||||
m_col_amount = 0;
|
||||
m_has_label = false;
|
||||
m_scroll_offset = 0;
|
||||
m_needed_cols = 0;
|
||||
m_col_amount = 0;
|
||||
m_previous_item_count = 0;
|
||||
m_multi_row = multi_row;
|
||||
m_combo = combo;
|
||||
m_has_label = false;
|
||||
m_left_widget = NULL;
|
||||
m_right_widget = NULL;
|
||||
m_type = WTYPE_DYNAMIC_RIBBON;
|
||||
|
||||
m_max_rows = max_rows;
|
||||
m_combo = combo;
|
||||
|
||||
m_left_widget = NULL;
|
||||
m_right_widget = NULL;
|
||||
m_type = WTYPE_DYNAMIC_RIBBON;
|
||||
|
||||
// by default, set all players to have no selection in this ribbon
|
||||
for (int n=0; n<MAX_PLAYER_COUNT; n++)
|
||||
{
|
||||
m_selected_item[n] = -1;
|
||||
@ -144,10 +143,22 @@ void DynamicRibbonWidget::add()
|
||||
m_child_height = 256;
|
||||
}
|
||||
|
||||
// determine row amonunt
|
||||
// determine row amount
|
||||
m_row_amount = (int)round((h-m_label_height) / (float)m_child_height);
|
||||
if (m_row_amount > m_max_rows) m_row_amount = m_max_rows;
|
||||
|
||||
if (m_properties[PROP_MAX_ROWS].size() > 0)
|
||||
{
|
||||
const int max_rows = atoi(m_properties[PROP_MAX_ROWS].c_str());
|
||||
if (max_rows < 1)
|
||||
{
|
||||
std::cout << "/!\\ WARNING : the 'max_rows' property must be an integer greater than zero."
|
||||
<< " Ingoring current value '" << m_properties[PROP_MAX_ROWS] << "'\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_row_amount > max_rows) m_row_amount = max_rows;
|
||||
}
|
||||
}
|
||||
// get and build a list of IDs (by now we may not yet know everything about items,
|
||||
// but we need to get IDs *now* in order for tabbing to work.
|
||||
m_ids.resize(m_row_amount);
|
||||
|
@ -91,8 +91,8 @@ namespace GUIEngine
|
||||
/** The total number of columns given item count and row count (even counting not visible with current scrolling) */
|
||||
int m_needed_cols;
|
||||
|
||||
/** The maximum number of rows, as passed to the constructor */
|
||||
int m_max_rows;
|
||||
/** Whether this ribbon can have multiple rows (i.e. ribbon grid) or is a single line */
|
||||
bool m_multi_row;
|
||||
|
||||
/** irrlicht relies on consecutive IDs to perform keyboard navigation between widgets. However, since this
|
||||
widget is dynamic, irrlicht widgets are not created as early as all others, so by the time we're ready
|
||||
@ -143,7 +143,12 @@ namespace GUIEngine
|
||||
|
||||
|
||||
public:
|
||||
DynamicRibbonWidget(const bool combo=false, const int max_rows=4);
|
||||
/**
|
||||
* \param combo Whether this is a "combo" ribbon, i.e. whether there is always one selected item.
|
||||
* If set to false, will behave more like a toolbar.
|
||||
* \param multi_row Whether this ribbon can have more than one row
|
||||
*/
|
||||
DynamicRibbonWidget(const bool combo, const bool multi_row);
|
||||
|
||||
/** Reference pointers only, the actual instances are owned by m_children. Used to create mtultiple-row
|
||||
ribbons (what appears to be a grid of icons is actually a vector of stacked basic ribbons) */
|
||||
|
Loading…
Reference in New Issue
Block a user