Added class documentation + renamed size_* (->msg)

I also renamed all 'size_*' variables in SuiScroller.gd to 'thickness_*' as it's a much better fitting name.
This commit is contained in:
JeremyStar™ 2024-05-08 23:17:02 +02:00
parent 3e036096b0
commit 0828d019b6
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
7 changed files with 77 additions and 18 deletions

View file

@ -55,6 +55,9 @@ offset_left = 11.0
offset_top = 8.0 offset_top = 8.0
offset_right = -1124.0 offset_right = -1124.0
offset_bottom = -576.0 offset_bottom = -576.0
thickness_mode = null
thickness_multiplier = null
thickness_value = null
[node name="Control" type="Control" parent="SuiScroller"] [node name="Control" type="Control" parent="SuiScroller"]
anchors_preset = 0 anchors_preset = 0
@ -111,6 +114,9 @@ offset_left = 338.0
offset_top = 20.0 offset_top = 20.0
offset_right = -814.0 offset_right = -814.0
offset_bottom = -577.0 offset_bottom = -577.0
thickness_mode = null
thickness_multiplier = null
thickness_value = null
[node name="Control" type="Control" parent="SuiScroller2"] [node name="Control" type="Control" parent="SuiScroller2"]
anchors_preset = 0 anchors_preset = 0

View file

@ -2,28 +2,38 @@
extends Control extends Control
class_name SuiBaseClass class_name SuiBaseClass
## Reference to the [CORE] Object.
var core: Core var core: Core
## Reference to a [CoreLoggerInstance]
var logger: CoreLoggerInstance = null var logger: CoreLoggerInstance = null
@export_category("Debugging") @export_category("Debugging")
## Determines if the element should be updated automatically [b]while running in the editor[/b].
@export var editor_process: bool = true @export var editor_process: bool = true
## Determines if the element should be updated automatically [b]during your game/application's runtime[/b].
@export var runtime_process: bool = true @export var runtime_process: bool = true
# +++ initialization and process methods +++ # +++ initialization and process methods +++
# Initializes the base class
func _ready() -> void: func _ready() -> void:
if !in_editor(): core = get_node("/root/CORE") if !in_editor(): core = get_node("/root/CORE")
# Calls 'update_element()' if allowed to execute
func _process(_delta: float): func _process(_delta: float):
if execute_process(): update_element() if execute_process(): update_element()
# +++ element updating +++ # +++ element updating +++
# This should be used by the element extending this script
# to provide their own update logic.
func update_element() -> void: pass func update_element() -> void: pass
# +++ etc +++ # +++ etc +++
# Determines if '_process()' is allowed to execute
func execute_process() -> bool: func execute_process() -> bool:
if in_editor() and !editor_process: return false if in_editor() and !editor_process: return false
elif !in_editor() and !runtime_process: return false elif !in_editor() and !runtime_process: return false
else: return true else: return true
# Determines if running inside the editor
func in_editor() -> bool: func in_editor() -> bool:
return get_node_or_null("/root/CORE") == null return get_node_or_null("/root/CORE") == null

View file

@ -3,8 +3,11 @@ extends SuiBaseClass
@export_category("Base Configuration") @export_category("Base Configuration")
@export_subgroup("RichTextLabel") @export_subgroup("RichTextLabel")
## Enables support for BBCode.
@export var bbcode_support: bool = true @export var bbcode_support: bool = true
## The text you want to display.
@export_multiline var text: String = "[center]SuiHeader[/center]" @export_multiline var text: String = "[center]SuiHeader[/center]"
## The size your font should have.
@export var font_size: int = 35 @export var font_size: int = 35
func update_element() -> void: func update_element() -> void:

View file

