Skip to content

Commit

Permalink
Fixes and simplifications.
Browse files Browse the repository at this point in the history
Changed applyInteractionHighlights method to be generic for text and images. Removed unnecessary and unused methods. Extra asserts in Table methods. Fixed SameLine name issue.
  • Loading branch information
SirMallard committed Sep 2, 2024
1 parent 0cbf632 commit 7be1b09
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 301 deletions.
54 changes: 13 additions & 41 deletions lib/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ return function(Iris: Types.Iris)
Iris.Indent = wrapper("Indent")

--[=[
@prop Sameline Iris.Sameline
@prop SameLine Iris.SameLine
@within Format
@tag Widget
@tag HasChildren
Expand Down Expand Up @@ -1389,38 +1389,6 @@ return function(Iris: Types.Iris)
]=]
Iris.SliderRect = wrapper("SliderRect")

--[=[
@private
@prop SliderNum Iris.SliderNum
@within Slider
@tag Widget
@tag HasState
A field which allows the user to slide a grip to enter a number within a range.
You can ctrl + click to directly input a number, like InputNum.
```lua
hasChildren = false
hasState = true
Arguments = {
Text: string? = "SliderNum",
Increment: number? = 1,
Min: number? = 0,
Max: number? = 100,
Format: string? | { string }? = [DYNAMIC] -- Iris will dynamically generate an approriate format.
}
Events = {
numberChanged: () -> boolean,
hovered: () -> boolean
}
States = {
number: State<number>?,
editingText: State<boolean>?
}
```
]=]
-- Iris.SliderEnum = wrapper("SliderEnum")

--[[
----------------------------------
[SECTION] Combo Widget API
Expand Down Expand Up @@ -1672,7 +1640,9 @@ return function(Iris: Types.Iris)
then the next cell will be the first column of the next row.
]=]
Iris.NextColumn = function()
Iris.Internal._GetParentWidget().RowColumnIndex += 1
local parentWidget: Types.Widget = Iris.Internal._GetParentWidget()
assert(parentWidget.type == "Table", "Iris.NextColumn can only be called within a table.")
parentWidget.RowColumnIndex += 1
end

--[=[
Expand All @@ -1683,9 +1653,10 @@ return function(Iris: Types.Iris)
In a table, directly sets the index of the column.
]=]
Iris.SetColumnIndex = function(columnIndex: number)
local ParentWidget: Types.Widget = Iris.Internal._GetParentWidget()
assert(columnIndex >= ParentWidget.InitialNumColumns, "Iris.SetColumnIndex Argument must be in column range")
ParentWidget.RowColumnIndex = math.floor(ParentWidget.RowColumnIndex / ParentWidget.InitialNumColumns) + (columnIndex - 1)
local parentWidget: Types.Widget = Iris.Internal._GetParentWidget()
assert(parentWidget.type == "Table", "Iris.SetColumnIndex can only be called within a table.")
assert(columnIndex >= parentWidget.InitialNumColumns, "Iris.SetColumnIndex Argument must be in column range")
parentWidget.RowColumnIndex = math.floor(parentWidget.RowColumnIndex / parentWidget.InitialNumColumns) + (columnIndex - 1)
end

