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

Make spacing be of type distance.

This commit is contained in:
Dave Davenport 2016-12-31 23:27:17 +01:00
parent 52e850dc33
commit 7b0e0643c8
7 changed files with 38 additions and 26 deletions

View file

@ -9,7 +9,7 @@ typedef enum {
} PixelWidth; } PixelWidth;
typedef struct { typedef struct {
int distance; double distance;
PixelWidth type; PixelWidth type;
} Distance; } Distance;
@ -86,10 +86,13 @@ void rofi_theme_widget_add_properties ( Widget *widget, GHashTable *table );
* Public API * Public API
*/ */
Distance rofi_theme_get_distance ( const char *wclass, const char *name, const char *state, const char *property, int def );
int rofi_theme_get_integer ( const char *wclass, const char *name, const char *state, const char *property, int def ); int rofi_theme_get_integer ( const char *wclass, const char *name, const char *state, const char *property, int def );
int rofi_theme_get_boolean ( const char *wclass, const char *name, const char *state, const char *property, int def ); int rofi_theme_get_boolean ( const char *wclass, const char *name, const char *state, const char *property, int def );
char *rofi_theme_get_string ( const char *wclass, const char *name, const char *state, const char *property, char *def ); char *rofi_theme_get_string ( const char *wclass, const char *name, const char *state, const char *property, char *def );
double rofi_theme_get_double ( const char *wclass, const char *name, const char *state, const char *property, double def ); double rofi_theme_get_double ( const char *wclass, const char *name, const char *state, const char *property, double def );
void rofi_theme_get_color ( const char *wclass, const char *name, const char *state, const char *property, cairo_t *d); void rofi_theme_get_color ( const char *wclass, const char *name, const char *state, const char *property, cairo_t *d);
Padding rofi_theme_get_padding ( const char *wclass, const char *name, const char *state, const char *property, Padding pad ); Padding rofi_theme_get_padding ( const char *wclass, const char *name, const char *state, const char *property, Padding pad );
int distance_get_pixel ( Distance d );
#endif #endif

View file

@ -255,5 +255,6 @@ PangoAttrList *textbox_get_pango_attributes ( textbox *tb );
* @returns the visible text. * @returns the visible text.
*/ */
const char *textbox_get_visible_text ( const textbox *tb ); const char *textbox_get_visible_text ( const textbox *tb );
int distance_get_pixel ( Distance d );
/*@}*/ /*@}*/
#endif //ROFI_TEXTBOX_H #endif //ROFI_TEXTBOX_H

View file

@ -24,6 +24,7 @@ WORD [[:alnum:]-]+
STRING [[:print:]]+ STRING [[:print:]]+
HEX [[:xdigit:]] HEX [[:xdigit:]]
NUMBER [[:digit:]] NUMBER [[:digit:]]
REAL [[:digit:]]+(\.[[:digit:]]+)?
PX (px) PX (px)
EM (em) EM (em)
NEWLINES (\r|\n)+ NEWLINES (\r|\n)+
@ -106,14 +107,14 @@ if ( queue == NULL ){
<PROPERTIES>{NUMBER}+\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} <PROPERTIES>{NUMBER}+\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;}
<PROPERTIES>\"{STRING}\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;} <PROPERTIES>\"{STRING}\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;}
<PROPERTIES>{NUMBER}+{PX} { <PROPERTIES>{REAL}{EM} {
yylval->distance.distance = (int)g_ascii_strtoll(yytext, NULL, 10); yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL);
yylval->distance.type = PW_PX; yylval->distance.type = PW_EM;
return T_PIXEL; return T_PIXEL;
} }
<PROPERTIES>{NUMBER}+{EM} { <PROPERTIES>{NUMBER}+{PX} {
yylval->distance.distance = (int)g_ascii_strtoll(yytext, NULL, 10); yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10);
yylval->distance.type = PW_EM; yylval->distance.type = PW_PX;
return T_PIXEL; return T_PIXEL;
} }
<PROPERTIES>#{HEX}{8} { <PROPERTIES>#{HEX}{8} {

View file