@ -3,12 +3,18 @@ extends SuiBaseClass
@export_category("Base Configuration") @export_category("Base Configuration")
@export_subgroup("Button") @export_subgroup("Button")
## Makes the button unable to be interacted with.
@export var disabled: bool = false @export var disabled: bool = false
## Makes the button toggleable.
@export var toggle_mode: bool = false @export var toggle_mode: bool = false
## Forwarded from the internal [Button]. Will be overwritten with the internal button's value, any manual changes to this variable will not be reflected.
@export var button_pressed: bool = false @export var button_pressed: bool = false
@export_subgroup("Icon") @export_subgroup("Icon")
## The image you want to display.
@export var image: Texture2D @export var image: Texture2D
## See [member NinePatchRect.region_rect]
@export var region_rect: Rect2 = Rect2(0, 0, 0, 0) @export var region_rect: Rect2 = Rect2(0, 0, 0, 0)
## See [member NinePatchRect.draw_center]
@export var draw_center: bool = true @export var draw_center: bool = true
@export_category("Advanced Configuration") @export_category("Advanced Configuration")
@export_subgroup("Icon Padding") @export_subgroup("Icon Padding")
@ -22,12 +28,18 @@ extends SuiBaseClass
@export var pm_right: int = 0 @export var pm_right: int = 0
@export var pm_bottom: int = 0 @export var pm_bottom: int = 0
@export_subgroup("Axis Stretch") @export_subgroup("Axis Stretch")
## See [member NinePathRect.axis_stretch_horizontal].
@export var as_horizontal: NinePatchRect.AxisStretchMode = NinePatchRect.AxisStretchMode.AXIS_STRETCH_MODE_STRETCH @export var as_horizontal: NinePatchRect.AxisStretchMode = NinePatchRect.AxisStretchMode.AXIS_STRETCH_MODE_STRETCH
## See [member NinePathRect.axis_stretch_vertical].
@export var as_vertical: NinePatchRect.AxisStretchMode = NinePatchRect.AxisStretchMode.AXIS_STRETCH_MODE_STRETCH @export var as_vertical: NinePatchRect.AxisStretchMode = NinePatchRect.AxisStretchMode.AXIS_STRETCH_MODE_STRETCH
## Emitted when the button is pressed.
signal down signal down
## Emitted when the button is released.
signal up signal up
## Emitted when the button has been pressed.
signal pressed signal pressed
## Emitted when the button has been toggled.
signal toggled signal toggled
func _ready() -> void: func _ready() -> void:

View file

