-
Notifications
You must be signed in to change notification settings - Fork 9
/
RadioGroup.lua
43 lines (35 loc) · 1.13 KB
/
RadioGroup.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-- Simple PseudoInstance wrapper to manage Radio buttons
-- @documentation https://rostrap.github.io/Libraries/RoStrapUI/RadioGroup/
-- @author Validark
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Resources = require(ReplicatedStorage:WaitForChild("Resources"))
local PseudoInstance = Resources:LoadLibrary("PseudoInstance")
return PseudoInstance:Register("RadioGroup", {
Internals = {"Radios", "Selection"};
Events = {"SelectionChanged"};
Methods = {
Add = function(self, Item, Option)
local Radios = self.Radios
Radios[#Radios + 1] = Item
self.Janitor:Add(Item.OnChecked:Connect(function(Checked)
if Checked then
for i = 1, #Radios do
local Radio = Radios[i]
if Radio ~= Item then
Radio:SetChecked(false)
end
end
self.Selection = Option
self.SelectionChanged:Fire(Option)
end
end), "Disconnect")
end;
GetSelection = function(self) -- `Selection` is not directly accessible because you can neither clone a RadioGroup nor set a Selection
return self.Selection or nil
end;
};
Init = function(self)
self.Radios = {}
self:superinit()
end;
})