Skip to content

Commit a7cfc8d

Browse files
committed
feat: added a property view for String properties
1 parent aa6ed93 commit a7cfc8d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

fxgl-scene/src/main/kotlin/com/almasb/fxgl/ui/FXGLUIFactoryServiceProvider.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.almasb.fxgl.ui.FontType.UI
1111
import com.almasb.fxgl.ui.property.BooleanPropertyView
1212
import com.almasb.fxgl.ui.property.DoublePropertyView
1313
import com.almasb.fxgl.ui.property.IntPropertyView
14+
import com.almasb.fxgl.ui.property.StringPropertyView
1415
import javafx.beans.binding.*
1516
import javafx.beans.property.*
1617
import javafx.collections.ObservableList
@@ -148,6 +149,9 @@ class FXGLUIFactoryServiceProvider : UIFactoryService() {
148149
is ReadOnlyBooleanProperty -> BooleanPropertyView(property)
149150
is BooleanBinding -> BooleanPropertyView(property)
150151

152+
is ReadOnlyStringProperty -> StringPropertyView(property)
153+
is StringBinding -> StringPropertyView(property)
154+
151155
is ObjectProperty<*> -> {
152156

153157
if (property.get().javaClass in PropertyMapView.converters) {

fxgl-scene/src/main/kotlin/com/almasb/fxgl/ui/property/PropertyViews.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import com.almasb.fxgl.core.math.Vec2
1010
import javafx.beans.binding.BooleanExpression
1111
import javafx.beans.binding.DoubleExpression
1212
import javafx.beans.binding.IntegerExpression
13+
import javafx.beans.binding.StringExpression
1314
import javafx.beans.property.BooleanProperty
1415
import javafx.beans.property.ObjectProperty
1516
import javafx.beans.property.Property
1617
import javafx.beans.value.ObservableBooleanValue
1718
import javafx.beans.value.ObservableDoubleValue
1819
import javafx.beans.value.ObservableIntegerValue
20+
import javafx.beans.value.ObservableStringValue
1921
import javafx.scene.Parent
2022
import javafx.scene.control.CheckBox
2123
import javafx.scene.control.TextField
@@ -66,6 +68,19 @@ class BooleanPropertyView(property: ObservableBooleanValue) : CheckBox() {
6668
}
6769
}
6870

71+
class StringPropertyView(property: ObservableStringValue) : TextField() {
72+
73+
init {
74+
if (!property.javaClass.canonicalName.contains("ReadOnlyStringWrapper")) {
75+
textProperty().bindBidirectional(property as Property<String>)
76+
} else {
77+
textProperty().bind(property as StringExpression)
78+
79+
isDisable = true
80+
}
81+
}
82+
}
83+
6984
class Vec2PropertyView(property: ObjectProperty<Vec2>) : Parent() {
7085

7186
init {

0 commit comments

Comments
 (0)