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 #ifndef ROFI_SCROLLBAR_H
#define ROFI_SCROLLBAR_H #define ROFI_SCROLLBAR_H
/**
* Internal structure for the scrollbar.
*/
typedef struct _scrollbar typedef struct _scrollbar
{ {
Window window, parent; Window window, parent;
@ -11,15 +14,80 @@ typedef struct _scrollbar
unsigned int pos_length; unsigned int pos_length;
} scrollbar; } 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, scrollbar *scrollbar_create ( Window parent, XVisualInfo *vinfo, Colormap map,
short x, short y, short w, short h ); short x, short y, short w, short h );
/**
* @param sb scrollbar object
*
* Hide (unmap) the scrollbar.
*/
void scrollbar_hide ( scrollbar *sb ); void scrollbar_hide ( scrollbar *sb );
/**
* @param sb scrollbar object
*
* Show (map) the scrollbar.
*/
void scrollbar_show ( scrollbar *sb ); void scrollbar_show ( scrollbar *sb );
/**
* @param sb scrollbar object
*
* Free the resources used by the scrollbar.
*/
void scrollbar_free ( scrollbar *sb ); 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 ); 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 ); unsigned int scrollbar_clicked ( scrollbar *sb, int y );
#endif // ROFI_SCROLLBAR_H #endif // ROFI_SCROLLBAR_H

View File

@ -368,7 +368,7 @@ static void menu_calculate_rows_columns ( MenuState *state )
// Always have at least one row. // Always have at least one row.
state->max_rows = MAX ( 1, state->max_rows ); state->max_rows = MAX ( 1, state->max_rows );
if ( state->scrollbar ) { 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 ) { 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; state->quit = TRUE;
} }
scrollbar_set_length ( state->scrollbar, state->filtered_lines ); scrollbar_set_max_value ( state->scrollbar, state->filtered_lines );
state->refilter = FALSE; state->refilter = FALSE;
state->rchanged = TRUE; state->rchanged = TRUE;
} }
@ -766,7 +766,7 @@ static void menu_draw ( MenuState *state )
state->cur_page = page; state->cur_page = page;
state->rchanged = TRUE; 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 ); scrollbar_draw ( state->scrollbar );
// Re calculate the boxes and sizes, see if we can move this in the menu_calc*rowscolumns // 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 ); 8, ( state.max_rows - 1 ) * ( element_height + config.line_margin ) + element_height );
scrollbar_set_length ( state.scrollbar, state.num_lines ); scrollbar_set_max_value ( state.scrollbar, state.num_lines );
scrollbar_set_pos_length ( state.scrollbar, state.max_rows ); scrollbar_set_handle_length ( state.scrollbar, state.max_rows );
// filtered list // filtered list
state.line_map = g_malloc0_n ( state.num_lines, sizeof ( int ) ); state.line_map = g_malloc0_n ( state.num_lines, sizeof ( int ) );
if ( config.levenshtein_sort ) { if ( config.levenshtein_sort ) {

View File

@ -84,17 +84,17 @@ void scrollbar_free ( scrollbar *sb )
g_free ( 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 ) ); 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 ) ); 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 ) void scrollbar_draw ( scrollbar *sb )
{ {
// Calculate position and size. // Calculate position and size.
const short bh = sb->h - 2; const short bh = sb->h - 0;
float sec = ( ( bh ) / (float) sb->length ); float sec = ( ( bh ) / (float) sb->length );
short height = sb->pos_length * sec; short height = sb->pos_length * sec;
short y = sb->pos * sec + 1; short y = sb->pos * sec;
// Set max pos. // Set max pos.
y = MIN ( y, bh - 2 ); y = MIN ( y, bh - 2 );
// Never go out of bar. // Never go out of bar.
@ -115,7 +115,7 @@ void scrollbar_draw ( scrollbar *sb )
// Redraw base window // Redraw base window
XClearWindow ( display, sb->window ); XClearWindow ( display, sb->window );
// Paint the handle. // 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 ) unsigned int scrollbar_clicked ( scrollbar *sb, int y )