1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Document doc, fix small drawing things in scrollbar

This commit is contained in:
Dave Davenport 2015-09-04 08:42:09 +02:00
parent 380697b895
commit 72ef9c014f
3 changed files with 83 additions and 15 deletions

View file

@ -1,6 +1,9 @@
#ifndef ROFI_SCROLLBAR_H
#define ROFI_SCROLLBAR_H
/**
* Internal structure for the scrollbar.
*/
typedef struct _scrollbar
{
Window window, parent;
@ -11,15 +14,80 @@ typedef struct _scrollbar
unsigned int pos_length;
} scrollbar;
/**
* @param parent the parent window
* @param vinfo The XVisualInfo to use when creating new window
* @param map The colormap to use for new window
* @param x The x coordinate (relative to parent) to position the new scrollbar
* @param y The y coordinate (relative to parent) to position the new scrollbar
* @param w The width of the scrollbar
* @param h The height of the scrollbar
*
* Create a new scrollbar
*
* @returns the scrollbar object.
*/
scrollbar *scrollbar_create ( Window parent, XVisualInfo *vinfo, Colormap map,
short x, short y, short w, short h );
/**
* @param sb scrollbar object
*
* Hide (unmap) the scrollbar.
*/
void scrollbar_hide ( scrollbar *sb );
/**
* @param sb scrollbar object
*
* Show (map) the scrollbar.
*/
void scrollbar_show ( scrollbar *sb );
/**
* @param sb scrollbar object
*
* Free the resources used by the scrollbar.
*/
void scrollbar_free ( scrollbar *sb );
void scrollbar_set_pos_length ( scrollbar *sb, unsigned int pos_length );
void scrollbar_set_pos ( scrollbar *sb, unsigned int pos );
void scrollbar_set_length ( scrollbar *sb, unsigned int length );
/**
* @param sb scrollbar object
* @param pos_length new length
*
* set the length of the handle relative to the max value of bar.
*/
void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length );
/**
* @param sb scrollbar object
* @param pos new position
*
* set the position of the handle relative to the set max value of bar.
*/
void scrollbar_set_handle ( scrollbar *sb, unsigned int pos );
/**
* @param sb scrollbar object
* @param max the new max
*
* set the max value of the bar.
*/
void scrollbar_set_max_value ( scrollbar *sb, unsigned int max );
/**
* @param sb scrollbar object
*
* Draw the scrollbar, used after expose event or update
*/
void scrollbar_draw ( scrollbar *sb );
/**
* @param sb scrollbar object
* @param y clicked position
*
* Calculate the position of the click relative to the max value of bar
*/
unsigned int scrollbar_clicked ( scrollbar *sb, int y );
#endif // ROFI_SCROLLBAR_H

View file

@ -368,7 +368,7 @@ static void menu_calculate_rows_columns ( MenuState *state )
// Always have at least one row.
state->max_rows = MAX ( 1, state->max_rows );
if ( state->scrollbar ) {
scrollbar_set_pos_length ( state->scrollbar, state->max_rows );
scrollbar_set_handle_length ( state->scrollbar, state->max_rows );
}
if ( config.fixed_num_lines == TRUE ) {
@ -741,7 +741,7 @@ static void menu_refilter ( MenuState *state, char **lines, menu_match_cb mmc, v
state->quit = TRUE;
}
scrollbar_set_length ( state->scrollbar, state->filtered_lines );
scrollbar_set_max_value ( state->scrollbar, state->filtered_lines );
state->refilter = FALSE;
state->rchanged = TRUE;
}
@ -766,7 +766,7 @@ static void menu_draw ( MenuState *state )
state->cur_page = page;
state->rchanged = TRUE;
}
scrollbar_set_pos ( state->scrollbar, page * state->max_rows );
scrollbar_set_handle ( state->scrollbar, page * state->max_rows );
}
scrollbar_draw ( state->scrollbar );
// Re calculate the boxes and sizes, see if we can move this in the menu_calc*rowscolumns
@ -1026,8 +1026,8 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
8, ( state.max_rows - 1 ) * ( element_height + config.line_margin ) + element_height );
scrollbar_set_length ( state.scrollbar, state.num_lines );
scrollbar_set_pos_length ( state.scrollbar, state.max_rows );
scrollbar_set_max_value ( state.scrollbar, state.num_lines );
scrollbar_set_handle_length ( state.scrollbar, state.max_rows );
// filtered list
state.line_map = g_malloc0_n ( state.num_lines, sizeof ( int ) );
if ( config.levenshtein_sort ) {

View file

@ -84,17 +84,17 @@ void scrollbar_free ( scrollbar *sb )
g_free ( sb );
}
void scrollbar_set_length ( scrollbar *sb, unsigned int length )
void scrollbar_set_max_value ( scrollbar *sb, unsigned int max )
{
sb->length = MAX ( 1, length );
sb->length = MAX ( 1, max );
}
void scrollbar_set_pos ( scrollbar *sb, unsigned int pos )
void scrollbar_set_handle ( scrollbar *sb, unsigned int pos )
{
sb->pos = MIN ( sb->length, MAX ( 0, pos ) );
}
void scrollbar_set_pos_length ( scrollbar *sb, unsigned int pos_length )
void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length )
{
sb->pos_length = MIN ( sb->length, MAX ( 1, pos_length ) );
}
@ -102,10 +102,10 @@ void scrollbar_set_pos_length ( scrollbar *sb, unsigned int pos_length )
void scrollbar_draw ( scrollbar *sb )
{
// Calculate position and size.
const short bh = sb->h - 2;
const short bh = sb->h - 0;
float sec = ( ( bh ) / (float) sb->length );
short height = sb->pos_length * sec;
short y = sb->pos * sec + 1;
short y = sb->pos * sec;
// Set max pos.
y = MIN ( y, bh - 2 );
// Never go out of bar.
@ -115,7 +115,7 @@ void scrollbar_draw ( scrollbar *sb )
// Redraw base window
XClearWindow ( display, sb->window );
// Paint the handle.
XFillRectangle ( display, sb->window, sb->gc, 1, y, sb->w, height );
XFillRectangle ( display, sb->window, sb->gc, 0, y, sb->w, height );
}
unsigned int scrollbar_clicked ( scrollbar *sb, int y )