scrolling text fixed positioning
This commit is contained in:
parent
c6a80e9e57
commit
991ff711e6
@ -20,6 +20,7 @@ import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
@ -102,8 +103,8 @@ public class MusicSelectable extends Button implements Disposable {
|
||||
}
|
||||
|
||||
|
||||
public void addInfoToPanel() {
|
||||
displayName = new ScrollText(songName, skin, true);
|
||||
public void addInfoToPanel(ScrollPane scroller) {
|
||||
displayName = new ScrollText(songName, skin, true, scroller);
|
||||
|
||||
defaults().align(Align.top);
|
||||
|
||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Widget;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
@ -25,10 +26,11 @@ public class ScrollText extends Widget {
|
||||
private boolean currentlyHovering;
|
||||
|
||||
private float textOffset;
|
||||
public ScrollText(String text, Skin skin, boolean scrollOnHover) {
|
||||
private ScrollPane scrollCoords;
|
||||
public ScrollText(String text, Skin skin, boolean scrollOnHover, ScrollPane scrollCoords) {
|
||||
super();
|
||||
setName(text);
|
||||
|
||||
this.scrollCoords = scrollCoords;
|
||||
this.scrollOnHover = scrollOnHover;
|
||||
|
||||
this.text = text;
|
||||
@ -71,13 +73,12 @@ public class ScrollText extends Widget {
|
||||
|
||||
@Override
|
||||
public void layout() {
|
||||
clipBounds.set(getParent().getX()+getX(), getParent().getY()+getY(), getWidth(), getHeight());
|
||||
clipBounds.set(getParent().getX()+getX()-scrollCoords.getVisualScrollX(), getParent().getY()+getY(), getWidth(), getHeight());
|
||||
super.layout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
clipBounds.setPosition(getParent().getX()+getX(), getParent().getY()+getY());
|
||||
if (fontWidth > clipBounds.getWidth()) {
|
||||
if (scrollOnHover) {
|
||||
if ((int) textOffset != 0 || currentlyHovering) {
|
||||
@ -100,7 +101,7 @@ public class ScrollText extends Widget {
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
validate();
|
||||
|
||||
clipBounds.setX(getParent().getX()+getX()+scrollCoords.getWidget().getX());
|
||||
getStage().calculateScissors(clipBounds, scissors);
|
||||
|
||||
batch.flush();
|
||||
|
@ -7,7 +7,6 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
@ -27,6 +26,7 @@ public class MusicSelectionPage extends Page {
|
||||
Preferences musicFileAnnotation;
|
||||
private Polyjet core;
|
||||
private volatile Label status;
|
||||
private volatile ScrollPane musicChoiceScroller;
|
||||
|
||||
public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu) {
|
||||
super("Select music", core.defaultSkin);
|
||||
@ -52,13 +52,14 @@ public class MusicSelectionPage extends Page {
|
||||
addActor(loading);
|
||||
|
||||
status = new Label("Loading: ", core.defaultSkin, "sub-font", core.defaultSkin.getColor("default"));
|
||||
status.setPosition(loading.getX()+loading.getWidth()+12f, loading.getY()-15f);
|
||||
status.setPosition(loading.getX()+loading.getWidth()+12f, loading.getY());
|
||||
addActor(status);
|
||||
|
||||
|
||||
musicChoices = new Table();
|
||||
musicChoices.defaults().pad(10f);
|
||||
ScrollPane musicChoiceScroller = new ScrollPane(musicChoices);
|
||||
musicChoiceScroller = new ScrollPane(musicChoices);
|
||||
musicChoiceScroller.setScrollingDisabled(false, true);
|
||||
musicChoiceScroller.setSize(getWidth(), getHeight()*0.85f);
|
||||
addActor(musicChoiceScroller);
|
||||
}
|
||||
@ -92,7 +93,7 @@ public class MusicSelectionPage extends Page {
|
||||
public void run() {
|
||||
Gdx.app.debug("Music Search Thread", "Finished loading: " + selectable.getName());
|
||||
musicChoices.add(selectable).prefSize(256, 0.8f*getHeight());
|
||||
selectable.addInfoToPanel();
|
||||
selectable.addInfoToPanel(musicChoiceScroller);
|
||||
}
|
||||
});
|
||||
System.out.println(music);
|
||||
@ -100,8 +101,9 @@ public class MusicSelectionPage extends Page {
|
||||
status.setText("Loading: " + prog + "%");
|
||||
}
|
||||
|
||||
loading.clearActions();
|
||||
status.setText("Done!");
|
||||
status.remove();
|
||||
loading.remove();
|
||||
|
||||
} else {
|
||||
loading.clearActions();
|
||||
status.setText("No music found.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user