add scroll_duration property for texts (#478)

This commit is contained in:
Felix Kratz 2024-02-20 20:25:58 +01:00
parent a2be857304
commit 16858937e6
3 changed files with 16 additions and 4 deletions

View file

@ -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"

View file

@ -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);
@ -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;
@ -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;
@ -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;
@ -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)) {

View file

@ -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;