Skip to content

Commit

Permalink
Fixed state bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirMallard committed Dec 10, 2024
1 parent 1454908 commit f2f4815
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/Internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ return function(Iris: Types.Iris): Types.Internal
-- generate a new state.
states[index] = Internal._widgetState(stateWidget, index, state)
end
states[index].lastChangeTick = Internal._cycleTick
end

stateWidget.state = states
Expand Down Expand Up @@ -649,11 +650,13 @@ return function(Iris: Types.Iris): Types.Internal
local ID: Types.ID = thisWidget.ID .. stateName
if Internal._states[ID] then
Internal._states[ID].ConnectedWidgets[thisWidget.ID] = thisWidget
Internal._states[ID].lastChangeTick = Internal._cycleTick
return Internal._states[ID]
else
Internal._states[ID] = {
ID = ID,
value = initialValue,
lastChangeTick = Internal._cycleTick,
ConnectedWidgets = { [thisWidget.ID] = thisWidget },
ConnectedFunctions = {},
}
Expand Down
8 changes: 5 additions & 3 deletions lib/demoWindow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ return function(Iris: Types.Iris)
local SampleState = Iris.State(37)
local BaseLineState = Iris.State(0)
local ValueState = Iris.State({})
local TimeState = Iris.State(-1)
local TimeState = Iris.State(0)

local Animated = Iris.Checkbox({ "Animate" })
local plotFunc = Iris.ComboArray({ "Plotting Function" }, { index = FunctionState }, { "Sin", "Cos", "Tan", "Saw" })
Expand All @@ -599,8 +599,10 @@ return function(Iris: Types.Iris)
end

if Animated.state.isChecked.value or plotFunc.closed() or samples.numberChanged() or #ValueState.value == 0 then
TimeState:set(TimeState.value + Iris.Internal._deltaTime)
local offset: number = math.floor(TimeState.value * 30)
if Animated.state.isChecked.value then
TimeState:set(TimeState.value + Iris.Internal._deltaTime)
end
local offset: number = math.floor(TimeState.value * 30) - 1
local func: string = FunctionState.value
table.clear(ValueState.value)
for i = 1, SampleState.value do
Expand Down
5 changes: 5 additions & 0 deletions lib/widgets/Input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,10 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
-- since the state values have changed display, we call an update. The check is because state is not
-- initialised on creation, so it would error otherwise.
if thisWidget.state then
thisWidget.state.color.lastChangeTick = Iris._cycleTick
if dataType == "Color4" then
thisWidget.state.transparency.lastChangeTick = Iris._cycleTick
end
Iris._widgets[thisWidget.type].UpdateState(thisWidget)
end
end,
Expand Down Expand Up @@ -1144,6 +1148,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
Iris._postCycleCallbacks[callbackIndex] = function()
if Iris._cycleTick >= desiredCycleTick then
if thisWidget.lastCycleTick ~= -1 then
thisWidget.state.number.lastChangeTick = Iris._cycleTick
Iris._widgets[`Slider{dataType}`].UpdateState(thisWidget)
end
Iris._postCycleCallbacks[callbackIndex] = nil
Expand Down
5 changes: 4 additions & 1 deletion lib/widgets/Plot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
thisWidget.HoveredLine.BackgroundColor3 = Iris._config.PlotLinesColor
thisWidget.HoveredLine.BackgroundTransparency = Iris._config.PlotLinesTransparency
thisWidget.HoveredLine = false
thisWidget.state.hovered:set(nil)
end
end

Expand Down Expand Up @@ -234,6 +235,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
Plot.ClipsDescendants = true

Plot:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
thisWidget.state.values.lastChangeTick = Iris._cycleTick
Iris._widgets.PlotLines.UpdateState(thisWidget)
end)

Expand Down Expand Up @@ -405,6 +407,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
thisWidget.HoveredBlock.BackgroundColor3 = Iris._config.PlotHistogramColor
thisWidget.HoveredBlock.BackgroundTransparency = Iris._config.PlotHistogramTransparency
thisWidget.HoveredBlock = false
thisWidget.state.hovered:set(nil)
end
end

Expand Down Expand Up @@ -551,7 +554,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
thisWidget.state.values = Iris._widgetState(thisWidget, "values", { 1 })
end
if thisWidget.state.hovered == nil then
thisWidget.state.hovered = Iris._widgetState(thisWidget, "hovered", { 1 })
thisWidget.state.hovered = Iris._widgetState(thisWidget, "hovered", nil)
end
end,
Update = function(thisWidget: Types.PlotHistogram)
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/RadioButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

TextLabel.Text = thisWidget.arguments.Text or "Radio Button"
if thisWidget.state then
thisWidget.state.index.lastChangeTick = Iris._cycleTick
Iris._widgets[thisWidget.type].UpdateState(thisWidget)
end
end,
Expand Down

0 comments on commit f2f4815

Please sign in to comment.