mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-26 21:30:17 +00:00
allow animating from/to dynamic width
This commit is contained in:
parent
44fd3a138d
commit
9951e25ccd
2 changed files with 29 additions and 6 deletions
|
@ -379,7 +379,12 @@ bool bar_item_set_blur_radius(struct bar_item* bar_item, uint32_t radius) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool bar_item_set_width(struct bar_item* bar_item, uint32_t width) {
|
||||
bool bar_item_set_width(struct bar_item* bar_item, int width) {
|
||||
if (width < 0) {
|
||||
bool prev = bar_item->has_const_width;
|
||||
bar_item->has_const_width = false;
|
||||
return prev != bar_item->has_const_width;
|
||||
}
|
||||
if (bar_item->custom_width == width && bar_item->has_const_width)
|
||||
return false;
|
||||
|
||||
|
@ -848,14 +853,32 @@ void bar_item_parse_set_message(struct bar_item* bar_item, char* message, FILE*
|
|||
} else if (token_equals(property, PROPERTY_WIDTH)) {
|
||||
struct token token = get_token(&message);
|
||||
if (token_equals(token, ARGUMENT_DYNAMIC)) {
|
||||
needs_refresh = bar_item->has_const_width;
|
||||
bar_item->has_const_width = false;
|
||||
if (bar_item->has_const_width) {
|
||||
ANIMATE(bar_item_set_width,
|
||||
bar_item,
|
||||
bar_item->custom_width,
|
||||
bar_item_get_length(bar_item, true)
|
||||
+ bar_item->background.padding_left
|
||||
+ bar_item->background.padding_right);
|
||||
|
||||
struct animation* animation = animation_create();
|
||||
animation_setup(animation,
|
||||
bar_item,
|
||||
(bool (*)(void*, int))&bar_item_set_width,
|
||||
bar_item->custom_width,
|
||||
-1,
|
||||
1,
|
||||
INTERP_FUNCTION_LINEAR );
|
||||
animator_add(&g_bar_manager.animator, animation);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ANIMATE(bar_item_set_width,
|
||||
bar_item,
|
||||
bar_item->custom_width,
|
||||
token_to_int(token) );
|
||||
bar_item_get_length(bar_item, false)
|
||||
+ bar_item->background.padding_left
|
||||
+ bar_item->background.padding_right,
|
||||
token_to_int(token) );
|
||||
}
|
||||
} else if (token_equals(property, PROPERTY_SCRIPT)) {
|
||||
bar_item_set_script(bar_item, token_to_string(get_token(&message)));
|
||||
|
|
|
@ -101,7 +101,7 @@ void bar_item_set_script(struct bar_item* bar_item, char* script);
|
|||
void bar_item_set_click_script(struct bar_item* bar_item, char* script);
|
||||
bool bar_item_set_drawing(struct bar_item* bar_item, bool state);
|
||||
bool bar_item_set_yoffset(struct bar_item* bar_item, int offset);
|
||||
bool bar_item_set_width(struct bar_item* bar_item, uint32_t width);
|
||||
bool bar_item_set_width(struct bar_item* bar_item, int width);
|
||||
|
||||
uint32_t bar_item_get_length(struct bar_item* bar_item, bool ignore_override);
|
||||
uint32_t bar_item_get_height(struct bar_item* bar_item);
|
||||
|
|
Loading…
Reference in a new issue