mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-07 10:59:49 +00:00
Add setters for ValueSlider's prefix and suffix
This way we ensure the display is reset if the prefix or suffix changes.
This commit is contained in:
parent
9adf74392a
commit
f6de836fc7
|
@ -6,8 +6,8 @@ extends TextureProgress
|
||||||
enum { NORMAL, HELD, SLIDING, TYPING }
|
enum { NORMAL, HELD, SLIDING, TYPING }
|
||||||
|
|
||||||
export var editable := true
|
export var editable := true
|
||||||
export var prefix: String
|
export var prefix: String setget _prefix_changed
|
||||||
export var suffix: String
|
export var suffix: String setget _suffix_changed
|
||||||
# Size of additional snapping (applied in addition to Range's step).
|
# Size of additional snapping (applied in addition to Range's step).
|
||||||
# This should always be larger than step.
|
# This should always be larger than step.
|
||||||
export var snap_step := 1.0
|
export var snap_step := 1.0
|
||||||
|
@ -25,12 +25,12 @@ onready var line_edit: LineEdit = $LineEdit
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
reset_display()
|
_reset_display()
|
||||||
|
|
||||||
|
|
||||||
func _notification(what: int) -> void:
|
func _notification(what: int) -> void:
|
||||||
if what == NOTIFICATION_THEME_CHANGED or what == NOTIFICATION_TRANSLATION_CHANGED:
|
if what == NOTIFICATION_THEME_CHANGED or what == NOTIFICATION_TRANSLATION_CHANGED:
|
||||||
reset_display()
|
_reset_display()
|
||||||
|
|
||||||
|
|
||||||
func _gui_input(event: InputEvent) -> void:
|
func _gui_input(event: InputEvent) -> void:
|
||||||
|
@ -98,6 +98,16 @@ func _gui_input(event: InputEvent) -> void:
|
||||||
value = round(value / snap_step) * snap_step
|
value = round(value / snap_step) * snap_step
|
||||||
|
|
||||||
|
|
||||||
|
func _prefix_changed(v: String) -> void:
|
||||||
|
prefix = v
|
||||||
|
_reset_display()
|
||||||
|
|
||||||
|
|
||||||
|
func _suffix_changed(v: String) -> void:
|
||||||
|
suffix = v
|
||||||
|
_reset_display()
|
||||||
|
|
||||||
|
|
||||||
func _on_LineEdit_gui_input(event: InputEvent) -> void:
|
func _on_LineEdit_gui_input(event: InputEvent) -> void:
|
||||||
if state == TYPING:
|
if state == TYPING:
|
||||||
if event is InputEventKey and event.scancode == KEY_ESCAPE:
|
if event is InputEventKey and event.scancode == KEY_ESCAPE:
|
||||||
|
@ -106,7 +116,7 @@ func _on_LineEdit_gui_input(event: InputEvent) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _on_value_changed(_value: float) -> void:
|
func _on_value_changed(_value: float) -> void:
|
||||||
reset_display()
|
_reset_display()
|
||||||
|
|
||||||
|
|
||||||
func _on_LineEdit_text_entered(_new_text) -> void:
|
func _on_LineEdit_text_entered(_new_text) -> void:
|
||||||
|
@ -124,17 +134,17 @@ func _confirm_text(confirm := true) -> void:
|
||||||
var expression := Expression.new()
|
var expression := Expression.new()
|
||||||
var error := expression.parse(line_edit.text, [])
|
var error := expression.parse(line_edit.text, [])
|
||||||
if error != OK:
|
if error != OK:
|
||||||
reset_display()
|
_reset_display()
|
||||||
return
|
return
|
||||||
var result = expression.execute([], null, true)
|
var result = expression.execute([], null, true)
|
||||||
if expression.has_execute_failed() or not (result is int or result is float):
|
if expression.has_execute_failed() or not (result is int or result is float):
|
||||||
reset_display()
|
_reset_display()
|
||||||
return
|
return
|
||||||
value = result
|
value = result
|
||||||
reset_display()
|
_reset_display()
|
||||||
|
|
||||||
|
|
||||||
func reset_display() -> void:
|
func _reset_display() -> void:
|
||||||
if not line_edit:
|
if not line_edit:
|
||||||
return
|
return
|
||||||
line_edit.selecting_enabled = false # Remove the selection
|
line_edit.selecting_enabled = false # Remove the selection
|
||||||
|
|
Loading…
Reference in a new issue