All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.czyzby.lml.parser.impl.attribute.scroll.ScrollPercentLmlAttribute Maven / Gradle / Ivy

package com.github.czyzby.lml.parser.impl.attribute.scroll;

import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.github.czyzby.lml.parser.LmlParser;
import com.github.czyzby.lml.parser.action.ActorConsumer;
import com.github.czyzby.lml.parser.tag.LmlAttribute;
import com.github.czyzby.lml.parser.tag.LmlTag;
import com.github.czyzby.lml.util.LmlUtilities;

/** See {@link ScrollPane#setScrollPercentX(float)}, {@link ScrollPane#setScrollPercentY(float)}. Mapped to
 * "scrollPercent", "percent".
 *
 * @author MJ */
public class ScrollPercentLmlAttribute implements LmlAttribute {
    @Override
    public Class getHandledType() {
        return ScrollPane.class;
    }

    @Override
    public void process(final LmlParser parser, final LmlTag tag, final ScrollPane actor,
            final String rawAttributeData) {
        LmlUtilities.getLmlUserObject(actor).addOnCloseAction(new ActorConsumer() {
            @Override
            public Object consume(final Object widget) {
                actor.layout(); // Needed to calculate scroll pane size.
                final float percent = parser.parseFloat(rawAttributeData, actor);
                actor.setScrollPercentX(percent);
                actor.setScrollPercentY(percent);
                return null;
            }
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy