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

Window close should have an close callback listener #372

Open
ronjunevaldoz opened this issue Nov 5, 2022 · 1 comment
Open

Window close should have an close callback listener #372

ronjunevaldoz opened this issue Nov 5, 2022 · 1 comment

Comments

@ronjunevaldoz
Copy link

ronjunevaldoz commented Nov 5, 2022

Assume using kotlin

addCloseButton(onClose = {
    println("window closed")
})
	public void addCloseButton () {
		Label titleLabel = getTitleLabel();
		Table titleTable = getTitleTable();

		VisImageButton closeButton = new VisImageButton("close-window");
		titleTable.add(closeButton).padRight(-getPadRight() + 0.7f);
		closeButton.addListener(new ChangeListener() {
			@Override
			public void changed (ChangeEvent event, Actor actor) {
				close();
			}
		});
		closeButton.addListener(new ClickListener() {
			@Override
			public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
				event.cancel();
				return true;
			}
		});

		if (titleLabel.getLabelAlign() == Align.center && titleTable.getChildren().size == 2)
			titleTable.getCell(titleLabel).padLeft(closeButton.getWidth() * 2);
	}
@czyzby
Copy link
Collaborator

czyzby commented Nov 5, 2022

Callback support would probably be the most convenient approach, especially with Java 8+ or Kotlin. For now, the workaround would be to extend the class and override the protected void close method. Remember to call super if you want the default fade-out behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants