Skip to content

Commit

Permalink
[bgw-gui] Added visuals to TextInputUIComponent (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
smilefx authored Nov 21, 2023
1 parent 9df6719 commit ce07f5e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
6 changes: 6 additions & 0 deletions bgw-gui/src/main/kotlin/tools/aqua/bgw/builder/NodeBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import tools.aqua.bgw.components.gamecomponentviews.HexagonView
import tools.aqua.bgw.components.layoutviews.CameraPane
import tools.aqua.bgw.components.layoutviews.LayoutView
import tools.aqua.bgw.components.layoutviews.Pane
import tools.aqua.bgw.components.uicomponents.TextInputUIComponent
import tools.aqua.bgw.components.uicomponents.UIComponent
import tools.aqua.bgw.core.BoardGameScene
import tools.aqua.bgw.core.Scene
Expand Down Expand Up @@ -172,6 +173,11 @@ object NodeBuilder {
if (nV.isNotEmpty()) background?.style = nV
}

if (this is TextInputUIComponent) {
this.internalCSS =
"-fx-control-inner-background: transparent; -fx-highlight-fill: dodgerblue; -fx-background-color: transparent; "
}

fontProperty.guiListener = { _, _ -> updateStyle(node) }
internalCSSProperty.guiListener = { _, _ -> updateStyle(node) }
componentStyleProperty.setGUIListenerAndInvoke(componentStyle) { _, _ -> updateStyle(node) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package tools.aqua.bgw.builder

import com.jfoenix.controls.*
import java.awt.Color
import java.io.FileNotFoundException
import javafx.beans.property.BooleanProperty as FXBooleanProperty
import javafx.beans.property.ObjectProperty as FXObjectProperty
import javafx.beans.property.StringProperty as FXStringProperty
Expand Down Expand Up @@ -84,6 +85,8 @@ object UINodeBuilder {
textProperty().bindTextProperty(textArea)
promptTextProperty().bindPromptProperty(textArea)
disableUndo()
val resource = this::class.java.getResource("/style.css") ?: throw FileNotFoundException()
stylesheets.add(resource.toExternalForm())
}

/** Builds [TextField]. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

package tools.aqua.bgw.components.uicomponents

import java.awt.Color
import tools.aqua.bgw.core.DEFAULT_TEXT_FIELD_HEIGHT
import tools.aqua.bgw.core.DEFAULT_TEXT_FIELD_WIDTH
import tools.aqua.bgw.util.Font
import tools.aqua.bgw.visual.ColorVisual
import tools.aqua.bgw.visual.Visual

/**
* A [PasswordField] is a single line input field that shows stars instead of typed text.
Expand All @@ -36,6 +39,7 @@ import tools.aqua.bgw.util.Font
* @param prompt Prompt for this [PasswordField]. This gets displayed as a prompt to the user
* whenever the label is an empty string. Default: empty string.
* @param font [Font] to be used to display [text].
* @param visual [Visual] to be used as a background. Defaults to a Light-gray [ColorVisual].
*
* @see TextField
* @see TextArea
Expand All @@ -47,7 +51,8 @@ open class PasswordField(
height: Number = DEFAULT_TEXT_FIELD_HEIGHT,
text: String = "",
prompt: String = "",
font: Font = Font()
font: Font = Font(),
visual: Visual = ColorVisual(Color(240, 240, 240))
) :
TextInputUIComponent(
posX = posX,
Expand All @@ -56,4 +61,5 @@ open class PasswordField(
height = height,
text = text,
prompt = prompt,
font = font)
font = font,
visual = visual)
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@

package tools.aqua.bgw.components.uicomponents

import java.awt.Color
import tools.aqua.bgw.core.DEFAULT_TEXT_AREA_HEIGHT
import tools.aqua.bgw.core.DEFAULT_TEXT_AREA_WIDTH
import tools.aqua.bgw.util.Font
import tools.aqua.bgw.visual.ColorVisual
import tools.aqua.bgw.visual.Visual

/**
* A [TextArea] is a multi line input field.
Expand All @@ -38,6 +41,7 @@ import tools.aqua.bgw.util.Font
* @param prompt Prompt for this [TextArea]. This gets displayed as a prompt to the user whenever
* the label is an empty string. Default: empty string.
* @param font [Font] to be used to display [text].
* @param visual [Visual] to be used as a background. Defaults to a Light-gray [ColorVisual].
*
* @see TextField
* @see PasswordField
Expand All @@ -49,7 +53,8 @@ open class TextArea(
height: Number = DEFAULT_TEXT_AREA_HEIGHT,
text: String = "",
prompt: String = "",
font: Font = Font()
font: Font = Font(),
visual: Visual = ColorVisual(Color(240, 240, 240))
) :
TextInputUIComponent(
posX = posX,
Expand All @@ -58,4 +63,5 @@ open class TextArea(
height = height,
text = text,
prompt = prompt,
font = font)
font = font,
visual = visual)
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

package tools.aqua.bgw.components.uicomponents

import java.awt.Color
import tools.aqua.bgw.core.DEFAULT_TEXT_FIELD_HEIGHT
import tools.aqua.bgw.core.DEFAULT_TEXT_FIELD_WIDTH
import tools.aqua.bgw.util.Font
import tools.aqua.bgw.visual.ColorVisual
import tools.aqua.bgw.visual.Visual

/**
* A [TextField] is a single line input field.
Expand All @@ -36,6 +39,7 @@ import tools.aqua.bgw.util.Font
* @param prompt Prompt for this [TextField]. This gets displayed as a prompt to the user whenever
* the label is an empty string. Default: empty string.
* @param font [Font] to be used to display [text].
* @param visual [Visual] to be used as a background. Defaults to a Light-gray [ColorVisual].
*
* @see PasswordField
* @see TextArea
Expand All @@ -47,7 +51,8 @@ open class TextField(
height: Number = DEFAULT_TEXT_FIELD_HEIGHT,
text: String = "",
prompt: String = "",
font: Font = Font()
font: Font = Font(),
visual: Visual = ColorVisual(Color(240, 240, 240))
) :
TextInputUIComponent(
posX = posX,
Expand All @@ -56,4 +61,5 @@ open class TextField(
height = height,
text = text,
prompt = prompt,
font = font)
font = font,
visual = visual)
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

package tools.aqua.bgw.components.uicomponents

import java.awt.Color
import tools.aqua.bgw.observable.properties.Property
import tools.aqua.bgw.observable.properties.StringProperty
import tools.aqua.bgw.util.Font
import tools.aqua.bgw.visual.ColorVisual
import tools.aqua.bgw.visual.Visual

/**
Expand All @@ -34,6 +36,7 @@ import tools.aqua.bgw.visual.Visual
* @param text Text for this [TextInputUIComponent].
* @param prompt Prompt for this [TextInputUIComponent].
* @param font Font to be used for the [text].
* @param visual [Visual] to be used as a background. Defaults to a Light-gray [ColorVisual].
*/
sealed class TextInputUIComponent(
posX: Number,
Expand All @@ -43,14 +46,10 @@ sealed class TextInputUIComponent(
text: String,
prompt: String,
font: Font,
visual: Visual = ColorVisual(Color(240, 240, 240))
) :
UIComponent(
posX = posX,
posY = posY,
width = width,
height = height,
font = font,
visual = Visual.EMPTY) {
posX = posX, posY = posY, width = width, height = height, font = font, visual = visual) {

/**
* [Property] for the text of this [TextInputUIComponent].
Expand Down

0 comments on commit ce07f5e

Please sign in to comment.