Improve code snippet viewer

This commit is contained in:
mkpaz 2023-05-17 16:17:55 +04:00
parent 70043895b0
commit 9438ef66d8
2 changed files with 13 additions and 6 deletions

@ -11,17 +11,15 @@ import javafx.beans.property.SimpleObjectProperty;
import javafx.css.PseudoClass; import javafx.css.PseudoClass;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.input.Clipboard; import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent; import javafx.scene.input.ClipboardContent;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.material2.Material2OutlinedAL;
// This widget emulates TabPane behavior, because TabPane itself doesn't work as it should: // This widget emulates TabPane behavior, because TabPane itself doesn't work as it should:
// https://bugs.openjdk.org/browse/JDK-8145490 // https://bugs.openjdk.org/browse/JDK-8145490
@ -44,9 +42,9 @@ public class ExampleBox extends VBox {
var previewTab = createTabLabel("Preview"); var previewTab = createTabLabel("Preview");
var codeTab = createTabLabel("Code"); var codeTab = createTabLabel("Code");
var copyBtn = new Button("", new FontIcon(Material2OutlinedAL.CODE)); var copyBtn = new Button("copy source code");
copyBtn.getStyleClass().addAll(Styles.BUTTON_CIRCLE, Styles.FLAT, Styles.SMALL); copyBtn.setCursor(Cursor.HAND);
copyBtn.setTooltip(new Tooltip("Copy source code")); copyBtn.getStyleClass().addAll(Styles.FLAT, Styles.SMALL);
stateToggle = new ToggleSwitch(); stateToggle = new ToggleSwitch();
HBox.setMargin(stateToggle, new Insets(0, 0, 0, 10)); HBox.setMargin(stateToggle, new Insets(0, 0, 0, 10));

@ -29,9 +29,18 @@
} }
.snippet { .snippet {
-fx-border-radius: 8px;
-fx-border-color: transparent;
-fx-border-width: 3px;
&:hover {
-fx-border-color: -color-accent-muted;
}
>TextFlow { >TextFlow {
-fx-padding: 10px; -fx-padding: 10px;
-fx-background-color: -color-bg-inset; -fx-background-color: -color-bg-inset;
-fx-background-radius: 8px;
-fx-font-family: monospace; -fx-font-family: monospace;
} }