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:
parent
52e850dc33
commit
7b0e0643c8
7 changed files with 38 additions and 26 deletions
|
@ -9,7 +9,7 @@ typedef enum {
|
|||
} PixelWidth;
|
||||
|
||||
typedef struct {
|
||||
int distance;
|
||||
double distance;
|
||||
PixelWidth type;
|
||||
} Distance;
|
||||
|
||||
|
@ -86,10 +86,13 @@ void rofi_theme_widget_add_properties ( Widget *widget, GHashTable *table );
|
|||
* 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_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 );
|
||||
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);
|
||||
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
|
||||
|
|
|
@ -255,5 +255,6 @@ PangoAttrList *textbox_get_pango_attributes ( textbox *tb );
|
|||
* @returns the visible text.
|
||||
*/
|
||||
const char *textbox_get_visible_text ( const textbox *tb );
|
||||
int distance_get_pixel ( Distance d );
|
||||
/*@}*/
|
||||
#endif //ROFI_TEXTBOX_H
|
||||
|
|
|
@ -24,6 +24,7 @@ WORD [[:alnum:]-]+
|
|||
STRING [[:print:]]+
|
||||
HEX [[:xdigit:]]
|
||||
NUMBER [[:digit:]]
|
||||
REAL [[:digit:]]+(\.[[:digit:]]+)?
|
||||
PX (px)
|
||||
EM (em)
|
||||
NEWLINES (\r|\n)+
|
||||
|
@ -106,14 +107,14 @@ if ( queue == NULL ){
|
|||
<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>{NUMBER}+{PX} {
|
||||
yylval->distance.distance = (int)g_ascii_strtoll(yytext, NULL, 10);
|
||||
yylval->distance.type = PW_PX;
|
||||
<PROPERTIES>{REAL}{EM} {
|
||||
yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL);
|
||||
yylval->distance.type = PW_EM;
|
||||
return T_PIXEL;
|
||||
}
|
||||
<PROPERTIES>{NUMBER}+{EM} {
|
||||
yylval->distance.distance = (int)g_ascii_strtoll(yytext, NULL, 10);
|
||||
yylval->distance.type = PW_EM;
|
||||
<PROPERTIES>{NUMBER}+{PX} {
|
||||
yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10);
|
||||
yylval->distance.type = PW_PX;
|
||||
return T_PIXEL;
|
||||
}
|
||||
<PROPERTIES>#{HEX}{8} {
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "theme.h"
|
||||
#include "lexer/theme-parser.h"
|
||||
#include "helper.h"
|
||||
#include "widgets/textbox.h"
|
||||
|
||||
void yyerror ( YYLTYPE *ylloc, const char *);
|
||||
|
||||
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));
|
||||
break;
|
||||
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.type == PW_PX? "px":"em",
|
||||
p->value.padding.right.distance,
|
||||
|
@ -250,6 +252,15 @@ int rofi_theme_get_integer ( const char *wclass, const char *name, const char *
|
|||
}
|
||||
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 )
|
||||
{
|
||||
|
@ -302,3 +313,11 @@ Padding rofi_theme_get_padding ( const char *wclass, const char *name, const ch
|
|||
}
|
||||
return pad;
|
||||
}
|
||||
|
||||
int distance_get_pixel ( Distance d )
|
||||
{
|
||||
if ( d.type == PW_EM ){
|
||||
return d.distance*textbox_get_estimated_char_height();
|
||||
}
|
||||
return d.distance;
|
||||
}
|
||||
|
|
|
@ -351,7 +351,7 @@ box * box_create ( const char *name, boxType type )
|
|||
b->widget.get_desired_height = box_get_desired_height;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -349,7 +349,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
|
|||
lv->udata = udata;
|
||||
|
||||
// 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_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 );
|
||||
|
|
|
@ -215,31 +215,19 @@ void widget_set_name ( widget *wid, const char *name )
|
|||
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_height();
|
||||
}
|
||||
return wid->pad.left.distance;
|
||||
return distance_get_pixel ( wid->pad.left );
|
||||
}
|
||||
int widget_padding_get_right ( const widget *wid )
|
||||
{
|
||||
if ( wid->pad.right.type == PW_EM ){
|
||||
return wid->pad.right.distance*textbox_get_estimated_char_height();
|
||||
}
|
||||
return wid->pad.right.distance;
|
||||
return distance_get_pixel ( wid->pad.right );
|
||||
}
|
||||
int widget_padding_get_top ( const widget *wid )
|
||||
{
|
||||
if ( wid->pad.top.type == PW_EM ){
|
||||
return wid->pad.top.distance*textbox_get_estimated_char_height();
|
||||
}
|
||||
return wid->pad.top.distance;
|
||||
return distance_get_pixel ( wid->pad.top );
|
||||
}
|
||||
int widget_padding_get_bottom ( const widget *wid )
|
||||
{
|
||||
if ( wid->pad.bottom.type == PW_EM ){
|
||||
return wid->pad.bottom.distance*textbox_get_estimated_char_height();
|
||||
}
|
||||
return wid->pad.bottom.distance;
|
||||
return distance_get_pixel ( wid->pad.bottom );
|
||||
}
|
||||
|
||||
int widget_padding_get_remaining_width ( const widget *wid )
|
||||
|
|
Loading…
Reference in a new issue