mirror of
https://github.com/lbonn/rofi
synced 2024-11-23 04:13:03 +00:00
Fix EM support, use char height
This commit is contained in:
parent
068592414e
commit
52e850dc33
5 changed files with 31 additions and 21 deletions
|
@ -75,15 +75,6 @@ void listview_set_selected ( listview *lv, unsigned int selected );
|
|||
*/
|
||||
unsigned int listview_get_selected ( listview *lv );
|
||||
|
||||
/**
|
||||
* @param lv The listview handle
|
||||
*
|
||||
* Get the desired height of the listview widget.
|
||||
*
|
||||
* @returns the desired height.
|
||||
*/
|
||||
unsigned int listview_get_desired_height ( listview *lv );
|
||||
|
||||
/**
|
||||
* @param lv The listview handle
|
||||
*
|
||||
|
|
|
@ -196,6 +196,7 @@ int textbox_get_font_width ( const textbox *tb );
|
|||
* @returns the width of a character in pixels.
|
||||
*/
|
||||
double textbox_get_estimated_char_width ( void );
|
||||
double textbox_get_estimated_char_height ( void );
|
||||
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
|
@ -217,13 +218,14 @@ void textbox_delete ( textbox *tb, int pos, int dlen );
|
|||
* TODO remove for #widget_resize and #widget_move
|
||||
*/
|
||||
void textbox_moveresize ( textbox *tb, int x, int y, int w, int h );
|
||||
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
* Get the (estimated) with of a character, can be used to calculate window width.
|
||||
*
|
||||
* @returns the estimated width of a character.
|
||||
*/
|
||||
int textbox_get_estimated_char_height ( const textbox *tb, int eh );
|
||||
int textbox_get_estimated_height ( const textbox *tb, int eh );
|
||||
/**
|
||||
* @param p The new default PangoContext
|
||||
*
|
||||
|
|
|
@ -77,6 +77,8 @@ struct _listview
|
|||
void *mouse_activated_data;
|
||||
};
|
||||
|
||||
static int listview_get_desired_height ( widget *wid );
|
||||
|
||||
static void listview_free ( widget *wid )
|
||||
{
|
||||
listview *lv = (listview *) wid;
|
||||
|
@ -340,7 +342,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
|
|||
//
|
||||
char *tb_name = g_strjoin (".", lv->widget.name,"element", NULL);
|
||||
textbox *tb = textbox_create ( tb_name, 0, NORMAL, "" );
|
||||
lv->element_height = textbox_get_estimated_char_height (tb, lv->eh);
|
||||
lv->element_height = textbox_get_estimated_height (tb, lv->eh);
|
||||
g_free(tb_name);
|
||||
|
||||
lv->callback = cb;
|
||||
|
@ -452,8 +454,9 @@ void listview_nav_page_next ( listview *lv )
|
|||
widget_queue_redraw ( WIDGET ( lv ) );
|
||||
}
|
||||
|
||||
unsigned int listview_get_desired_height ( listview *lv )
|
||||
static int listview_get_desired_height ( widget *wid )
|
||||
{
|
||||
listview *lv = (listview *)wid;
|
||||
if ( lv == NULL || lv->widget.enabled == FALSE ) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -757,13 +757,27 @@ int textbox_get_font_width ( const textbox *tb )
|
|||
return width;
|
||||
}
|
||||
|
||||
double textbox_get_estimated_char_width ( void )
|
||||
static double char_height = -1;
|
||||
double textbox_get_estimated_char_height ( void )
|
||||
{
|
||||
int width = pango_font_metrics_get_approximate_char_width ( p_metrics );
|
||||
return ( width ) / (double) PANGO_SCALE;
|
||||
if ( char_height < 0 ){
|
||||
int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics );
|
||||
char_height = ( height ) / (double) PANGO_SCALE;
|
||||
}
|
||||
return char_height;
|
||||
}
|
||||
|
||||
int textbox_get_estimated_char_height ( const textbox *tb, int eh )
|
||||
static double char_width = -1;
|
||||
double textbox_get_estimated_char_width ( void )
|
||||
{
|
||||
if ( char_width < 0 ){
|
||||
int width = pango_font_metrics_get_approximate_char_width ( p_metrics );
|
||||
char_width = ( width ) / (double) PANGO_SCALE;
|
||||
}
|
||||
return char_width;
|
||||
}
|
||||
|
||||
int textbox_get_estimated_height ( const textbox *tb, int eh )
|
||||
{
|
||||
int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics );
|
||||
return ( eh*height ) / PANGO_SCALE + widget_padding_get_padding_height ( WIDGET ( tb ) );
|
||||
|
|
|
@ -212,32 +212,32 @@ void widget_set_name ( widget *wid, const char *name )
|
|||
}
|
||||
|
||||
// External
|
||||
double textbox_get_estimated_char_width ( void );
|
||||
double textbox_get_estimated_char_height ( void );
|
||||
int widget_padding_get_left ( const widget *wid )
|
||||
{
|
||||
if ( wid->pad.left.type == PW_EM ){
|
||||
return wid->pad.left.distance*textbox_get_estimated_char_width();
|
||||
return wid->pad.left.distance*textbox_get_estimated_char_height();
|
||||
}
|
||||
return wid->pad.left.distance;
|
||||
}
|
||||
int widget_padding_get_right ( const widget *wid )
|
||||
{
|
||||
if ( wid->pad.right.type == PW_EM ){
|
||||
return wid->pad.right.distance*textbox_get_estimated_char_width();
|
||||
return wid->pad.right.distance*textbox_get_estimated_char_height();
|
||||
}
|
||||
return wid->pad.right.distance;
|
||||
}
|
||||
int widget_padding_get_top ( const widget *wid )
|
||||
{
|
||||
if ( wid->pad.top.type == PW_EM ){
|
||||
return wid->pad.top.distance*textbox_get_estimated_char_width();
|
||||
return wid->pad.top.distance*textbox_get_estimated_char_height();
|
||||
}
|
||||
return wid->pad.top.distance;
|
||||
}
|
||||
int widget_padding_get_bottom ( const widget *wid )
|
||||
{
|
||||
if ( wid->pad.bottom.type == PW_EM ){
|
||||
return wid->pad.bottom.distance*textbox_get_estimated_char_width();
|
||||
return wid->pad.bottom.distance*textbox_get_estimated_char_height();
|
||||
}
|
||||
return wid->pad.bottom.distance;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue