From 058724f2314950b8129199c9f924a127d07c21c2 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Mon, 12 Aug 2024 20:08:11 +0200 Subject: [PATCH] Apply Guichan's changes from 3cffde49fee87bfe5a426e8c799f143ed965cc60 (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 --- TODO | 2 +- include/guisan/widgets/listbox.hpp | 8 ++++++++ src/widgets/listbox.cpp | 19 ++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/TODO b/TODO index 04cc72b..30a121a 100644 --- a/TODO +++ b/TODO @@ -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. diff --git a/include/guisan/widgets/listbox.hpp b/include/guisan/widgets/listbox.hpp index 5e4e84c..8d93d85 100644 --- a/include/guisan/widgets/listbox.hpp +++ b/include/guisan/widgets/listbox.hpp @@ -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 diff --git a/src/widgets/listbox.cpp b/src/widgets/listbox.cpp index 8fa123f..4dadda1 100644 --- a/src/widgets/listbox.cpp +++ b/src/widgets/listbox.cpp @@ -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 @@ -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); } @@ -272,7 +272,7 @@ namespace gcn { if (mouseEvent.getButton() == MouseEvent::LEFT) { - setSelected(mouseEvent.getY() / getFont()->getHeight()); + setSelected(mouseEvent.getY() / getRowHeight()); distributeActionEvent(); } } @@ -321,7 +321,7 @@ namespace gcn { if (mListModel != NULL) { - setHeight(getFont()->getHeight() * mListModel->getNumberOfElements()); + setHeight(getRowHeight() * mListModel->getNumberOfElements()); } } @@ -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); @@ -355,4 +355,9 @@ namespace gcn (*iter)->valueChanged(event); } } + + unsigned int ListBox::getRowHeight() const + { + return getFont()->getHeight(); + } }