Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct widget' Instance discard behaviour #89

Merged
merged 4 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ return function(Iris: Types.Iris): Types.Internal
self.value = newValue
self.lastChangeTick = Iris.Internal._cycleTick
for _, thisWidget: Types.Widget in self.ConnectedWidgets do
Internal._widgets[thisWidget.type].UpdateState(thisWidget)
if thisWidget.lastCycleTick ~= -1 then
Internal._widgets[thisWidget.type].UpdateState(thisWidget)
end
end

for _, callback in self.ConnectedFunctions do
Expand Down
7 changes: 7 additions & 0 deletions lib/widgets/Combo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,14 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
PreviewLabel.Text = if typeof(stateIndex) == "EnumItem" then stateIndex.Name else tostring(stateIndex)
end,
Discard = function(thisWidget: Types.Combo)
-- If we are discarding the current combo active, we need to hide it
if OpenedCombo and OpenedCombo == thisWidget then
OpenedCombo = nil
AnyOpenedCombo = false
end

thisWidget.Instance:Destroy()
thisWidget.ChildContainer:Destroy()
widgets.discardState(thisWidget)
end,
} :: Types.WidgetClass)
Expand Down
14 changes: 14 additions & 0 deletions lib/widgets/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,21 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
end
end,
Discard = function(thisWidget: Types.Menu)
-- properly handle removing a menu if open and deleted
if AnyMenuOpen then
local parentMenu = thisWidget.parentWidget :: Types.Menu
local parentIndex: number? = table.find(MenuStack, parentMenu)
if parentIndex then
EmptyMenuStack(parentIndex)
if #MenuStack ~= 0 then
ActiveMenu = parentMenu
AnyMenuOpen = true
end
end
end

thisWidget.Instance:Destroy()
thisWidget.ChildContainer:Destroy()
widgets.discardState(thisWidget)
end,
} :: Types.WidgetClass)
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/Plot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
end,
Discard = function(thisWidget: Types.PlotLines)
thisWidget.Instance:Destroy()
thisWidget.Tooltip:Destroy()
widgets.discardState(thisWidget)
end,
} :: Types.WidgetClass)
Expand Down Expand Up @@ -640,6 +641,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
end,
Discard = function(thisWidget: Types.PlotHistogram)
thisWidget.Instance:Destroy()
thisWidget.Tooltip:Destroy()
widgets.discardState(thisWidget)
end,
} :: Types.WidgetClass)
Expand Down
6 changes: 6 additions & 0 deletions lib/widgets/Tab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,13 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
end
end,
Discard = function(thisWidget: Types.Tab)
if thisWidget.state.isOpened.value == true then
closeTab(thisWidget.parentWidget, thisWidget.Index)
end

thisWidget.Instance:Destroy()
thisWidget.ChildContainer:Destroy()
widgets.discardState(thisWidget)
end
} :: Types.WidgetClass)
end
Loading