Add resizing code for list widget
This commit is contained in:
parent
3641183121
commit
2a60d6508b
@ -93,22 +93,30 @@ void ListWidget::setIcons(STKModifiedSpriteBank* icons, int size)
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
int ListWidget::getHeaderHeight() const
|
||||
{
|
||||
return GUIEngine::getFontHeight() + 15;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
rect<s32> ListWidget::getListBoxSize() const
|
||||
{
|
||||
return m_header.size() > 0 ?
|
||||
rect<s32>(m_x, m_y + getHeaderHeight(), m_x + m_w, m_y + m_h) :
|
||||
rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void ListWidget::add()
|
||||
{
|
||||
const int header_height = GUIEngine::getFontHeight() + 15;
|
||||
|
||||
rect<s32> widget_size = (m_header.size() > 0 ? rect<s32>(m_x, m_y + header_height, m_x + m_w, m_y + m_h) :
|
||||
rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h) );
|
||||
|
||||
IGUISkin * current_skin = GUIEngine::getGUIEnv()->getSkin();
|
||||
IGUIFont * current_font = GUIEngine::getGUIEnv()->getBuiltInFont();
|
||||
CGUISTKListBox * list_box = new CGUISTKListBox(
|
||||
GUIEngine::getGUIEnv(),
|
||||
m_parent ? m_parent : GUIEngine::getGUIEnv()->getRootGUIElement(),
|
||||
getNewID(),
|
||||
widget_size,
|
||||
getListBoxSize(),
|
||||
true,
|
||||
true,
|
||||
false);
|
||||
@ -140,20 +148,8 @@ void ListWidget::createHeader()
|
||||
if (m_header_created)
|
||||
return;
|
||||
|
||||
const int header_height = GUIEngine::getFontHeight() + 15;
|
||||
|
||||
if (m_header.size() > 0)
|
||||
{
|
||||
//const int col_size = m_w / m_header.size();
|
||||
|
||||
int proportion_total = 0;
|
||||
for (unsigned int n=0; n<m_header.size(); n++)
|
||||
{
|
||||
proportion_total += m_header[n].m_proportion;
|
||||
}
|
||||
|
||||
int x = m_x;
|
||||
int scrollbar_width = GUIEngine::getSkin()->getSize(EGDS_SCROLLBAR_SIZE);
|
||||
for (unsigned int n=0; n<m_header.size()+1; n++)
|
||||
{
|
||||
std::ostringstream name;
|
||||
@ -177,25 +173,6 @@ void ListWidget::createHeader()
|
||||
header = icon;
|
||||
}
|
||||
header->m_reserved_id = getNewNoFocusID();
|
||||
|
||||
header->m_y = m_y;
|
||||
header->m_h = header_height;
|
||||
|
||||
header->m_x = x;
|
||||
if (n == m_header.size())
|
||||
{
|
||||
header->m_w = scrollbar_width;
|
||||
header->setActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
int header_width = m_w - scrollbar_width;
|
||||
header->m_w = (int)(header_width * float(m_header[n].m_proportion)
|
||||
/float(proportion_total));
|
||||
}
|
||||
|
||||
x += header->m_w;
|
||||
|
||||
header->m_properties[PROP_ID] = name.str();
|
||||
|
||||
header->add();
|
||||
@ -210,6 +187,8 @@ void ListWidget::createHeader()
|
||||
m_check_inside_me = true;
|
||||
}
|
||||
m_header_created = true;
|
||||
|
||||
updateHeader();
|
||||
} // createHeader
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -671,3 +650,50 @@ void ListWidget::setActive(bool active)
|
||||
Widget::setActive(active);
|
||||
getIrrlichtElement<CGUISTKListBox>()->setDisactivated(!active);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void ListWidget::updateHeader()
|
||||
{
|
||||
if (m_header.size() > 0)
|
||||
{
|
||||
int proportion_total = 0;
|
||||
for (unsigned int n = 0; n < m_header.size(); n++)
|
||||
{
|
||||
proportion_total += m_header[n].m_proportion;
|
||||
}
|
||||
|
||||
int x = m_x;
|
||||
int scrollbar_width = GUIEngine::getSkin()->getSize(EGDS_SCROLLBAR_SIZE);
|
||||
for (unsigned int n = 0; n < m_header.size() + 1; n++)
|
||||
{
|
||||
Widget* header = m_header_elements.get(n);
|
||||
header->m_y = m_y;
|
||||
header->m_h = getHeaderHeight();
|
||||
|
||||
header->m_x = x;
|
||||
if (n == m_header.size())
|
||||
{
|
||||
header->m_w = scrollbar_width;
|
||||
header->setActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
int header_width = m_w - scrollbar_width;
|
||||
header->m_w = (int)(header_width * float(m_header[n].m_proportion)
|
||||
/ float(proportion_total));
|
||||
header->setActive(true);
|
||||
}
|
||||
|
||||
x += header->m_w;
|
||||
header->resize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void ListWidget::resize()
|
||||
{
|
||||
if (m_element)
|
||||
m_element->setRelativePosition(getListBoxSize());
|
||||
updateHeader();
|
||||
}
|
||||
|
@ -108,6 +108,10 @@ namespace GUIEngine
|
||||
m_sort_col = 0;
|
||||
}
|
||||
|
||||
void updateHeader();
|
||||
int getHeaderHeight() const;
|
||||
irr::core::rect<s32> getListBoxSize() const;
|
||||
|
||||
public:
|
||||
typedef irr::gui::CGUISTKListBox::ListItem ListItem;
|
||||
typedef ListItem::ListCell ListCell;
|
||||
@ -302,6 +306,7 @@ namespace GUIEngine
|
||||
void setSortable(bool sortable) { m_sortable = sortable; }
|
||||
void focusHeader(const NavigationDirection nav);
|
||||
virtual void setActive(bool active=true);
|
||||
virtual void resize();
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user