@ -3,20 +3,32 @@ extends SuiBaseClass
@export_category("Base Configuration") @export_category("Base Configuration")
@export_subgroup("Visibility") @export_subgroup("Visibility")
## Controls the visibility of the horizontal scroll bar.
@export var hscroll_visibility: SuiTypes.ScrollVisibility = SuiTypes.ScrollVisibility.AUTO @export var hscroll_visibility: SuiTypes.ScrollVisibility = SuiTypes.ScrollVisibility.AUTO
## Controls the visibility of the vertical scroll bar.
@export var vscroll_visibility: SuiTypes.ScrollVisibility = SuiTypes.ScrollVisibility.AUTO @export var vscroll_visibility: SuiTypes.ScrollVisibility = SuiTypes.ScrollVisibility.AUTO
@export_category("Advanced Configuration") @export_category("Advanced Configuration")
@export_subgroup("Scroller speed") @export_subgroup("Scroller speed")
## Determines how the scrolling speed should be calculated.
@export var speed_mode: SuiTypes.ScrollMode = SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE @export var speed_mode: SuiTypes.ScrollMode = SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE
## The speed multiplier, used for [constant SuiTypes.ScrollMode.MULTIPLY_VIEWPORT] and [constant SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE].
@export var speed_multiplier: float = 1 @export var speed_multiplier: float = 1
## The speed value, used for [constant SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE] and [constant SuiTypes.ScrollMode.CUSTOM_VALUE].
@export var speed_value: float = 1 @export var speed_value: float = 1
@export_subgroup("Scroller speed (wheel)") @export_subgroup("Scroller speed (wheel)")
## Determines how much the scrolling speed should be multiplied by when scrolling with the scroll wheel.
## Using a lower value results in more mouse scrolling, higher values result in less mouse scrolling.
@export var speed_wheel_multiplier: float = 50 @export var speed_wheel_multiplier: float = 50
@export_subgroup("Scroller size") @export_subgroup("Scroll bar thickness")
@export var size_mode: SuiTypes.ScrollMode = SuiTypes.ScrollMode.MULTIPLY_VIEWPORT ## Determines how the thickness of both scroll bars should be calculated.
@export var size_multiplier: float = 0.025 @export var thickness_mode: SuiTypes.ScrollMode = SuiTypes.ScrollMode.MULTIPLY_VIEWPORT
@export var size_value: float = 0 ## The thickness multiplier, used for [constant SuiTypes.ScrollMode.MULTIPLY_VIEWPORT] and [constant SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE].
@export var thickness_multiplier: float = 0.025
## The thickness value, used for [constant SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE] and [constant SuiTypes.ScrollMode.CUSTOM_VALUE].
@export var thickness_value: float = 0
@export_category("Debugging") @export_category("Debugging")
## Will cause elements not inside the SuiScroller node to be no longer clipped [i]in editor mode[/i].
## Useful when editing the contents of a SuiScroller node, but may cause visual chaos.
@export var editor_clip_content: bool = true @export var editor_clip_content: bool = true
func _ready() -> void: func _ready() -> void:
@ -29,7 +41,7 @@ func update_element() -> void:
else: clip_contents = true else: clip_contents = true
# Update sizes and positions # Update sizes and positions
match(size_mode): match(thickness_mode):
SuiTypes.ScrollMode.MULTIPLY_VIEWPORT: SuiTypes.ScrollMode.MULTIPLY_VIEWPORT:
var window_size: Vector2i = Vector2i(ProjectSettings.get("display/window/size/viewport_width"), ProjectSettings.get("display/window/size/viewport_height")) var window_size: Vector2i = Vector2i(ProjectSettings.get("display/window/size/viewport_width"), ProjectSettings.get("display/window/size/viewport_height"))
# Find smaller value # Find smaller value
@ -37,14 +49,14 @@ func update_element() -> void:
if window_size.x < window_size.y: scale_size = window_size.x if window_size.x < window_size.y: scale_size = window_size.x
elif window_size.x > window_size.y: scale_size = window_size.y elif window_size.x > window_size.y: scale_size = window_size.y
$HScrollBar.size.y = scale_size*size_multiplier $HScrollBar.size.y = scale_size*thickness_multiplier
$VScrollBar.size.x = scale_size*size_multiplier $VScrollBar.size.x = scale_size*thickness_multiplier
SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE: SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE:
$HScrollBar.size.y = size_value*size_multiplier $HScrollBar.size.y = thickness_value*thickness_multiplier
$VScrollBar.size.x = size_value*size_multiplier $VScrollBar.size.x = thickness_value*thickness_multiplier
SuiTypes.ScrollMode.CUSTOM_VALUE: SuiTypes.ScrollMode.CUSTOM_VALUE:
$HScrollBar.size.y = size_value $HScrollBar.size.y = thickness_value
$VScrollBar.size.x = size_value $VScrollBar.size.x = thickness_value
$HScrollBar.size.x = size.x-$VScrollBar.size.x $HScrollBar.size.x = size.x-$VScrollBar.size.x
$VScrollBar.size.y = size.y-$HScrollBar.size.y $VScrollBar.size.y = size.y-$HScrollBar.size.y
$HScrollBar.position.x = 0 $HScrollBar.position.x = 0
@ -151,7 +163,7 @@ func update_element() -> void:
$HScrollBar.max_value = size.x $HScrollBar.max_value = size.x
$VScrollBar.max_value = size.y $VScrollBar.max_value = size.y
func scroll(direction: SuiTypes.ScrollDirection) -> void: func _scroll(direction: SuiTypes.ScrollDirection) -> void:
var bar: ScrollBar var bar: ScrollBar
var dsign: int = 0 var dsign: int = 0
@ -177,13 +189,13 @@ func _input(event: InputEvent):
if event.is_pressed(): if event.is_pressed():
match(event.button_index): match(event.button_index):
MouseButton.MOUSE_BUTTON_WHEEL_UP: MouseButton.MOUSE_BUTTON_WHEEL_UP:
if Input.is_key_pressed(Key.KEY_SHIFT): scroll(SuiTypes.ScrollDirection.LEFT) if Input.is_key_pressed(Key.KEY_SHIFT): _scroll(SuiTypes.ScrollDirection.LEFT)
else: scroll(SuiTypes.ScrollDirection.DOWN) else: _scroll(SuiTypes.ScrollDirection.DOWN)
MouseButton.MOUSE_BUTTON_WHEEL_DOWN: MouseButton.MOUSE_BUTTON_WHEEL_DOWN:
if Input.is_key_pressed(Key.KEY_SHIFT): scroll(SuiTypes.ScrollDirection.RIGHT) if Input.is_key_pressed(Key.KEY_SHIFT): _scroll(SuiTypes.ScrollDirection.RIGHT)
else: scroll(SuiTypes.ScrollDirection.UP) else: _scroll(SuiTypes.ScrollDirection.UP)
MouseButton.MOUSE_BUTTON_WHEEL_LEFT: scroll(SuiTypes.ScrollDirection.RIGHT) MouseButton.MOUSE_BUTTON_WHEEL_LEFT: _scroll(SuiTypes.ScrollDirection.RIGHT)
MouseButton.MOUSE_BUTTON_WHEEL_RIGHT: scroll(SuiTypes.ScrollDirection.LEFT) MouseButton.MOUSE_BUTTON_WHEEL_RIGHT: _scroll(SuiTypes.ScrollDirection.LEFT)
func _get_configuration_warnings(): func _get_configuration_warnings():
if get_child_count() != 3: if get_child_count() != 3:

