Created
December 15, 2022 18:23
-
-
Save howmanysmall/004ebde424cf85b7c0d47a2a2c26c5f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local function NumberEntry(labelText: string, defaultValue: number, onChanged: (value: number) -> (), parent: Instance) | |
| local text = Fusion.Value(tostring(defaultValue)) | |
| local value = Fusion.Value(defaultValue) | |
| return Fusion.New("Frame") { | |
| AutomaticSize = Enum.AutomaticSize.X, | |
| BackgroundColor3 = Color3.fromRGB(54, 54, 54), | |
| Name = "Container", | |
| Parent = parent, | |
| Size = UDim2.fromOffset(200, 30), | |
| [Fusion.Cleanup] = Fusion.Observer(value):onChange(function() | |
| onChanged(value:get()) | |
| end), | |
| [Fusion.Children] = { | |
| Fusion.New("UICorner") { | |
| CornerRadius = UDim.new(0, 8), | |
| }, | |
| Fusion.New("UIListLayout") { | |
| FillDirection = Enum.FillDirection.Horizontal, | |
| HorizontalAlignment = Enum.HorizontalAlignment.Left, | |
| SortOrder = Enum.SortOrder.LayoutOrder, | |
| }, | |
| Fusion.New("TextLabel") { | |
| BackgroundTransparency = 1, | |
| FontFace = Font.fromEnum(Enum.Font.Roboto), | |
| LayoutOrder = 0, | |
| Size = UDim2.fromScale(0.6, 1), | |
| Text = labelText, | |
| TextColor3 = Color3.fromRGB(147, 147, 147), | |
| TextScaled = true, | |
| TextXAlignment = Enum.TextXAlignment.Right, | |
| }, | |
| Fusion.New("TextBox") { | |
| BackgroundTransparency = 1, | |
| FontFace = Font.fromEnum(Enum.Font.Roboto), | |
| LayoutOrder = 1, | |
| PlaceholderText = tostring(defaultValue), | |
| Size = UDim2.fromScale(0.4, 1), | |
| Text = Fusion.Computed(function() | |
| return tostring(text:get()) | |
| end), | |
| TextColor3 = Color3.fromRGB(147, 147, 147), | |
| TextScaled = true, | |
| [Fusion.OnChange("Text")] = function(currentText) | |
| local number = GetNumberFromString(currentText) | |
| value:set(number) | |
| text:set(tostring(number)) | |
| end, | |
| }, | |
| Fusion.New("UIPadding") { | |
| PaddingBottom = UDim.new(0, 5), | |
| PaddingLeft = UDim.new(0, 5), | |
| PaddingRight = UDim.new(0, 5), | |
| PaddingTop = UDim.new(0, 5), | |
| }, | |
| }, | |
| } | |
| end | |
| return NumberEntry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local NumberEntry = Plasma.widget(function(labelText, defaultValue) | |
| local text, setText = Plasma.useState(tostring(defaultValue)) | |
| local value, setValue = Plasma.useState(defaultValue) | |
| local textBox = Plasma.useInstance(function(ref) | |
| local textBox = Plasma.create("TextBox", { | |
| BackgroundTransparency = 1, | |
| FontFace = Font.fromEnum(Enum.Font.Roboto), | |
| LayoutOrder = 1, | |
| PlaceholderText = tostring(defaultValue), | |
| Size = UDim2.fromScale(0.4, 1), | |
| Text = tostring(text), | |
| TextColor3 = Color3.fromRGB(147, 147, 147), | |
| TextScaled = true, | |
| [ref] = "TextBox", | |
| }) | |
| return Plasma.create("Frame", { | |
| AutomaticSize = Enum.AutomaticSize.X, | |
| BackgroundColor3 = Color3.fromRGB(54, 54, 54), | |
| Name = "Container", | |
| Size = UDim2.fromOffset(200, 30), | |
| Plasma.create("UICorner", { | |
| CornerRadius = UDim.new(0, 8), | |
| }), | |
| Plasma.create("UIListLayout", { | |
| FillDirection = Enum.FillDirection.Horizontal, | |
| HorizontalAlignment = Enum.HorizontalAlignment.Left, | |
| SortOrder = Enum.SortOrder.LayoutOrder, | |
| }), | |
| Plasma.create("TextLabel", { | |
| BackgroundTransparency = 1, | |
| FontFace = Font.fromEnum(Enum.Font.Roboto), | |
| LayoutOrder = 0, | |
| Size = UDim2.fromScale(0.6, 1), | |
| Text = labelText, | |
| TextColor3 = Color3.fromRGB(147, 147, 147), | |
| TextScaled = true, | |
| TextXAlignment = Enum.TextXAlignment.Right, | |
| }), | |
| textBox, | |
| Plasma.create("UIPadding", { | |
| PaddingBottom = UDim.new(0, 5), | |
| PaddingLeft = UDim.new(0, 5), | |
| PaddingRight = UDim.new(0, 5), | |
| PaddingTop = UDim.new(0, 5), | |
| }), | |
| }) | |
| end) | |
| Plasma.useEffect(function() | |
| local currentTextBox = textBox.TextBox | |
| local connection = currentTextBox:GetPropertyChangedSignal("Text"):Connect(function() | |
| local number = GetNumberFromString(currentTextBox.Text) | |
| setValue(number) | |
| setText(tostring(number)) | |
| end) | |
| return function() | |
| connection:Disconnect() | |
| end | |
| end, textBox.TextBox) | |
| return value | |
| end) | |
| return NumberEntry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment