Add small arrows indicating more pages. (to be updated later)

This commit is contained in:
Qball Cow 2014-05-14 19:51:48 +02:00
parent a925e59653
commit de5187bb01
4 changed files with 49 additions and 19 deletions

View File

@ -46,4 +46,5 @@ void textbox_draw ( textbox *tb );
int textbox_keypress ( textbox *tb, XEvent *ev ); int textbox_keypress ( textbox *tb, XEvent *ev );
void textbox_cursor_end ( textbox *tb ); void textbox_cursor_end ( textbox *tb );
void textbox_move (textbox *tb, int x, int y);
#endif //__TEXTBOX_H__ #endif //__TEXTBOX_H__

View File

@ -808,6 +808,19 @@ Window main_window = None;
GC gc = NULL; GC gc = NULL;
#include "textbox.h" #include "textbox.h"
inline char *menu_set_arrow_text(int filtered_lines, int selected, int max_lines)
{
int page = (filtered_lines > 0)? selected/max_lines:0;
int npages = (filtered_lines > 0)? ((filtered_lines+max_lines-1)/max_lines):1;
if( page != 0 && page != (npages-1)) {
return "";
} else if (page != 0) {
return "";
} else if (page != (npages-1)) {
return "";
}
return " ";
}
void menu_draw ( textbox *text, void menu_draw ( textbox *text,
textbox **boxes, textbox **boxes,
@ -1044,13 +1057,22 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
} }
// search text input // search text input
textbox *arrowbox = textbox_create ( box, TB_AUTOHEIGHT | TB_AUTOWIDTH,
(config.padding),
(config.padding),
0, 0,
config.menu_font, config.menu_fg, config.menu_bg,
"W", NULL);
textbox *text = textbox_create ( box, TB_AUTOHEIGHT | TB_EDITABLE, textbox *text = textbox_create ( box, TB_AUTOHEIGHT | TB_EDITABLE,
( config.padding ), ( config.padding ),
( config.padding ), ( config.padding ),
element_width, 1, element_width-arrowbox->w, 1,
config.menu_font, config.menu_fg, config.menu_bg, config.menu_font, config.menu_fg, config.menu_bg,
( input != NULL ) ? *input : "", prompt ); ( input != NULL ) ? *input : "", prompt );
textbox_move ( arrowbox, w-config.padding-arrowbox->w, config.padding);
textbox_show ( text ); textbox_show ( text );
textbox_show ( arrowbox );
int line_height = text->font->ascent + text->font->descent; int line_height = text->font->ascent + text->font->descent;
@ -1184,6 +1206,8 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
} }
menu_draw ( text, boxes, max_lines, num_lines, &last_offset, selected, filtered ); menu_draw ( text, boxes, max_lines, num_lines, &last_offset, selected, filtered );
textbox_text( arrowbox, menu_set_arrow_text(filtered_lines, selected, max_lines));
textbox_draw( arrowbox );
// Why do we need the specian -1? // Why do we need the specian -1?
if ( config.wmode == VERTICAL && max_lines > 0) if ( config.wmode == VERTICAL && max_lines > 0)
@ -1396,6 +1420,8 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
} }
menu_draw ( text, boxes, max_lines, num_lines, &last_offset, selected, filtered ); menu_draw ( text, boxes, max_lines, num_lines, &last_offset, selected, filtered );
textbox_text( arrowbox, menu_set_arrow_text(filtered_lines, selected, max_lines));
textbox_draw( arrowbox );
} }
} }

View File

@ -59,18 +59,6 @@ static inline int execsh ( const char *cmd, int run_in_term )
return execlp ( "/bin/sh", "sh", "-c", cmd, NULL ); return execlp ( "/bin/sh", "sh", "-c", cmd, NULL );
} }
#define RUN_DIALOG_NAME_LENGTH 256
typedef struct _element
{
long int index;
char name[RUN_DIALOG_NAME_LENGTH];
}element;
static int element_sort_func ( const void *ea, const void *eb )
{
element *a = *(element * *) ea;
element *b = *(element * *) eb;
return b->index - a->index;
}
// execute sub-process // execute sub-process
static pid_t exec_cmd ( const char *cmd, int run_in_term ) static pid_t exec_cmd ( const char *cmd, int run_in_term )
{ {

View File

@ -39,7 +39,7 @@
#include "rofi.h" #include "rofi.h"
#include "textbox.h" #include "textbox.h"
#define SIDE_MARGIN 3 #define SIDE_MARGIN 2
extern Display *display; extern Display *display;
@ -133,6 +133,15 @@ void textbox_text ( textbox *tb, char *text )
textbox_extents ( tb ); textbox_extents ( tb );
} }
void textbox_move (textbox *tb, int x, int y)
{
if ( x != tb->x || y != tb->y )
{
tb->x = x;
tb->y = y;
XMoveResizeWindow ( display, tb->window, tb->x, tb->y, tb->w, tb->h );
}
}
// within the parent. handled auto width/height modes // within the parent. handled auto width/height modes
void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
{ {
@ -143,7 +152,14 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
if ( tb->flags & TB_AUTOWIDTH ) if ( tb->flags & TB_AUTOWIDTH )
{ {
w = tb->extents.width; if(w > 1)
{
w = MIN(w, tb->extents.width+2*SIDE_MARGIN);
}
else
{
w = tb->extents.width+2*SIDE_MARGIN;
}
} }
if ( x != tb->x || y != tb->y || w != tb->w || h != tb->h ) if ( x != tb->x || y != tb->y || w != tb->w || h != tb->h )
@ -259,12 +275,10 @@ void textbox_draw ( textbox *tb )
// calc full input text width // calc full input text width
// Calculate the right size, so no characters are cut off. // Calculate the right size, so no characters are cut off.
// TODO: Check performance of this. // TODO: Check performance of this.
while ( 1 ) do{
{
XftTextExtentsUtf8 ( display, tb->font, ( unsigned char * ) line, length, &extents ); XftTextExtentsUtf8 ( display, tb->font, ( unsigned char * ) line, length, &extents );
line_width = extents.width; line_width = extents.width;
if ( line_width <= ( tb->w - 2 * SIDE_MARGIN ) )
if ( line_width < ( tb->w - 2 * SIDE_MARGIN ) )
{ {
break; break;
} }
@ -274,6 +288,7 @@ void textbox_draw ( textbox *tb )
; ;
} }
} }
while ( line_width >0 );
int x = SIDE_MARGIN, y = tb->font->ascent; int x = SIDE_MARGIN, y = tb->font->ascent;