Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Guichan's changes from 3cffde49fee87bfe5a426e8c799f143ed965cc60… #42

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}