Skip to content

Commit

Permalink
Merge pull request #10 from ImAvafe/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ImAvafe authored Sep 17, 2024
2 parents b8d234a + 46a2def commit 227566f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions samples/SettingsMenu/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local Themer = OnyxUI.Themer
local Util = OnyxUI.Util
local Children = Fusion.Children
local InnerScope = Fusion.innerScope
local Components = OnyxUI.Components

local SettingToggle = require(script.SettingToggle)

Expand All @@ -14,7 +13,7 @@ export type Props = {
}

return function(Scope: Fusion.Scope<any>, Props: Props)
local Scope = InnerScope(Scope, Fusion, Util, Components, {
local Scope = InnerScope(Scope, Fusion, OnyxUI.Util, OnyxUI.Components, {
SettingToggle = SettingToggle,
})
local Theme = Themer.Theme:now()
Expand Down Expand Up @@ -69,6 +68,7 @@ return function(Scope: Fusion.Scope<any>, Props: Props)
Scope:TextInput {
AutomaticSize = Enum.AutomaticSize.Y,
PlaceholderText = "Nickname",
CharacterLimit = 20,
},
},
},
Expand Down
45 changes: 24 additions & 21 deletions src/Components/TextInput.luau
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ local Themer = require(OnyxUI.Themer)

local Peek = Fusion.peek
local OnEvent = Fusion.OnEvent
local Out = Fusion.Out
local InnerScope = Fusion.innerScope

local Base = require(script.Parent.Base)
Expand Down Expand Up @@ -124,16 +123,16 @@ return function(Scope: Fusion.Scope<any>, Props: Props)
end)
)

local OutText = Scope:Value("")
local ProcessedText = Scope:Computed(function(Use)
local OutTextValue = Use(OutText) or ""
local CharacterLimitValue = Use(CharacterLimit)
local LimitedText = OutTextValue:sub(1, utf8.offset(OutTextValue, CharacterLimitValue))
local FullyProcessedText = Use(TextProcessor)(LimitedText)
local InvalidInputActive = Scope:Value(false)

local function ProcessText(NewText: string)
local CharacterLimitValue = Peek(CharacterLimit)
local TextProcessorValue = Peek(TextProcessor)
local LimitedText = NewText:sub(1, utf8.offset(NewText, CharacterLimitValue))
local FullyProcessedText = TextProcessorValue(LimitedText)

return FullyProcessedText
end)
local InvalidInputActive = Scope:Value(false)
end

local Object = Scope:Hydrate(Scope:Base(Util.CombineProps(Props, {
ClassName = "TextBox",
Expand Down Expand Up @@ -246,22 +245,26 @@ return function(Scope: Fusion.Scope<any>, Props: Props)
SoundService:PlayLocalSound(Peek(Theme.Sound.Hover))
end
end,
[Out "Text"] = OutText,
}

Scope:Observer(OutText):onChange(function()
local ProcessedTextValue = Peek(ProcessedText)
local OutTextValue = Peek(OutText)
table.insert(
Scope,
Object:GetPropertyChangedSignal("Text"):Connect(function()
local NewText = Object.Text
local ProcessedText = ProcessText(NewText)

Text:set(ProcessedTextValue)
Object.Text = ProcessedTextValue
if Object.Text ~= ProcessedText then
Text:set(ProcessedText)
Object.Text = ProcessedText
end

if utf8.len(OutTextValue) ~= utf8.len(ProcessedTextValue) then
InvalidInputActive:set(true)
task.wait(0.075)
InvalidInputActive:set(false)
end
end)
if utf8.len(NewText) ~= utf8.len(ProcessedText) then
InvalidInputActive:set(true)
task.wait(0.075)
InvalidInputActive:set(false)
end
end)
)

return Object
end
2 changes: 1 addition & 1 deletion src/Themer/NewTheme.luau
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ local function NewTheme(Scope: Fusion.Scope<any>, ThemeSpec: ThemeSpec)
Immediate = Scope:Value(1000),
},
SpringDampening = {
Base = Scope:Value(40),
Base = Scope:Value(1),
["0.1"] = Scope:Value(nil),
["0.175"] = Scope:Value(nil),
["0.25"] = Scope:Value(nil),
Expand Down

0 comments on commit 227566f

Please sign in to comment.