mkpaz / atlantafx

Modern JavaFX CSS theme collection with additional controls.
https://mkpaz.github.io/atlantafx
MIT License
791 stars 64 forks source link

ModalPane dialog examples are not complete #87

Open mcantrell opened 5 months ago

mcantrell commented 5 months ago

Some of the snippets have the exact same content. For instance, the positioning sample is exactly the same as the default

image

It's also not clear that the pane needs to be used within a StackPane. Going through the source code for the sampler cleared things up but adding these details to the documentation would help save others some time.

mrasadatik commented 3 months ago

The documentation for modal pane in atlantaFX could benefit from including more comprehensive examples and potential workarounds. Here's an improved implementation of a ModalPane:

package com.example.modalpane;

import atlantafx.base.controls.ModalPane;
import atlantafx.base.theme.Styles;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.material2.Material2OutlinedAL;

public class App extends Application {
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setWidth(640);
        primaryStage.setHeight(480);
        primaryStage.setMinWidth(320);
        Scene scene = getScene();
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private static Scene getScene() {
        StackPane root = new StackPane();
        VBox sceneRoot = new VBox();
        ModalPane aboutModalPane = new ModalPane();

        aboutModalPane.setId("aboutModal");
        aboutModalPane.displayProperty().addListener((obs, old, val) -> {
            if (!val) {
                aboutModalPane.setAlignment(Pos.CENTER);
                aboutModalPane.usePredefinedTransitionFactories(null);
            }
        });

        Dialog aboutDialog = new Dialog(300, 300);

        Button aboutDialogOpenBtn = new Button(null, new FontIcon(Material2OutlinedAL.INFO));
        aboutDialogOpenBtn.getStyleClass().addAll(Styles.ROUNDED);
        aboutDialogOpenBtn.setOnAction(evt -> {
            aboutModalPane.show(aboutDialog);
        });

        Button aboutDialogCloseBtn = new Button(null, new FontIcon(Material2OutlinedAL.CLOSE));
        aboutDialogCloseBtn.getStyleClass().addAll(Styles.ROUNDED);
        aboutDialogCloseBtn.setOnAction(evt -> {
            aboutModalPane.hide(true);
        });
        aboutDialog.getChildren().setAll(aboutDialogCloseBtn);

        sceneRoot.getChildren().addAll(aboutDialogOpenBtn);

        root.getChildren().addAll(sceneRoot, aboutModalPane);

        return new Scene(root);
    }

    private static class Dialog extends VBox {

        public Dialog(int width, int height) {
            super();
            setSpacing(10);
            setMinSize(width, height);
            setMaxSize(width, height);
            setStyle("-fx-background-color: -color-bg-default;");
        }
    }
}