slider component finalization (#284) and padding_left = background.padding_left and padding_right = background.padding_right

This commit is contained in:
Felix Kratz 2022-12-31 18:37:34 +01:00
parent 26f5504445
commit dea17e9962
5 changed files with 39 additions and 16 deletions

View file

@ -97,24 +97,24 @@ static bool background_set_corner_radius(struct background* background, uint32_t
return true;
}
static bool background_set_padding_left(struct background* background, uint32_t pad) {
static bool background_set_yoffset(struct background* background, int offset) {
if (background->y_offset == offset) return false;
background->y_offset = offset;
return true;
}
bool background_set_padding_left(struct background* background, uint32_t pad) {
if (background->padding_left == pad) return false;
background->padding_left = pad;
return true;
}
static bool background_set_padding_right(struct background* background, uint32_t pad) {
bool background_set_padding_right(struct background* background, uint32_t pad) {
if (background->padding_right == pad) return false;
background->padding_right = pad;
return true;
}
static bool background_set_yoffset(struct background* background, int offset) {
if (background->y_offset == offset) return false;
background->y_offset = offset;
return true;
}
bool background_clip_needs_update(struct background* background, struct bar* bar) {
if (background->clip == 0.f || !background->enabled) return false;
struct background* clip = background_get_clip(background, bar->adid);

View file

@ -30,6 +30,8 @@ void background_calculate_bounds(struct background* background, uint32_t x, uint
bool background_set_enabled(struct background* background, bool enabled);
bool background_set_color(struct background* background, uint32_t color);
bool background_set_height(struct background* background, uint32_t height);
bool background_set_padding_left(struct background* background, uint32_t pad);
bool background_set_padding_right(struct background* background, uint32_t pad);
void background_draw(struct background* background, CGContextRef context);
struct background* background_get_clip(struct background* background, uint32_t adid);

View file

@ -745,6 +745,8 @@ void bar_item_serialize(struct bar_item* bar_item, FILE* rsp) {
"\t\t\"ignore_association\": \"%s\",\n"
"\t\t\"y_offset\": %d,\n"
"\t\t\"width\": %d,\n"
"\t\t\"padding_left\": %d,\n"
"\t\t\"padding_right\": %d,\n"
"\t\t\"background\": {\n",
bar_item->name,
type,
@ -754,6 +756,8 @@ void bar_item_serialize(struct bar_item* bar_item, FILE* rsp) {
bar_item->associated_display,
format_bool(bar_item->ignore_association),
bar_item->y_offset,
bar_item->background.padding_left,
bar_item->background.padding_right,
bar_item->has_const_width ? bar_item->custom_width : -1);
background_serialize(&bar_item->background, "\t\t\t", rsp, true);
@ -1024,6 +1028,20 @@ void bar_item_parse_set_message(struct bar_item* bar_item, char* message, FILE*
bar_item->y_offset,
token_to_int(token) );
} else if (token_equals(property, PROPERTY_PADDING_LEFT)) {
struct token token = get_token(&message);
ANIMATE(background_set_padding_left,
&bar_item->background,
bar_item->background.padding_left,
token_to_int(token) );
} else if (token_equals(property, PROPERTY_PADDING_RIGHT)) {
struct token token = get_token(&message);
ANIMATE(background_set_padding_right,
&bar_item->background,
bar_item->background.padding_right,
token_to_int(token) );
} else if (token_equals(property, PROPERTY_BLUR_RADIUS)) {
struct token token = get_token(&message);
ANIMATE(bar_item_set_blur_radius,

View file

@ -23,7 +23,6 @@ static bool slider_set_foreground_color(struct slider* slider, uint32_t color) {
void slider_init(struct slider* slider) {
slider->percentage = 0;
slider->bounds = CGRectNull;
slider->foreground_color = 0xff0000ff;
text_init(&slider->knob);
background_init(&slider->background);
@ -77,9 +76,11 @@ void slider_destroy(struct slider* slider) {
void slider_serialize(struct slider* slider, char* indent, FILE* rsp) {
fprintf(rsp, "%s\"highlight_color\": \"0x%x\",\n"
"%s\"percentage\": \"%d\",\n",
"%s\"percentage\": \"%d\",\n"
"%s\"width\": \"%d\",\n",
indent, slider->foreground_color,
indent, slider->percentage);
indent, slider->percentage,
indent, (int)slider->background.bounds.size.width);
char deeper_indent[strlen(indent) + 2];
snprintf(deeper_indent, strlen(indent) + 2, "%s\t", indent);
@ -96,8 +97,11 @@ void slider_serialize(struct slider* slider, char* indent, FILE* rsp) {
bool slider_parse_sub_domain(struct slider* slider, FILE* rsp, struct token property, char* message) {
bool needs_refresh = false;
if (token_equals(property, PROPERTY_PERCENTAGE)) {
needs_refresh = slider_set_percentage(slider,
token_to_uint32t(get_token(&message)));
struct token token = get_token(&message);
ANIMATE(slider_set_percentage,
slider,
slider->percentage,
token_to_uint32t(token));
}
else if (token_equals(property, PROPERTY_HIGHLIGHT_COLOR)) {
struct token token = get_token(&message);
@ -110,8 +114,8 @@ bool slider_parse_sub_domain(struct slider* slider, FILE* rsp, struct token prop
struct token token = get_token(&message);
ANIMATE(slider_set_width,
slider,
slider->bounds.size.width,
token_to_uint32t(token) );
slider->background.bounds.size.width,
token_to_uint32t(token) );
}
else if (token_equals(property, SUB_DOMAIN_KNOB)) {
needs_refresh = text_set_string(&slider->knob,

View file

@ -7,7 +7,6 @@ struct slider {
uint32_t percentage;
uint32_t foreground_color;
CGRect bounds;
struct text knob;
struct background background;
struct background foreground;