Skip to content

Commit

Permalink
add app tittle below icon and fix css
Browse files Browse the repository at this point in the history
  • Loading branch information
peretr committed May 25, 2026
1 parent 6901435 commit 8bae994
Showing 1 changed file with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import javafx.scene.Node;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

/**
Expand All @@ -38,7 +40,8 @@ public record DesktopComponentFactory(
* @param type the application type
* @return the created application button node
*/
public Node createAppButton(final App type) {
public VBox createAppButton(final App type) {
final VBox buttonContainer = new VBox();
Button button = new Button();
button.setStyle(
"-fx-background-color: transparent; -fx-padding: 0; -fx-border-color: transparent;"
Expand Down Expand Up @@ -73,8 +76,15 @@ public Node createAppButton(final App type) {
bindButtonSize(button, newParent));

popupsController.bindOpenButton(button, type);
setupDrag(button);
return button;
setupDrag(button, buttonContainer);

Label appName = new Label(type.getDisplayName());
appName.setStyle(
"-fx-font-size: 12px; -fx-font-weight: bold; -fx-text-fill: white; -fx-wrap-text: true;");
buttonContainer.setAlignment(javafx.geometry.Pos.CENTER);
buttonContainer.setSpacing(5);
buttonContainer.getChildren().addAll(button, appName);
return buttonContainer;
}

private String iconPath(final App type) {
Expand Down Expand Up @@ -102,12 +112,12 @@ private void bindButtonSize(final Button button, final Object parent) {
}
}

private void setupDrag(final Button button) {
private void setupDrag(final Button button, final VBox container) {
button.setOnDragDetected(event -> {
Dragboard dragboard = button.startDragAndDrop(TransferMode.MOVE);
Dragboard dragboard = container.startDragAndDrop(TransferMode.MOVE);
SnapshotParameters params = new SnapshotParameters();
params.setFill(Color.TRANSPARENT);
dragboard.setDragView(button.snapshot(params, null));
dragboard.setDragView(container.snapshot(params, null));
dragboard.setDragViewOffsetX(event.getX());
dragboard.setDragViewOffsetY(event.getY());
ClipboardContent content = new ClipboardContent();
Expand All @@ -119,14 +129,14 @@ private void setupDrag(final Button button) {

private void applyIconClip(
final javafx.scene.image.ImageView icon,
final double w,
final double h) {
if (w <= 0 || h <= 0) {
final double width,
final double height) {
if (width <= 0 || height <= 0) {
return;
}
javafx.scene.shape.Rectangle clip = new javafx.scene.shape.Rectangle(w, h);
clip.setArcWidth(w * 0.45);
clip.setArcHeight(h * 0.45);
javafx.scene.shape.Rectangle clip = new javafx.scene.shape.Rectangle(width, height);
clip.setArcWidth(width * 0.45);
clip.setArcHeight(height * 0.45);
icon.setClip(clip);
}

Expand All @@ -137,17 +147,18 @@ private void applyIconClip(
*/
public void configureCellAsDropTarget(final StackPane cell) {
cell.setOnDragOver(event -> {
if (event.getGestureSource() instanceof Button && cell.getChildren().isEmpty()) {
if (event.getGestureSource() instanceof VBox && cell.getChildren().isEmpty()) {
event.acceptTransferModes(TransferMode.MOVE);
}
event.consume();
});

cell.setOnDragDropped(event -> {
boolean success = false;
if (event.getGestureSource() instanceof Button button) {
((StackPane) button.getParent()).getChildren().remove(button);
cell.getChildren().add(button);
if (event.getGestureSource() instanceof VBox container) {
StackPane source = (StackPane) container.getParent();
source.getChildren().remove(container);
cell.getChildren().add(container);
success = true;
}
event.setDropCompleted(success);
Expand Down

0 comments on commit 8bae994

Please sign in to comment.