@ -5,6 +5,8 @@
#include "theme.h" #include "theme.h"
#include "lexer/theme-parser.h" #include "lexer/theme-parser.h"
#include "helper.h" #include "helper.h"
#include "widgets/textbox.h"
void yyerror ( YYLTYPE *ylloc, const char *); void yyerror ( YYLTYPE *ylloc, const char *);
Widget *rofi_theme_find_or_create_class ( Widget *base, const char *class ) Widget *rofi_theme_find_or_create_class ( Widget *base, const char *class )
@ -88,7 +90,7 @@ static void rofi_theme_print_property_index ( int depth, Property *p )
(unsigned char)(p->value.color.blue*255.0)); (unsigned char)(p->value.color.blue*255.0));
break; break;
case P_PADDING: case P_PADDING:
printf("%d%s %d%s %d%s %d%s", printf("%f%s %f%s %f%s %f%s",
p->value.padding.left.distance, p->value.padding.left.distance,
p->value.padding.left.type == PW_PX? "px":"em", p->value.padding.left.type == PW_PX? "px":"em",
p->value.padding.right.distance, p->value.padding.right.distance,
@ -250,6 +252,15 @@ int rofi_theme_get_integer ( const char *wclass, const char *name, const char *
} }
return def; return def;
} }
Distance rofi_theme_get_distance ( const char *wclass, const char *name, const char *state, const char *property, int def )
{
Widget *widget = rofi_theme_find_widget ( wclass, name, state );
Property *p = rofi_theme_find_property ( widget, P_PADDING, property );
if ( p ){
return p->value.padding.left;
}
return (Distance){def, PW_PX};
}
int rofi_theme_get_boolean ( const char *wclass, const char *name, const char *state, const char *property, int def ) int rofi_theme_get_boolean ( const char *wclass, const char *name, const char *state, const char *property, int def )
{ {
@ -302,3 +313,11 @@ Padding rofi_theme_get_padding ( const char *wclass, const char *name, const ch
} }
return pad; return pad;
} }
int distance_get_pixel ( Distance d )
{
if ( d.type == PW_EM ){
return d.distance*textbox_get_estimated_char_height();
}
return d.distance;
}

View file

@ -351,7 +351,7 @@ box * box_create ( const char *name, boxType type )
b->widget.get_desired_height = box_get_desired_height; b->widget.get_desired_height = box_get_desired_height;
b->widget.enabled = TRUE; b->widget.enabled = TRUE;
box_set_spacing ( b, rofi_theme_get_integer ( b->widget.class_name, b->widget.name, NULL, "spacing",config.line_margin )); box_set_spacing ( b, distance_get_pixel (rofi_theme_get_distance ( b->widget.class_name, b->widget.name, NULL, "spacing",config.line_margin )));
return b; return b;
} }

View file

@ -349,7 +349,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
lv->udata = udata; lv->udata = udata;
// Some settings. // Some settings.
lv->spacing = rofi_theme_get_integer (lv->widget.class_name, lv->widget.name, NULL, "spacing", config.line_margin ); lv->spacing = distance_get_pixel (rofi_theme_get_distance (lv->widget.class_name, lv->widget.name, NULL, "spacing", config.line_margin ));
lv->menu_lines = rofi_theme_get_integer (lv->widget.class_name, lv->widget.name, NULL, "lines", config.menu_lines ); lv->menu_lines = rofi_theme_get_integer (lv->widget.class_name, lv->widget.name, NULL, "lines", config.menu_lines );
lv->menu_columns = rofi_theme_get_integer (lv->widget.class_name, lv->widget.name, NULL, "columns", config.menu_columns); lv->menu_columns = rofi_theme_get_integer (lv->widget.class_name, lv->widget.name, NULL, "columns", config.menu_columns);
lv->fixed_num_lines = rofi_theme_get_boolean (lv->widget.class_name, lv->widget.name, NULL, "fixed-height", config.fixed_num_lines ); lv->fixed_num_lines = rofi_theme_get_boolean (lv->widget.class_name, lv->widget.name, NULL, "fixed-height", config.fixed_num_lines );

View file

@ -215,31 +215,19 @@ void widget_set_name ( widget *wid, const char *name )
double textbox_get_estimated_char_height ( void ); double textbox_get_estimated_char_height ( void );
int widget_padding_get_left ( const widget *wid ) int widget_padding_get_left ( const widget *wid )
{ {
if ( wid->pad.left.type == PW_EM ){ return distance_get_pixel ( wid->pad.left );
return wid->pad.left.distance*textbox_get_estimated_char_height();
}
return wid->pad.left.distance;
} }
int widget_padding_get_right ( const widget *wid ) int widget_padding_get_right ( const widget *wid )
{ {
if ( wid->pad.right.type == PW_EM ){ return distance_get_pixel ( wid->pad.right );
return wid->pad.right.distance*textbox_get_estimated_char_height();
}
return wid->pad.right.distance;
} }
int widget_padding_get_top ( const widget *wid ) int widget_padding_get_top ( const widget *wid )
{ {
if ( wid->pad.top.type == PW_EM ){ return distance_get_pixel ( wid->pad.top );
return wid->pad.top.distance*textbox_get_estimated_char_height();
}
return wid->pad.top.distance;
} }
int widget_padding_get_bottom ( const widget *wid ) int widget_padding_get_bottom ( const widget *wid )
{ {
if ( wid->pad.bottom.type == PW_EM ){ return distance_get_pixel ( wid->pad.bottom );
return wid->pad.bottom.distance*textbox_get_estimated_char_height();
}
return wid->pad.bottom.distance;
} }
int widget_padding_get_remaining_width ( const widget *wid ) int widget_padding_get_remaining_width ( const widget *wid )