Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Range

繼承: Control < CanvasItem < Node < Object

被繼承: EditorSpinSlider, ProgressBar, ScrollBar, Slider, SpinBox, TextureProgressBar

代表特定範圍內數位的控制項的抽象基底類別。

說明

Range 是代表特定範圍內數位的控制項的抽象基底類別,能夠對步長 step 和分頁大小 page 進行配置。使用 Range 的高階節點範例請參考 ScrollBarSlider

屬性

bool

allow_greater

false

bool

allow_lesser

false

bool

exp_edit

false

float

max_value

100.0

float

min_value

0.0

float

page

0.0

float

ratio

bool

rounded

false

BitField[SizeFlags]

size_flags_vertical

0 (overrides Control)

float

step

0.01

float

value

0.0

方法

void

_value_changed(new_value: float) virtual

void

set_value_no_signal(value: float)

void

share(with: Node)

void

unshare()


訊號

changed() 🔗

min_valuemax_valuepagestep 改變時釋放訊號。


value_changed(value: float) 🔗

value 更改時發出。在 Slider 上使用時,會在拖動時連續呼叫(可能是每一影格)。如果在連接到 value_changed 的函式中執行昂貴的操作,請考慮使用去除抖動 Timer 來減少呼叫該函式的頻率。

注意:LineEdit.text_changed 等訊號不同,當直接通過程式碼設置 value 時,value_changed 仍會發出。


屬性說明

bool allow_greater = false 🔗

  • void set_allow_greater(value: bool)

  • bool is_greater_allowed()

如果為 truevalue 可能大於 max_value


bool allow_lesser = false 🔗

  • void set_allow_lesser(value: bool)

  • bool is_lesser_allowed()

如果為 truevalue 可能小於 min_value


bool exp_edit = false 🔗

  • void set_exp_ratio(value: bool)

  • bool is_ratio_exp()

If true, and min_value is greater or equal to 0, value will be represented exponentially rather than linearly.


float max_value = 100.0 🔗

最大值。如果 value 大於 max_value,則會被範圍限制。


float min_value = 0.0 🔗

最小值。如果 value 小於 min_value,則會被範圍限制。


float page = 0.0 🔗

Page size. Used mainly for ScrollBar. A ScrollBar's grabber length is the ScrollBar's size multiplied by page over the difference between min_value and max_value.


float ratio 🔗

  • void set_as_ratio(value: float)

  • float get_as_ratio()

該值在 0 和 1 之間進行對應。


bool rounded = false 🔗

  • void set_use_rounded_values(value: bool)

  • bool is_using_rounded_values()

如果為 truevalue 將始終四捨五入到最接近的整數。


float step = 0.01 🔗

If greater than 0.0, value will always be rounded to a multiple of this property's value above min_value. For example, if min_value is 0.1 and step is 0.2, then value is limited to 0.1, 0.3, 0.5, and so on. If rounded is also true, value will first be rounded to a multiple of this property's value, then rounded to the nearest integer.


float value = 0.0 🔗

Range 的目前值。更改這個屬性(即便是通過程式碼修改的)會觸發 value_changed 訊號。如果你想避免觸發訊號,請使用 set_value_no_signal()


方法說明

void _value_changed(new_value: float) virtual 🔗

Range 的值發生更改時呼叫(條件與 value_changed 相同)。


void set_value_no_signal(value: float) 🔗

Range 的目前值設定為指定的 value 而不發出 value_changed 訊號。


void share(with: Node) 🔗

將兩個 Range 綁定,之前已與兩者之中的任何一個組合的 Range 也會被綁定在一起。其中任何一個 Range 的成員變數改變時,它將與它的組中的所有其他 Range 共用新值。


void unshare() 🔗

使該 Range 停止與任何其他 Range 共用其成員變數。