Skip to content

Commit

Permalink
wrap text on notifications when the line is too long
Browse files Browse the repository at this point in the history
  • Loading branch information
varun7654 committed Nov 6, 2023
1 parent 60dcf14 commit 59cdb8b
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.dacubeking.autobuilder.gui.util.RoundedShapeRenderer;
import space.earlygrey.shapedrawer.ShapeDrawer;

import static com.google.common.primitives.Floats.min;

public class Notification {
private final long deleteTime;
private final long creationTime;
Expand Down Expand Up @@ -52,8 +54,14 @@ public String toString() {

public boolean tick(ShapeDrawer drawer, Batch batch) {
long now = System.currentTimeMillis();
float renderHeight = (Gdx.graphics.getHeight()) + Math.min(Math.min((float) (now - creationTime) / ANIMATE_IN_OUT_TIME,
(float) (deleteTime - now) / ANIMATE_IN_OUT_TIME), 1) * (-50);
notification.setWrapWidth(Gdx.graphics.getWidth() - 20.0f);

float renderHeight = (Gdx.graphics.getHeight()) +
min((float) (now - creationTime) / ANIMATE_IN_OUT_TIME, // Appear part
(float) (deleteTime - now) / ANIMATE_IN_OUT_TIME, // Disappear part
1 // Maximum amount out
) * -(notification.getHeight() + notification.getBottomPaddingAmount() + 5); // Scale factor

RoundedShapeRenderer.roundedRect(drawer, Gdx.graphics.getWidth() / 2f - ((notification.getWidth() + 20) / 2f),
renderHeight, (notification.getWidth() + 20),
notification.getHeight() + notification.getBottomPaddingAmount(), 5, color);
Expand Down

0 comments on commit 59cdb8b

Please sign in to comment.