mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
added: toggle
This commit is contained in:
@@ -3,13 +3,18 @@ package org.toop.app.layer;
|
|||||||
import org.toop.app.events.AppEvents;
|
import org.toop.app.events.AppEvents;
|
||||||
import org.toop.framework.eventbus.GlobalEventBus;
|
import org.toop.framework.eventbus.GlobalEventBus;
|
||||||
|
|
||||||
|
import javafx.beans.property.BooleanProperty;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.layout.Region;
|
import javafx.scene.layout.Region;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public final class Container {
|
public final class Container {
|
||||||
public enum Type {
|
public enum Type {
|
||||||
VERTICAL, HORIZONTAL,
|
VERTICAL, HORIZONTAL,
|
||||||
@@ -82,5 +87,36 @@ public final class Container {
|
|||||||
return addButton("button", x, runnable);
|
return addButton("button", x, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Label addToggle(String cssClass, String unChecked, String checked, Consumer<Boolean> consumer) {
|
||||||
|
final Label element = new Label(unChecked);
|
||||||
|
element.getStyleClass().add(cssClass);
|
||||||
|
|
||||||
|
final BooleanProperty selected = new SimpleBooleanProperty(false);
|
||||||
|
|
||||||
|
element.setOnMouseEntered(_ -> {
|
||||||
|
GlobalEventBus.post(new AppEvents.OnNodeHover());
|
||||||
|
});
|
||||||
|
|
||||||
|
element.setOnMouseClicked(_ -> {
|
||||||
|
GlobalEventBus.post(new AppEvents.OnNodeClick());
|
||||||
|
selected.set(!selected.get());
|
||||||
|
|
||||||
|
if (selected.get()) {
|
||||||
|
element.setText(checked);
|
||||||
|
} else {
|
||||||
|
element.setText(unChecked);
|
||||||
|
}
|
||||||
|
|
||||||
|
consumer.accept(selected.get());
|
||||||
|
});
|
||||||
|
|
||||||
|
container.getChildren().addLast(element);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Label addToggle(String unChecked, String checked, Consumer<Boolean> consumer) {
|
||||||
|
return addToggle("toggle", unChecked, checked, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
public Pane getContainer() { return container; }
|
public Pane getContainer() { return container; }
|
||||||
}
|
}
|
||||||
@@ -11,9 +11,19 @@ public class SelectionLayer extends Layer {
|
|||||||
protected SelectionLayer(GameType type) {
|
protected SelectionLayer(GameType type) {
|
||||||
super("selection.css");
|
super("selection.css");
|
||||||
|
|
||||||
|
final Container player1Container = Container.create(Container.Type.HORIZONTAL, 5);
|
||||||
|
player1Container.addToggle("test","other test", (checked) -> {
|
||||||
|
if (checked) {
|
||||||
|
System.out.println("Checked");
|
||||||
|
} else {
|
||||||
|
System.out.println("Un checked");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
final Container controlContainer = Container.create(Container.Type.VERTICAL, 5);
|
final Container controlContainer = Container.create(Container.Type.VERTICAL, 5);
|
||||||
controlContainer.addButton("Back", () -> { App.activate(new MainLayer()); });
|
controlContainer.addButton("Back", () -> { App.activate(new MainLayer()); });
|
||||||
|
|
||||||
|
addContainer(player1Container, Pos.TOP_LEFT, 2, 2);
|
||||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2);
|
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
-fx-font-size: 24px;
|
-fx-font-size: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button, .toggle {
|
||||||
-fx-padding: 10;
|
-fx-padding: 10;
|
||||||
|
|
||||||
-fx-background-color: transparent;
|
-fx-background-color: transparent;
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
-fx-transition: all 0.3s ease-in-out;
|
-fx-transition: all 0.3s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button:hover {
|
.button:hover, .toggle:hover {
|
||||||
-fx-cursor: hand;
|
-fx-cursor: hand;
|
||||||
|
|
||||||
-fx-scale-x: 1.1;
|
-fx-scale-x: 1.1;
|
||||||
|
|||||||
Reference in New Issue
Block a user