From c376a89fc0a082b8e3e7d4b9e2e67568b44b5eab Mon Sep 17 00:00:00 2001 From: vanhofen Date: Wed, 14 Jun 2017 14:57:09 +0200 Subject: [PATCH] cc_frm_scrollbar: add getScrollBarData() function ... to calculate total pages and current page for CComponentsScrollBar Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/adb71c756cf203c72182ac2607082604a3b87b8f Author: vanhofen Date: 2017-06-14 (Wed, 14 Jun 2017) Origin message was: ------------------ - cc_frm_scrollbar: add getScrollBarData() function ... to calculate total pages and current page for CComponentsScrollBar --- src/gui/components/cc_frm_scrollbar.cpp | 10 ++++++++++ src/gui/components/cc_frm_scrollbar.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/gui/components/cc_frm_scrollbar.cpp b/src/gui/components/cc_frm_scrollbar.cpp index 2a553950e..a2ea040a2 100644 --- a/src/gui/components/cc_frm_scrollbar.cpp +++ b/src/gui/components/cc_frm_scrollbar.cpp @@ -220,6 +220,16 @@ void CComponentsScrollBar::initSegments() } } +void getScrollBarData(int *total_pages, int *current_page, int total_items, int items_per_page, int selected_item) +{ + // avoid divison by zero and fix wrong values + total_items = std::max(total_items, 1); + items_per_page = std::max(items_per_page, 1); + selected_item = std::max(selected_item, 0); + + *total_pages = ((total_items - 1) / items_per_page) + 1; + *current_page = selected_item / items_per_page; +} void paintScrollBar( const int &x_pos, const int &y_pos, diff --git a/src/gui/components/cc_frm_scrollbar.h b/src/gui/components/cc_frm_scrollbar.h index 8658d5428..8bd1c0568 100644 --- a/src/gui/components/cc_frm_scrollbar.h +++ b/src/gui/components/cc_frm_scrollbar.h @@ -145,6 +145,8 @@ class CComponentsScrollBar : public CComponentsFrmChain void disableVisualize(){enableVisualize(false);} }; +void getScrollBarData(int *total_pages, int *current_page, int total_items, int items_per_page, int selected_item); + /**Small and easy to apply scrollbar paint methode without expilcit object declaration * @return void *