Skip to content

Commit 837ebc5

Browse files
committed
fix(Slider): add option to show/hide decimal values in sliders
1 parent 0ec8073 commit 837ebc5

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

core/ui/common/settings/display_settings_menu.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ value = 1.0
6363
max_value = 3.0
6464
min_value = 0.2
6565
step = 0.02
66+
show_decimal = true
6667

6768
[node name="OverlayLabel" parent="VBoxContainer" instance=ExtResource("3_nmfgp")]
6869
layout_mode = 2

core/ui/components/battery_container.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func _on_update_device(item: UPowerDevice):
3737
var capacity := item.percentage
3838
var state := item.state
3939
battery_icon.texture = get_capacity_texture(capacity, state)
40-
battery_label.text = str(capacity)+"%"
40+
battery_label.text = str(int(capacity))+"%"
4141
if capacity > 5:
4242
battery_icon.modulate = Color(1, 1, 1)
4343
else:

core/ui/components/slider.gd

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ signal value_changed(value: float)
2020
set(v):
2121
value = v
2222
if label_value:
23-
label_value.text = str(v)
23+
label_value.text = _get_value_str()
2424
if slider:
2525
slider.value = v
2626
value_changed.emit(v)
@@ -54,6 +54,11 @@ signal value_changed(value: float)
5454
slider.editable = v
5555
notify_property_list_changed()
5656

57+
@export var show_decimal: bool = false:
58+
set(v):
59+
show_decimal = v
60+
notify_property_list_changed()
61+
5762
@export var tick_count := 0
5863
@export var separator_visible: bool = false
5964

@@ -68,7 +73,7 @@ signal value_changed(value: float)
6873
func _ready() -> void:
6974
focus_entered.connect(_grab_focus)
7075
label.text = text
71-
label_value.text = str(slider.value)
76+
label_value.text = _get_value_str()
7277
hsep.visible = separator_visible
7378
slider.value_changed.connect(_on_value_changed)
7479
slider.value = value
@@ -92,7 +97,7 @@ func _ready() -> void:
9297
drag_started.emit()
9398
slider.drag_ended.connect(on_drag_started)
9499
var on_changed := func():
95-
label_value.text = str(slider.value)
100+
label_value.text = _get_value_str()
96101
changed.emit()
97102
slider.changed.connect(on_changed)
98103

@@ -118,6 +123,14 @@ func _grab_focus() -> void:
118123
slider.grab_focus()
119124

120125

126+
# Get the current value as a string
127+
func _get_value_str() -> String:
128+
if show_decimal:
129+
return str(slider.value)
130+
else:
131+
return str(int(slider.value))
132+
133+
121134
# Override certain properties and pass them to child objects
122135
func _set(property: StringName, value: Variant) -> bool:
123136
if not slider:

0 commit comments

Comments
 (0)