Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toast manager api improvements related to #374 #376

Merged
merged 4 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#### Version: 1.5.1-SNAPSHOT (libGDX 1.11.0)

- Updated to libGDX 1.11.0
- **Changed**: [#374](https://github.com/kotcrab/vis-ui/issues/374) - `ToastManager` now supports 'center' horizontal alignment for 'top' and 'bottom' alignments.
- Also `ToastManager.updateToastsPositions` and `ToastManager` member variables are now protected, allowing further customization of the toast positions.

#### Version: 1.5.0 (libGDX 1.10.0)
- Updated to libGDX 1.10.0
Expand Down
24 changes: 13 additions & 11 deletions ui/src/main/java/com/kotcrab/vis/ui/util/ToastManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
public class ToastManager {
public static final int UNTIL_CLOSED = -1;

private final Group root;
protected final Group root;

private int screenPaddingX = 20;
private int screenPaddingY = 20;
private int messagePadding = 5;
private int alignment = Align.topRight;
protected int screenPaddingX = 20;
protected int screenPaddingY = 20;
protected int messagePadding = 5;
protected int alignment = Align.topRight;

private Array<Toast> toasts = new Array<Toast>();
private ObjectMap<Toast, Timer.Task> timersTasks = new ObjectMap<Toast, Timer.Task>();
protected Array<Toast> toasts = new Array<Toast>();
protected ObjectMap<Toast, Timer.Task> timersTasks = new ObjectMap<Toast, Timer.Task>();

/** Toast manager will create own group to host toasts and put it into the stage root. */
public ToastManager (Stage stage) {
Expand Down Expand Up @@ -186,16 +186,18 @@ public void toFront () {
root.toFront();
}

private void updateToastsPositions () {
protected void updateToastsPositions () {
boolean bottom = (alignment & Align.bottom) != 0;
boolean left = (alignment & Align.left) != 0;
boolean center = (alignment & Align.center) != 0;
float y = bottom ? screenPaddingY : root.getHeight() - screenPaddingY;

for (Toast toast : toasts) {
Table table = toast.getMainTable();
table.setPosition(
left ? screenPaddingX : root.getWidth() - table.getWidth() - screenPaddingX,
bottom ? y : y - table.getHeight());
float x = left ? screenPaddingX
: center ? (root.getWidth() - table.getWidth() - screenPaddingX) / 2f
: /*right*/ root.getWidth() - table.getWidth() - screenPaddingX;
table.setPosition(x, bottom ? y : y - table.getHeight());

y += (table.getHeight() + messagePadding) * (bottom ? 1 : -1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void resize () {
});

final VisSelectBox<String> alignment = new VisSelectBox<String>();
alignment.setItems("top left", "top right", "bottom left", "bottom right");
alignment.setItems("top left", "top right", "top center", "bottom left", "bottom right", "bottom center");
alignment.setSelectedIndex(1);
alignment.addListener(new ChangeListener() {
@Override
Expand All @@ -63,11 +63,17 @@ public void changed (ChangeEvent event, Actor actor) {
toastManager.setAlignment(Align.topRight);
break;
case 2:
toastManager.setAlignment(Align.bottomLeft);
toastManager.setAlignment(Align.top | Align.center);
break;
case 3:
toastManager.setAlignment(Align.bottomLeft);
break;
case 4:
toastManager.setAlignment(Align.bottomRight);
break;
case 5:
toastManager.setAlignment(Align.bottom | Align.center);
break;
}
}
});
Expand Down