diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-02-17 20:29:23 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-02-17 20:29:23 +0100 |
commit | d2567a68842dbcdae1c722b0421ee551409f481e (patch) | |
tree | 32124946df7f21830b8023c3dc00833f434ea559 /source | |
parent | 99515f986e941a40948f3fca37713e0758c9a1c5 (diff) |
#219: Implement continious scroll
Diffstat (limited to 'source')
-rw-r--r-- | source/view.c | 35 | ||||
-rw-r--r-- | source/xrmoptions.c | 3 |
2 files changed, 35 insertions, 3 deletions
diff --git a/source/view.c b/source/view.c index d6130b59..32631d0e 100644 --- a/source/view.c +++ b/source/view.c @@ -664,9 +664,10 @@ inline static void rofi_view_nav_last ( RofiViewState * state ) state->update = TRUE; } -static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) +static unsigned int rofi_scroll_per_page ( RofiViewState * state ) { - unsigned int i, offset = 0; + int offset = 0; + // selected row is always visible. // If selected is visible do not scroll. if ( ( ( state->selected - ( state->last_offset ) ) < ( state->max_elements ) ) && ( state->selected >= ( state->last_offset ) ) ) { @@ -684,6 +685,35 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) // Set the position scrollbar_set_handle ( state->scrollbar, page * state->max_elements ); } + return offset; +} + +static unsigned int rofi_scroll_continious ( RofiViewState * state ) +{ + unsigned int middle = state->menu_lines / 2; + unsigned int offset = 0; + if ( state->selected > middle ) { + if ( state->selected < ( state->filtered_lines - middle ) ) { + offset = state->selected - middle; + } + else { + offset = state->filtered_lines - state->menu_lines; + } + } + state->rchanged = TRUE; + scrollbar_set_handle ( state->scrollbar, offset ); + return offset; +} + +static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) +{ + unsigned int i, offset = 0; + if ( config.scroll_method == 1 ) { + offset = rofi_scroll_continious ( state ); + } + else { + offset = rofi_scroll_per_page ( state ); + } // Re calculate the boxes and sizes, see if we can move this in the menu_calc*rowscolumns // Get number of remaining lines to display. unsigned int a_lines = MIN ( ( state->filtered_lines - offset ), state->max_elements ); @@ -907,6 +937,7 @@ static void rofi_view_resize ( RofiViewState *state ) } } state->max_rows = MAX ( 1, ( h / element_height ) ); + state->menu_lines = state->max_rows; state->max_elements = state->max_rows * config.menu_columns; // Free boxes no longer needed. for ( unsigned int i = state->max_elements; i < last_length; i++ ) { diff --git a/source/xrmoptions.c b/source/xrmoptions.c index e02ed530..c25794af 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -138,7 +138,8 @@ static XrmOption xrmOptions[] = { { xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL, "Fake transparency" }, { xrm_SNumber, "dpi", { .snum = &config.dpi }, NULL, "DPI" }, { xrm_Number, "threads", { .num = &config.threads }, NULL, "Threads to use for string matching" }, - { xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL, "Scrollbar width" } + { xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL, "Scrollbar width" }, + { xrm_Number, "scroll-method", { .num = &config.scroll_method }, NULL, "Scrolling method. (0: Page, 1: Centered)" } }; // Dynamic options. |