Skip to content

Commit

Permalink
Fixed InputNum and PlotLines issues.
Browse files Browse the repository at this point in the history
Fixed an issue with InputNum where button padding remained even when the buttons were disabled. Fixed an issue with PlotLines where the hovered line would not update when the value changed but the mouse stayed hovered over.
  • Loading branch information
SirMallard committed Dec 21, 2024
1 parent 79ea7ae commit 46b26d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
11 changes: 6 additions & 5 deletions lib/widgets/Input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
]]
local generateInputScalar: <T>(dataType: InputDataTypes, components: number, defaultValue: any) -> Types.WidgetClass
do
local function generateButtons(thisWidget: Types.Input<number>, parent: GuiObject, rightPadding: number, textHeight: number)
rightPadding += 2 * Iris._config.ItemInnerSpacing.X + 2 * textHeight

local function generateButtons(thisWidget: Types.Input<number>, parent: GuiObject, textHeight: number)
local SubButton = widgets.abstractButton.Generate(thisWidget) :: TextButton
SubButton.Name = "SubButton"
SubButton.ZIndex = 5
Expand Down Expand Up @@ -244,7 +242,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
thisWidget.lastNumberChangedTick = Iris._cycleTick + 1
end)

return rightPadding
return 2 * Iris._config.ItemInnerSpacing.X + 2 * textHeight
end

function generateInputScalar<T>(dataType: InputDataTypes, components: number, defaultValue: any)
Expand Down Expand Up @@ -280,7 +278,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
local textHeight: number = Iris._config.TextSize + 2 * Iris._config.FramePadding.Y

if components == 1 then
rightPadding = generateButtons(thisWidget :: any, Input, rightPadding, textHeight)
rightPadding = generateButtons(thisWidget :: any, Input, textHeight)
end

-- we divide the total area evenly between each field. This includes accounting for any additional boxes and the offset.
Expand Down Expand Up @@ -369,6 +367,9 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
if components == 1 then
Input.SubButton.Visible = not thisWidget.arguments.NoButtons
Input.AddButton.Visible = not thisWidget.arguments.NoButtons
local rightPadding: number = if thisWidget.arguments.NoButtons then 0 else (2 * Iris._config.ItemInnerSpacing.X) + (2 * (Iris._config.TextSize + 2 * Iris._config.FramePadding.Y))
local InputField: TextBox = Input.InputField1
InputField.Size = UDim2.new(UDim.new(Iris._config.ContentWidth.Scale, Iris._config.ContentWidth.Offset - rightPadding), Iris._config.ContentHeight)
end

if thisWidget.arguments.Format and typeof(thisWidget.arguments.Format) ~= "table" then
Expand Down
28 changes: 18 additions & 10 deletions lib/widgets/Plot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
end
end

local function updateLine(thisWidget: Types.PlotLines)
local function updateLine(thisWidget: Types.PlotLines, silent: true?)
local PlotLines = thisWidget.Instance :: Frame
local Background = PlotLines.Background :: Frame
local Plot = Background.Plot :: Frame
Expand All @@ -171,7 +171,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
local line: Frame? = thisWidget.Lines[index]

if line then
if line ~= thisWidget.HoveredLine then
if line ~= thisWidget.HoveredLine and not silent then
clearLine(thisWidget)
end
local start: number? = thisWidget.state.values.value[index]
Expand All @@ -186,7 +186,11 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
thisWidget.HoveredLine = line
line.BackgroundColor3 = Iris._config.PlotLinesHoveredColor
line.BackgroundTransparency = Iris._config.PlotLinesHoveredTransparency
thisWidget.state.hovered:set({ start, stop })
if silent then
thisWidget.state.hovered.value = { start, stop }
else
thisWidget.state.hovered:set({ start, stop })
end
end
end

Expand Down Expand Up @@ -379,9 +383,9 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
end

-- only update the hovered block if it exists.
-- if thisWidget.HoveredLine then
-- updateLine(thisWidget)
-- end
if thisWidget.HoveredLine then
updateLine(thisWidget, true)
end
end
end,
Discard = function(thisWidget: Types.PlotLines)
Expand Down Expand Up @@ -411,7 +415,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
end
end

local function updateBlock(thisWidget: Types.PlotHistogram)
local function updateBlock(thisWidget: Types.PlotHistogram, silent: true?)
local PlotHistogram = thisWidget.Instance :: Frame
local Background = PlotHistogram.Background :: Frame
local Plot = Background.Plot :: Frame
Expand All @@ -424,7 +428,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
local block: Frame? = thisWidget.Blocks[index]

if block then
if block ~= thisWidget.HoveredBlock then
if block ~= thisWidget.HoveredBlock and not silent then
clearBlock(thisWidget)
end
local value: number? = thisWidget.state.values.value[index]
Expand All @@ -434,7 +438,11 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
thisWidget.HoveredBlock = block
block.BackgroundColor3 = Iris._config.PlotHistogramHoveredColor
block.BackgroundTransparency = Iris._config.PlotHistogramHoveredTransparency
thisWidget.state.hovered:set(value)
if silent then
thisWidget.state.hovered.value = value
else
thisWidget.state.hovered:set(value)
end
end
end

Expand Down Expand Up @@ -626,7 +634,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

-- only update the hovered block if it exists.
if thisWidget.HoveredBlock then
updateBlock(thisWidget)
updateBlock(thisWidget, true)
end
end
end,
Expand Down

0 comments on commit 46b26d4

Please sign in to comment.