From f2f4815c47b03f756baed517d304b028b8cd43d2 Mon Sep 17 00:00:00 2001 From: Sir Mallard <73789875+SirMallard@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:42:56 +0000 Subject: [PATCH] Fixed state bugs. --- lib/Internal.lua | 3 +++ lib/demoWindow.lua | 8 +++++--- lib/widgets/Input.lua | 5 +++++ lib/widgets/Plot.lua | 5 ++++- lib/widgets/RadioButton.lua | 1 + 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/Internal.lua b/lib/Internal.lua index 2f3cfd8..22c2ed4 100644 --- a/lib/Internal.lua +++ b/lib/Internal.lua @@ -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 @@ -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 = {}, } diff --git a/lib/demoWindow.lua b/lib/demoWindow.lua index f7d2075..36872c1 100644 --- a/lib/demoWindow.lua +++ b/lib/demoWindow.lua @@ -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" }) @@ -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 diff --git a/lib/widgets/Input.lua b/lib/widgets/Input.lua index 9f11c19..7efbe55 100644 --- a/lib/widgets/Input.lua +++ b/lib/widgets/Input.lua @@ -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, @@ -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 diff --git a/lib/widgets/Plot.lua b/lib/widgets/Plot.lua index 96df53e..3ccfc26 100644 --- a/lib/widgets/Plot.lua +++ b/lib/widgets/Plot.lua @@ -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 @@ -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) @@ -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 @@ -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) diff --git a/lib/widgets/RadioButton.lua b/lib/widgets/RadioButton.lua index 4e618c3..fbb7c36 100644 --- a/lib/widgets/RadioButton.lua +++ b/lib/widgets/RadioButton.lua @@ -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,