Skip to content

Commit

Permalink
add scroll_duration property for texts (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Feb 20, 2024
1 parent a2be857 commit 1685893
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/misc/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#define PROPERTY_SCALE "scale"
#define PROPERTY_STRING "string"
#define PROPERTY_SCROLL_TEXTS "scroll_texts"
#define PROPERTY_SCROLL_DURATION "scroll_duration"

#define PROPERTY_COLOR_HEX "hex"
#define PROPERTY_COLOR_ALPHA "alpha"
Expand Down
18 changes: 14 additions & 4 deletions src/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void text_init(struct text* text) {
text->max_chars = 0;
text->align = POSITION_LEFT;
text->scroll = 0.f;
text->scroll_duration = 100;

text->string = string_copy("");
text_set_string(text, text->string, false);
Expand Down Expand Up @@ -177,6 +178,12 @@ static bool text_set_yoffset(struct text* text, int offset) {
return true;
}

static bool text_set_scroll_duration(struct text* text, int duration) {
if (duration < 0) return false;
text->scroll_duration = duration;
return false;
}

static bool text_set_width(struct text* text, int width) {
if (width < 0) {
bool prev = text->has_const_width;
Expand Down Expand Up @@ -266,10 +273,10 @@ bool text_set_scroll(struct text* text, float scroll) {
bool text_animate_scroll(struct text* text) {
if (text->max_chars == 0) return false;
if (text->scroll != 0) return false;
if (text->has_const_width && text->custom_width == 0) return false;
if (text->has_const_width && text->custom_width < text->width) return false;
if (text->width == 0 || text->width == text->bounds.size.width) return false;

g_bar_manager.animator.duration = 100
g_bar_manager.animator.duration = text->scroll_duration
* (text->bounds.size.width / text->width);
g_bar_manager.animator.interp_function = INTERP_FUNCTION_LINEAR;

Expand All @@ -285,8 +292,8 @@ bool text_animate_scroll(struct text* text) {
text->scroll,
-max(text->width, 0));

g_bar_manager.animator.duration = 100;
;
g_bar_manager.animator.duration = text->scroll_duration;

ANIMATE_FLOAT(text_set_scroll, text, text->scroll, 0);

g_bar_manager.animator.duration = 0;
Expand Down Expand Up @@ -471,6 +478,9 @@ bool text_parse_sub_domain(struct text* text, FILE* rsp, struct token property,
text->y_offset,
token_to_int(token));

} else if (token_equals(property, PROPERTY_SCROLL_DURATION)) {
struct token token = get_token(&message);
text_set_scroll_duration(text, token_to_int(token));
} else if (token_equals(property, PROPERTY_WIDTH)) {
struct token token = get_token(&message);
if (token_equals(token, ARGUMENT_DYNAMIC)) {
Expand Down
1 change: 1 addition & 0 deletions src/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct text {
int padding_right;
uint32_t custom_width;
uint32_t max_chars;
uint32_t scroll_duration;
float scroll;
float width;

Expand Down

0 comments on commit 1685893

Please sign in to comment.