You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/elements/ScrollFrame.lua
+78-1Lines changed: 78 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,91 @@ local tHex = require("libraries/colorHex")
4
4
---@configDescription A scrollable container that automatically displays scrollbars when content overflows.
5
5
6
6
--- A container that provides automatic scrolling capabilities with visual scrollbars. Displays vertical and/or horizontal scrollbars when child content exceeds the container's dimensions.
7
+
--- @run [[
8
+
--- local basalt = require("basalt")
9
+
---
10
+
--- local main = basalt.getMainFrame()
11
+
---
12
+
--- -- Create a ScrollFrame with content larger than the frame
13
+
--- local scrollFrame = main:addScrollFrame({
14
+
--- x = 2,
15
+
--- y = 2,
16
+
--- width = 30,
17
+
--- height = 12,
18
+
--- background = colors.lightGray
19
+
--- })
20
+
---
21
+
--- -- Add a title
22
+
--- scrollFrame:addLabel({
23
+
--- x = 2,
24
+
--- y = 1,
25
+
--- text = "ScrollFrame Example",
26
+
--- foreground = colors.yellow
27
+
--- })
28
+
---
29
+
--- -- Add multiple labels that exceed the frame height
30
+
--- for i = 1, 20 do
31
+
--- scrollFrame:addLabel({
32
+
--- x = 2,
33
+
--- y = i + 2,
34
+
--- text = "Line " .. i .. " - Scroll to see more",
35
+
--- foreground = i % 2 == 0 and colors.white or colors.lightGray
36
+
--- })
37
+
--- end
38
+
---
39
+
--- -- Add some interactive buttons at different positions
40
+
--- scrollFrame:addButton({
41
+
--- x = 2,
42
+
--- y = 24,
43
+
--- width = 15,
44
+
--- height = 3,
45
+
--- text = "Button 1",
46
+
--- background = colors.blue
47
+
--- })
48
+
--- :onClick(function()
49
+
--- scrollFrame:addLabel({
50
+
--- x = 18,
51
+
--- y = 24,
52
+
--- text = "Clicked!",
53
+
--- foreground = colors.lime
54
+
--- })
55
+
--- end)
56
+
---
57
+
--- scrollFrame:addButton({
58
+
--- x = 2,
59
+
--- y = 28,
60
+
--- width = 15,
61
+
--- height = 3,
62
+
--- text = "Button 2",
63
+
--- background = colors.green
64
+
--- })
65
+
--- :onClick(function()
66
+
--- scrollFrame:addLabel({
67
+
--- x = 18,
68
+
--- y = 28,
69
+
--- text = "Nice!",
70
+
--- foreground = colors.orange
71
+
--- })
72
+
--- end)
73
+
---
74
+
--- -- Info label outside the scroll frame
75
+
--- main:addLabel({
76
+
--- x = 2,
77
+
--- y = 15,
78
+
--- text = "Use mouse wheel to scroll!",
79
+
--- foreground = colors.gray
80
+
--- })
81
+
---
82
+
--- basalt.run()
83
+
--- ]]
7
84
---@classScrollFrame:Container
8
85
localScrollFrame=setmetatable({}, Container)
9
86
ScrollFrame.__index=ScrollFrame
10
87
11
88
---@property showScrollBar boolean true Whether to show scrollbars
0 commit comments