View file

@ -3,12 +3,18 @@ extends SuiBaseClass
@export_category("Base Configuration") @export_category("Base Configuration")
@export_subgroup("RichTextLabel") @export_subgroup("RichTextLabel")
## Enables support for BBCode.
@export var bbcode_support: bool = true @export var bbcode_support: bool = true
## The text you want to display.
@export_multiline var text: String = "[center]SuiText[/center]" @export_multiline var text: String = "[center]SuiText[/center]"
## The size your font should have.
@export var font_size: int = 25 @export var font_size: int = 25
## Emitted when some interactive BBCode tag (e.g. url) is clicked
signal meta_clicked signal meta_clicked
## Emitted when some interactive BBCode tag (e.g. url) is hovered over
signal meta_hover_started signal meta_hover_started
## Emitted when some interactive BBCode tag (e.g. url) is no longer being hovered over
signal meta_hover_ended signal meta_hover_ended
func _ready(): func _ready():

View file

@ -3,17 +3,27 @@ extends SuiBaseClass
@export_category("Base Configuration") @export_category("Base Configuration")
@export_subgroup("Button") @export_subgroup("Button")
## Makes the button unable to be interacted with.
@export var disabled: bool = false @export var disabled: bool = false
## Makes the button toggleable.
@export var toggle_mode: bool = false @export var toggle_mode: bool = false
## Forwarded from the internal [Button]. Will be overwritten with the internal button's value, any manual changes to this variable will not be reflected.
@export var button_pressed: bool = false @export var button_pressed: bool = false
@export_subgroup("RichTextLabel") @export_subgroup("RichTextLabel")
## Enables support for BBCode.
@export var bbcode_support: bool = true @export var bbcode_support: bool = true
## The text you want to display.
@export_multiline var text: String = "[center]SuiTextButton[/center]" @export_multiline var text: String = "[center]SuiTextButton[/center]"
## The size your font should have.
@export var font_size: int = 35 @export var font_size: int = 35
## Emitted when the button is pressed.
signal down signal down
## Emitted when the button is released.
signal up signal up
## Emitted when the button has been pressed.
signal pressed signal pressed
## Emitted when the button has been toggled.
signal toggled signal toggled
func _ready() -> void: func _ready() -> void: