Skip to content

Commit

Permalink
Apply Guichan's changes from 3cffde49fee87bfe5a426e8c799f143ed965cc60…
Browse files Browse the repository at this point in the history
… (Feb 23th 2008)

A method for getting the height of a row has been added. The method can easily be overridden if another row height than the font row height is preferred.

http://code.google.com/p/guichan/issues/detail?id=25
  • Loading branch information
Jarod42 committed Aug 19, 2024
1 parent 8bdb83d commit 058724f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* Continue rebasing from 3cffde49fee87bfe5a426e8c799f143ed965cc60
* Continue rebasing from 957109f8411fba542c42860413d1bc8938173553
* Add a focus listener interface.
* Make focus apply synchronously.
* Graphics and input objects for DirectX.
Expand Down
8 changes: 8 additions & 0 deletions include/guisan/widgets/listbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ namespace gcn
*/
void removeSelectionListener(SelectionListener* selectionListener);

/**
* Gets the height of a row. Should be overridden if another row
* height than the font height is preferred.
*
* @return The height of a row.
* @since 1.1.0
*/
virtual unsigned int getRowHeight() const;

// Inherited from Widget

Expand Down
19 changes: 12 additions & 7 deletions src/widgets/listbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace gcn
// Check the current clip area so we don't draw unnecessary items
// that are not visible.
const auto currentClipArea = graphics->getCurrentClipArea();
const int rowHeight = getFont()->getHeight();
const int rowHeight = getRowHeight();

// Calculate the number of rows to draw by checking the clip area.
// The addition of two makes covers a partial visible row at the top
Expand Down Expand Up @@ -205,10 +205,10 @@ namespace gcn
}
else
{
scroll.y = getFont()->getHeight() * mSelected;
scroll.y = getRowHeight() * mSelected;
}

scroll.height = getFont()->getHeight();
scroll.height = getRowHeight();
showPart(scroll);
}

Expand Down Expand Up @@ -272,7 +272,7 @@ namespace gcn
{
if (mouseEvent.getButton() == MouseEvent::LEFT)
{
setSelected(mouseEvent.getY() / getFont()->getHeight());
setSelected(mouseEvent.getY() / getRowHeight());
distributeActionEvent();
}
}
Expand Down Expand Up @@ -321,7 +321,7 @@ namespace gcn
{
if (mListModel != NULL)
{
setHeight(getFont()->getHeight() * mListModel->getNumberOfElements());
setHeight(getRowHeight() * mListModel->getNumberOfElements());
}
}

Expand All @@ -334,12 +334,12 @@ namespace gcn
{
mWrappingEnabled = wrappingEnabled;
}

void ListBox::addSelectionListener(SelectionListener* selectionListener)
{
mSelectionListeners.push_back(selectionListener);
}

void ListBox::removeSelectionListener(SelectionListener* selectionListener)
{
mSelectionListeners.remove(selectionListener);
Expand All @@ -355,4 +355,9 @@ namespace gcn
(*iter)->valueChanged(event);
}
}

unsigned int ListBox::getRowHeight() const
{
return getFont()->getHeight();
}
}

0 comments on commit 058724f

Please sign in to comment.