Scrolling text

The Weather Observation Name can be a long string, that doesn't fit into the 75% of the full width of a data field I allow for it, using a Tiny font size. I don't want to go any smaller or it is pretty much unreadable.

Is there a clever way to smoothly scroll a text screen within a fixed "mask" N pixels wide?

Altnerattuely I could parse the OBS name into words and scroll it at a word boundary, displaying only the set of full words that fit into the allowable window.

  • I have a class TextAnimation, that is something you could build on:

    // Copyright (C) 2022 by Gavriel Fleischer ([email protected])
    
    using Toybox.Lang;
    
    class TextAnimation {
        private var mAnimationSteps as Array;
        private var mIndex as Number;
        private var mDirection as Number;
    
        function initialize(animationSteps as Array) {
            if (animationSteps.size() < 2) {
                throw new Lang.InvalidOptionsException("min 2 steps required");
            }
            mAnimationSteps = animationSteps;
            reset();
        }
    
        function reset() as Void {
            mIndex = 0;
            mDirection = 1;
        }
    
        function next() {
            var item = mAnimationSteps[mIndex];
            mIndex += mDirection;
            if (mDirection < 0 && mIndex < 0) {
                mDirection = -mDirection;
                mIndex = 1;
            } else if (mDirection > 0 && mIndex >= mAnimationSteps.size()) {
                mDirection = -mDirection;
                mIndex = mAnimationSteps.size() - 2;
            }
            return item;
        }
    }

    The way to use it:

    hidden const SEARCH_ANIMATION = new TextAnimation(["+--", "-+-", "--+"]);
    
    str = SEARCH_ANIMATION.next();
    // or if needed then:
    SEARCH_ANIMATION.reset();
    

  • VERY COOL! Thanks! I'll give that a try.