LargeScreen/Modules/scroll_label.gd
2024-12-19 19:13:12 +08:00

90 lines
1.8 KiB
GDScript

@tool
extends ScrollContainer
@export var text:String="":
set(value):
if is_scroll:
%text.text=value
else:
%text.text=get_text_not_scroll(value)
text=value
@export var margin_left:float=0:
set(value):
%tab_left.custom_minimum_size.x=value
margin_left=value
pass
@export var margin_right:float=0:
set(value):
%tab_right.custom_minimum_size.x=value
margin_right=value
pass
@export var scroll_speed:float=300
var scroll_value:float:
set(value):
var scroll_max_value:float=get_h_scroll_bar().max_value
if value>scroll_max_value:
scroll_value=0
else:
scroll_value=value
set_deferred("scroll_horizontal",value)
@export var font_size:int:
set(value):
font_size=value
%text.add_theme_font_size_override("font_size",value)
@export var is_scroll:bool=false:
set(value):
if not value:
scroll_value=0
%text.text=get_text_not_scroll(text)
else:
%text.text=text
is_scroll=value
pass
@export var view_font_num_not_scroll:int=7:
set(value):
view_font_num_not_scroll=value
if not is_scroll:
%text.text=get_text_not_scroll(text)
func _ready() -> void:
%text.add_theme_font_size_override("font_size",font_size)
%tab_left.custom_minimum_size.x=margin_left
%tab_right.custom_minimum_size.x=margin_right
if is_scroll:
%text.text=text
else:
set_deferred("scroll_horizontal",0)
%text.text=get_text_not_scroll(text)
pass
func _process(delta: float) -> void:
if is_scroll:
if text.length()>view_font_num_not_scroll:
scroll_value+=(scroll_speed*delta)
%tab_left.show()
%tab_right.show()
else:
scroll_value=0
%tab_left.hide()
%tab_right.hide()
func get_text_not_scroll(str:String)->String:
if str.length()<=view_font_num_not_scroll:
return str
else:
return str.left(view_font_num_not_scroll)+"..."