-
-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: javafx sliders are now replaced with FXGLSlider type
- Loading branch information
Showing
5 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
fxgl-scene/src/main/kotlin/com/almasb/fxgl/ui/FXGLSlider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* FXGL - JavaFX Game Library. The MIT License (MIT). | ||
* Copyright (c) AlmasB ([email protected]). | ||
* See LICENSE for details. | ||
*/ | ||
|
||
package com.almasb.fxgl.ui | ||
|
||
import javafx.scene.control.Slider | ||
import javafx.scene.effect.BoxBlur | ||
|
||
/** | ||
* | ||
* @author Almas Baimagambetov ([email protected]) | ||
*/ | ||
class FXGLSlider : Slider() { | ||
|
||
init { | ||
styleClass.add("fxgl-slider") | ||
|
||
effect = BoxBlur(1.2, 1.2, 2) | ||
|
||
valueProperty().addListener { _, _, newValue -> | ||
val percentage: Double = 100.0 * newValue.toDouble() / max | ||
|
||
// solution from https://stackoverflow.com/questions/51343759/how-to-change-fill-color-of-slider-in-javafx | ||
// in the String format, | ||
// %1$.1f%% gives the first format argument ("1$"), | ||
// i.e. percentage, formatted to 1 decimal place (".1f"). | ||
// Note literal % signs must be escaped ("%%") | ||
|
||
val style = String.format( | ||
"-track-color: linear-gradient(to right, " + | ||
"-active-color 0.5%%, " + | ||
"-active-color %1$.1f%%, " + | ||
"-inactive-color %1$.1f%%, " + | ||
"-inactive-color 100%%);", | ||
percentage | ||
) | ||
|
||
setStyle(style) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters