mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2026-01-07 19:52:39 +01:00
Disable the apply button if the input is invalid
This commit is contained in:
parent
a65c683529
commit
bbfd85395a
@ -58,10 +58,13 @@ TextInputForeground = #333333
|
||||
TextInputBorderError = #aa8888
|
||||
TextInputBorderErrorFocused = #cc6666
|
||||
|
||||
ButtonBackground = #aaaaaa
|
||||
ButtonBorder = #888888
|
||||
ButtonForeground = #333333
|
||||
ButtonConfirm = #336633
|
||||
ButtonBackground = #aaaaaa
|
||||
ButtonBorder = #888888
|
||||
ButtonForeground = #333333
|
||||
ButtonBackgroundDisabled = #333333
|
||||
ButtonBorderDisabled = #666666
|
||||
ButtonForegroundDisabled = #888888
|
||||
ButtonConfirm = #336633
|
||||
|
||||
BottomDrawerBorder = #888888
|
||||
|
||||
|
||||
@ -11,26 +11,40 @@ import ocelot.desktop.util.DrawUtils
|
||||
|
||||
class Button extends Widget with ClickHandler with ClickSoundSource {
|
||||
def text: String = ""
|
||||
|
||||
def onClick(): Unit = {}
|
||||
|
||||
def enabled: Boolean = true
|
||||
|
||||
override def receiveMouseEvents: Boolean = true
|
||||
|
||||
eventHandlers += {
|
||||
case ClickEvent(MouseEvent.Button.Left, _) =>
|
||||
case ClickEvent(MouseEvent.Button.Left, _) if enabled =>
|
||||
onClick()
|
||||
|
||||
clickSoundSource.play()
|
||||
}
|
||||
|
||||
override def minimumSize: Size2D = Size2D(24 + text.length * 8, 24)
|
||||
|
||||
override def maximumSize: Size2D = minimumSize
|
||||
|
||||
override def draw(g: Graphics): Unit = {
|
||||
g.rect(bounds, ColorScheme("ButtonBackground"))
|
||||
DrawUtils.ring(g, position.x, position.y, width, height, 2, ColorScheme("ButtonBorder"))
|
||||
val (background, border, foreground) = if (enabled) (
|
||||
ColorScheme("ButtonBackground"),
|
||||
ColorScheme("ButtonBorder"),
|
||||
ColorScheme("ButtonForeground")
|
||||
) else (
|
||||
ColorScheme("ButtonBackgroundDisabled"),
|
||||
ColorScheme("ButtonBorderDisabled"),
|
||||
ColorScheme("ButtonForegroundDisabled")
|
||||
)
|
||||
|
||||
g.rect(bounds, background)
|
||||
DrawUtils.ring(g, position.x, position.y, width, height, 2, border)
|
||||
|
||||
g.background = Color.Transparent
|
||||
g.foreground = ColorScheme("ButtonForeground")
|
||||
g.foreground = foreground
|
||||
val textWidth = text.iterator.map(g.font.charWidth(_)).sum
|
||||
g.text(position.x + ((width - textWidth) / 2).round, position.y + 4, text)
|
||||
}
|
||||
|
||||
@ -91,10 +91,10 @@ class ChangeSimulationSpeedDialog() extends ModalDialog {
|
||||
override def onClick(): Unit = close()
|
||||
}, Padding2D(right = 8))
|
||||
|
||||
// TODO: disable the button if tickInterval.isEmpty
|
||||
children :+= new Button {
|
||||
override def text: String = "Apply"
|
||||
override def onClick(): Unit = confirm()
|
||||
override def enabled: Boolean = tickInterval.nonEmpty
|
||||
}
|
||||
}
|
||||
}, Padding2D.equal(16))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user