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