--[=[
Expand All @@ -1697,9 +1668,10 @@ return function(Iris: Types.Iris)
]=]
Iris.NextRow = function()
-- sets column Index back to 0, increments Row
local ParentWidget: Types.Widget = Iris.Internal._GetParentWidget()
local InitialNumColumns: number = ParentWidget.InitialNumColumns
local nextRow: number = math.floor((ParentWidget.RowColumnIndex + 1) / InitialNumColumns) * InitialNumColumns
ParentWidget.RowColumnIndex = nextRow
local parentWidget: Types.Widget = Iris.Internal._GetParentWidget()
assert(parentWidget.type == "Table", "Iris.NextColumn can only be called within a table.")
local InitialNumColumns: number = parentWidget.InitialNumColumns
local nextRow: number = math.floor((parentWidget.RowColumnIndex + 1) / InitialNumColumns) * InitialNumColumns
parentWidget.RowColumnIndex = nextRow
end
end
8 changes: 2 additions & 6 deletions lib/Types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,10 @@ export type WidgetUtility = {
UIStroke: (Parent: GuiObject, Thickness: number, Color: Color3, Transparency: number) -> UIStroke,
UICorner: (Parent: GuiObject, PxRounding: number?) -> UICorner,
UISizeConstraint: (Parent: GuiObject, MinSize: Vector2?, MaxSize: Vector2?) -> UISizeConstraint,
UIReference: (Parent: GuiObject, Child: GuiObject, Name: string) -> ObjectValue,

calculateTextSize: (text: string, width: number?) -> Vector2,
applyTextStyle: (thisInstance: TextLabel | TextButton | TextBox) -> (),
applyInteractionHighlights: (thisWidget: Widget, Button: GuiButton, Highlightee: GuiObject, Colors: { [string]: any }) -> (),
applyInteractionHighlightsWithMultiHighlightee: (thisWidget: Widget, Button: GuiButton, Highlightees: { { GuiObject | { [string]: Color3 | number } } }) -> (),
applyImageInteractionHighlights: (thisWidget: Widget, Button: GuiButton, Highlightee: GuiObject, Colors: { [string]: any }) -> (),
applyTextInteractionHighlights: (thisWidget: Widget, Button: GuiButton, Highlightee: TextLabel | TextButton | TextBox, Colors: { [string]: any }) -> (),
applyInteractionHighlights: (thisWidget: Widget, Property: string, Button: GuiButton, Highlightee: GuiObject, Colors: { [string]: any }) -> (),
applyInteractionHighlightsWithMultiHighlightee: (thisWidget: Widget, Property: string, Button: GuiButton, Highlightees: { { GuiObject | { [string]: Color3 | number } } }) -> (),
applyFrameStyle: (thisInstance: GuiObject, noPadding: boolean?, noCorner: boolean?) -> (),

applyButtonClick: (thisWidget: Widget, thisInstance: GuiButton, callback: () -> ()) -> (),
Expand Down
14 changes: 7 additions & 7 deletions lib/widgets/Button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

widgets.applyFrameStyle(Button)

widgets.applyInteractionHighlights(thisWidget, Button, Button, {
ButtonColor = Iris._config.ButtonColor,
ButtonTransparency = Iris._config.ButtonTransparency,
ButtonHoveredColor = Iris._config.ButtonHoveredColor,
ButtonHoveredTransparency = Iris._config.ButtonHoveredTransparency,
ButtonActiveColor = Iris._config.ButtonActiveColor,
ButtonActiveTransparency = Iris._config.ButtonActiveTransparency,
widgets.applyInteractionHighlights(thisWidget, "Background", Button, Button, {
Color = Iris._config.ButtonColor,
Transparency = Iris._config.ButtonTransparency,
HoveredColor = Iris._config.ButtonHoveredColor,
HoveredTransparency = Iris._config.ButtonHoveredTransparency,
ActiveColor = Iris._config.ButtonActiveColor,
ActiveTransparency = Iris._config.ButtonActiveTransparency,
})

Button.ZIndex = thisWidget.ZIndex
Expand Down
14 changes: 7 additions & 7 deletions lib/widgets/Checkbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
widgets.applyFrameStyle(Box, true)
widgets.UIPadding(Box, (checkboxSize // 10) * Vector2.one)

widgets.applyInteractionHighlights(thisWidget, Checkbox, Box, {
ButtonColor = Iris._config.FrameBgColor,
ButtonTransparency = Iris._config.FrameBgTransparency,
ButtonHoveredColor = Iris._config.FrameBgHoveredColor,
ButtonHoveredTransparency = Iris._config.FrameBgHoveredTransparency,
ButtonActiveColor = Iris._config.FrameBgActiveColor,
ButtonActiveTransparency = Iris._config.FrameBgActiveTransparency,
widgets.applyInteractionHighlights(thisWidget, "Background", Checkbox, Box, {
Color = Iris._config.FrameBgColor,
Transparency = Iris._config.FrameBgTransparency,
HoveredColor = Iris._config.FrameBgHoveredColor,
HoveredTransparency = Iris._config.FrameBgHoveredTransparency,
ActiveColor = Iris._config.FrameBgActiveColor,
ActiveTransparency = Iris._config.FrameBgActiveTransparency,
})

Box.Parent = Checkbox
Expand Down
44 changes: 22 additions & 22 deletions lib/widgets/Combo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
widgets.UISizeConstraint(SelectableButton, Vector2.xAxis)

thisWidget.ButtonColors = {
ButtonColor = Iris._config.HeaderColor,
ButtonTransparency = 1,
ButtonHoveredColor = Iris._config.HeaderHoveredColor,
ButtonHoveredTransparency = Iris._config.HeaderHoveredTransparency,
ButtonActiveColor = Iris._config.HeaderActiveColor,
ButtonActiveTransparency = Iris._config.HeaderActiveTransparency,
Color = Iris._config.HeaderColor,
Transparency = 1,
HoveredColor = Iris._config.HeaderHoveredColor,
HoveredTransparency = Iris._config.HeaderHoveredTransparency,
ActiveColor = Iris._config.HeaderActiveColor,
ActiveTransparency = Iris._config.HeaderActiveTransparency,
}

widgets.applyInteractionHighlights(thisWidget, SelectableButton, SelectableButton, thisWidget.ButtonColors)
widgets.applyInteractionHighlights(thisWidget, "Background", SelectableButton, SelectableButton, thisWidget.ButtonColors)

widgets.applyButtonClick(thisWidget, SelectableButton, function()
if thisWidget.arguments.NoClick ~= true then
Expand Down Expand Up @@ -116,11 +116,11 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
local Selectable = thisWidget.Instance :: Frame
local SelectableButton: TextButton = Selectable.SelectableButton
if thisWidget.state.index.value == (thisWidget.arguments.Index or true) then
thisWidget.ButtonColors.ButtonTransparency = Iris._config.HeaderTransparency
thisWidget.ButtonColors.Transparency = Iris._config.HeaderTransparency
SelectableButton.BackgroundTransparency = Iris._config.HeaderTransparency
thisWidget.lastSelectedTick = Iris._cycleTick + 1
else
thisWidget.ButtonColors.ButtonTransparency = 1
thisWidget.ButtonColors.Transparency = 1
SelectableButton.BackgroundTransparency = 1
thisWidget.lastUnselectedTick = Iris._cycleTick + 1
end
Expand Down Expand Up @@ -290,28 +290,28 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

-- for some reason ImGui Combo has no highlights for Active, only hovered.
-- so this deviates from ImGui, but its a good UX change
widgets.applyInteractionHighlightsWithMultiHighlightee(thisWidget, PreviewContainer, {
widgets.applyInteractionHighlightsWithMultiHighlightee(thisWidget, "Background", PreviewContainer, {
{
PreviewLabel,
{
ButtonColor = Iris._config.FrameBgColor,
ButtonTransparency = Iris._config.FrameBgTransparency,
ButtonHoveredColor = Iris._config.FrameBgHoveredColor,
ButtonHoveredTransparency = Iris._config.FrameBgHoveredTransparency,
ButtonActiveColor = Iris._config.FrameBgActiveColor,
ButtonActiveTransparency = Iris._config.FrameBgActiveTransparency,
Color = Iris._config.FrameBgColor,
Transparency = Iris._config.FrameBgTransparency,
HoveredColor = Iris._config.FrameBgHoveredColor,
HoveredTransparency = Iris._config.FrameBgHoveredTransparency,
ActiveColor = Iris._config.FrameBgActiveColor,
ActiveTransparency = Iris._config.FrameBgActiveTransparency,
},
},
{
DropdownButton,
{
ButtonColor = Iris._config.ButtonColor,
ButtonTransparency = Iris._config.ButtonTransparency,
ButtonHoveredColor = Iris._config.ButtonHoveredColor,
ButtonHoveredTransparency = Iris._config.ButtonHoveredTransparency,
Color = Iris._config.ButtonColor,
Transparency = Iris._config.ButtonTransparency,
HoveredColor = Iris._config.ButtonHoveredColor,
HoveredTransparency = Iris._config.ButtonHoveredTransparency,
-- Use hovered for active
ButtonActiveColor = Iris._config.ButtonHoveredColor,
ButtonActiveTransparency = Iris._config.ButtonHoveredTransparency,
ActiveColor = Iris._config.ButtonHoveredColor,
ActiveTransparency = Iris._config.ButtonHoveredTransparency,
},
},
})
Expand Down
14 changes: 7 additions & 7 deletions lib/widgets/Image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
Image.ImageTransparency = Iris._config.ImageTransparency
Image.Parent = Button

widgets.applyInteractionHighlights(thisWidget, Button, Button, {
ButtonColor = Iris._config.FrameBgColor,
ButtonTransparency = Iris._config.FrameBgTransparency,
ButtonHoveredColor = Iris._config.FrameBgHoveredColor,
ButtonHoveredTransparency = Iris._config.FrameBgHoveredTransparency,
ButtonActiveColor = Iris._config.FrameBgActiveColor,
ButtonActiveTransparency = Iris._config.FrameBgActiveTransparency,
widgets.applyInteractionHighlights(thisWidget, "Background", Button, Button, {
Color = Iris._config.FrameBgColor,
Transparency = Iris._config.FrameBgTransparency,
HoveredColor = Iris._config.FrameBgHoveredColor,
HoveredTransparency = Iris._config.FrameBgHoveredTransparency,
ActiveColor = Iris._config.FrameBgActiveColor,
ActiveTransparency = Iris._config.FrameBgActiveTransparency,
})

return Button
Expand Down
28 changes: 14 additions & 14 deletions lib/widgets/Input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,13 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

DragField.Parent = Drag

widgets.applyInteractionHighlights(thisWidget, DragField, DragField, {
ButtonColor = Iris._config.FrameBgColor,
ButtonTransparency = Iris._config.FrameBgTransparency,
ButtonHoveredColor = Iris._config.FrameBgHoveredColor,
ButtonHoveredTransparency = Iris._config.FrameBgHoveredTransparency,
ButtonActiveColor = Iris._config.FrameBgActiveColor,
ButtonActiveTransparency = Iris._config.FrameBgActiveTransparency,
widgets.applyInteractionHighlights(thisWidget, "Background", DragField, DragField, {
Color = Iris._config.FrameBgColor,
Transparency = Iris._config.FrameBgTransparency,
HoveredColor = Iris._config.FrameBgHoveredColor,
HoveredTransparency = Iris._config.FrameBgHoveredTransparency,
ActiveColor = Iris._config.FrameBgActiveColor,
ActiveTransparency = Iris._config.FrameBgActiveTransparency,
})

local InputField: TextBox = Instance.new("TextBox")
Expand Down Expand Up @@ -985,13 +985,13 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

OverlayText.Parent = SliderField

widgets.applyInteractionHighlights(thisWidget, SliderField, SliderField, {
ButtonColor = Iris._config.FrameBgColor,
ButtonTransparency = Iris._config.FrameBgTransparency,
ButtonHoveredColor = Iris._config.FrameBgHoveredColor,
ButtonHoveredTransparency = Iris._config.FrameBgHoveredTransparency,
ButtonActiveColor = Iris._config.FrameBgActiveColor,
ButtonActiveTransparency = Iris._config.FrameBgActiveTransparency,
widgets.applyInteractionHighlights(thisWidget, "Background", SliderField, SliderField, {
Color = Iris._config.FrameBgColor,
Transparency = Iris._config.FrameBgTransparency,
HoveredColor = Iris._config.FrameBgHoveredColor,
HoveredTransparency = Iris._config.FrameBgHoveredTransparency,
ActiveColor = Iris._config.FrameBgActiveColor,
ActiveTransparency = Iris._config.FrameBgActiveTransparency,
})

local InputField: TextBox = Instance.new("TextBox")
Expand Down
Loading

0 comments on commit 7be1b09

Please sign in to comment.