1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[Lexer] Support hsla

This commit is contained in:
Dave Davenport 2017-05-15 09:10:02 +02:00
parent 9d068151fd
commit f0ceeb86d8
3 changed files with 42 additions and 2 deletions

View file

@ -176,7 +176,7 @@ RGBA "rgba"
RGB "rgb"
HWB "hwb"
CMYK "cmyk"
HSL "hsl"
HSL hsl[a]?
S_T_PARENT_LEFT \(
S_T_PARENT_RIGHT \)

View file

@ -499,6 +499,17 @@ t_property_color
gdouble l = $8;
$$ = hsl_to_rgb ( h/360.0, s/100.0, l/100.0 );
$$.alpha = 1.0;
}
/** hsl ( 0-360 , 0-100 %, 0 - 100 %) */
| T_COL_HSL T_PARENT_LEFT T_INT T_COMMA t_property_color_value T_PERCENT T_COMMA t_property_color_value T_PERCENT T_COMMA t_property_color_value T_PERCENT T_PARENT_RIGHT {
if ( ! check_in_range($3, 0,360, &(@$)) ) { YYABORT; }
if ( ! check_in_range($5, 0,100, &(@$)) ) { YYABORT; }
if ( ! check_in_range($8, 0,100, &(@$)) ) { YYABORT; }
gdouble h = $3;
gdouble s = $5;
gdouble l = $8;
$$ = hsl_to_rgb ( h/360.0, s/100.0, l/100.0 );
$$.alpha = $11/100.0;
}
/** Hex colors parsed by lexer. */
| T_COLOR {

View file

@ -593,7 +593,35 @@ START_TEST ( test_properties_color_hsl )
widget wid;
wid.name = "blaat";
wid.state = NULL;
rofi_theme_parse_string ( "* { test1: hsl(127,40%,66.66666%); test2: hsl(0, 100%, 50%); }");
rofi_theme_parse_string ( "* { test1: hsl(127,40%,66.66666%); test2: hsl(0, 100%, 50%); testa: hsl(127,40%, 66.66666%, 30%);}");
ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE );
Property *p = rofi_theme_find_property ( twid, P_COLOR, "test1", FALSE );
ck_assert_ptr_nonnull ( p );
ck_assert_double_eq ( p->value.color.alpha , 1.0 );
ck_assert_double_eq_tol ( p->value.color.red , 0x88/255.0 , 0.004);
ck_assert_double_eq_tol ( p->value.color.green, 0xcd/255.0, 0.004 );
ck_assert_double_eq_tol ( p->value.color.blue , 0x90/255.0 , 0.004);
p = rofi_theme_find_property ( twid, P_COLOR, "test2", FALSE );
ck_assert_ptr_nonnull ( p );
ck_assert_double_eq ( p->value.color.alpha , 1.0 );
ck_assert_double_eq_tol ( p->value.color.red , 1 , 0.004);
ck_assert_double_eq_tol ( p->value.color.green , 0, 0.004 );
ck_assert_double_eq_tol ( p->value.color.blue , 0 , 0.004);
p = rofi_theme_find_property ( twid, P_COLOR, "testa", FALSE );
ck_assert_ptr_nonnull ( p );
ck_assert_double_eq ( p->value.color.alpha , 0.3 );
ck_assert_double_eq_tol ( p->value.color.red , 0x88/255.0 ,0.004);
ck_assert_double_eq_tol ( p->value.color.green ,0xcd/255.0, 0.004 );
ck_assert_double_eq_tol ( p->value.color.blue , 0x90/255.0 ,0.004);
}
END_TEST
START_TEST ( test_properties_color_hsla )
{
widget wid;
wid.name = "blaat";
wid.state = NULL;
rofi_theme_parse_string ( "* { test1: hsla(127,40%,66.66666%); test2: hsla(0, 100%, 50%); }");
ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE );
Property *p = rofi_theme_find_property ( twid, P_COLOR, "test1", FALSE );
@ -879,6 +907,7 @@ static Suite * theme_parser_suite (void)
tcase_add_test ( tc_prop_color, test_properties_color_rgba_percent);
tcase_add_test ( tc_prop_color, test_properties_color_argb);
tcase_add_test ( tc_prop_color, test_properties_color_hsl);
tcase_add_test ( tc_prop_color, test_properties_color_hsla);
tcase_add_test ( tc_prop_color, test_properties_color_hwb);
tcase_add_test ( tc_prop_color, test_properties_color_cmyk);
suite_add_tcase(s, tc_prop_color );