1717 */
1818package org .jackhuang .hmcl .ui ;
1919
20+ import com .jfoenix .controls .JFXButton ;
2021import com .jfoenix .controls .JFXListView ;
2122import javafx .beans .binding .Bindings ;
2223import javafx .geometry .Insets ;
2324import javafx .geometry .Pos ;
2425import javafx .scene .Node ;
26+ import javafx .scene .control .ListCell ;
2527import javafx .scene .control .SkinBase ;
2628import javafx .scene .layout .HBox ;
2729import javafx .scene .layout .Priority ;
@@ -61,6 +63,19 @@ public ToolbarListPageSkin2(P skinnable) {
6163 {
6264 this .listView = new JFXListView <>();
6365 this .listView .setPadding (Insets .EMPTY );
66+ this .listView .setCellFactory (listView -> new ListCell <>() {
67+ @ Override
68+ protected void updateItem (E item , boolean empty ) {
69+ super .updateItem (item , empty );
70+ if (!empty && item instanceof Node node ) {
71+ setGraphic (node );
72+ setText (null );
73+ } else {
74+ setGraphic (null );
75+ setText (null );
76+ }
77+ }
78+ });
6479 ComponentList .setVgrow (listView , Priority .ALWAYS );
6580 Bindings .bindContent (this .listView .getItems (), skinnable .itemsProperty ());
6681 root .getContent ().add (listView );
@@ -71,5 +86,30 @@ public ToolbarListPageSkin2(P skinnable) {
7186 getChildren ().setAll (spinnerPane );
7287 }
7388
89+ public static Node wrap (Node node ) {
90+ StackPane stackPane = new StackPane ();
91+ stackPane .setPadding (new Insets (0 , 5 , 0 , 2 ));
92+ stackPane .getChildren ().setAll (node );
93+ return stackPane ;
94+ }
95+
96+ public static JFXButton createToolbarButton2 (String text , SVG svg , Runnable onClick ) {
97+ JFXButton ret = new JFXButton ();
98+ ret .getStyleClass ().add ("jfx-tool-bar-button" );
99+ ret .setGraphic (wrap (svg .createIcon ()));
100+ ret .setText (text );
101+ ret .setOnAction (e -> onClick .run ());
102+ return ret ;
103+ }
104+
105+ public static JFXButton createDecoratorButton (String tooltip , SVG svg , Runnable onClick ) {
106+ JFXButton ret = new JFXButton ();
107+ ret .getStyleClass ().add ("jfx-decorator-button" );
108+ ret .setGraphic (wrap (svg .createIcon ()));
109+ FXUtils .installFastTooltip (ret , tooltip );
110+ ret .setOnAction (e -> onClick .run ());
111+ return ret ;
112+ }
113+
74114 protected abstract List <Node > initializeToolbar (P skinnable );
75115}
0 commit comments