Skip to content

Commit

Permalink
Use UIFlexItem for Widgets
Browse files Browse the repository at this point in the history
With the full release of UIFlexItems out of Beta and available to clients, widgets can start using UIFlexItems.

There are two places where UIFlexItems can be used:
1. Window child containers to fill the full window height after the title and menu bar.
2. Window title bar text to fill the full width and clip properly with the collapse and close buttons.

Closes #46
  • Loading branch information
SirMallard authored Aug 3, 2024
2 parents 040ae28 + 572ab59 commit f0a9df2
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions lib/widgets/Window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local ChildContainer: ScrollingFrame = Instance.new("ScrollingFrame")
ChildContainer.Name = "ChildContainer"
ChildContainer.AutomaticSize = Enum.AutomaticSize.None
ChildContainer.Size = UDim2.fromScale(1, 1)
ChildContainer.Position = UDim2.fromOffset(0, 0)
ChildContainer.BackgroundColor3 = Iris._config.WindowBgColor
Expand Down Expand Up @@ -509,6 +508,8 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

TitleBar.Parent = Content

widgets.UIPadding(TitleBar, Vector2.xAxis * Iris._config.FramePadding.X)
widgets.UIListLayout(TitleBar, Enum.FillDirection.Horizontal, UDim.new(0, Iris._config.FramePadding.X)).VerticalAlignment = Enum.VerticalAlignment.Center
widgets.applyInputBegan(thisWidget, TitleBar, function(input: InputObject)
if input.UserInputType == Enum.UserInputType.Touch then
if not thisWidget.arguments.NoMove then
Expand All @@ -526,7 +527,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
CollapseButton.Name = "CollapseButton"
CollapseButton.AnchorPoint = Vector2.new(0, 0.5)
CollapseButton.Size = UDim2.fromOffset(TitleButtonSize, TitleButtonSize)
CollapseButton.Position = UDim2.new(0, Iris._config.FramePadding.X + 1, 0.5, 0)
CollapseButton.Position = UDim2.new(0, 0, 0.5, 0)
CollapseButton.AutomaticSize = Enum.AutomaticSize.None
CollapseButton.BackgroundTransparency = 1
CollapseButton.BorderSizePixel = 0
Expand Down Expand Up @@ -566,13 +567,12 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
CloseButton.Name = "CloseButton"
CloseButton.AnchorPoint = Vector2.new(1, 0.5)
CloseButton.Size = UDim2.fromOffset(TitleButtonSize, TitleButtonSize)
CloseButton.Position = UDim2.new(1, -(Iris._config.FramePadding.X + 1), 0.5, 0)
CloseButton.Position = UDim2.new(1, 0, 0.5, 0)
CloseButton.AutomaticSize = Enum.AutomaticSize.None
CloseButton.BackgroundTransparency = 1
CloseButton.BorderSizePixel = 0
CloseButton.Text = ""

CloseButton.ZIndex = thisWidget.ZIndex + 4
CloseButton.LayoutOrder = 2
CloseButton.AutoButtonColor = false

widgets.UICorner(CloseButton)
Expand Down Expand Up @@ -606,25 +606,23 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

-- allowing fractional titlebar title location dosent seem useful, as opposed to Enum.LeftRight.

local titleAlign: number
if Iris._config.WindowTitleAlign == Enum.LeftRight.Left then
titleAlign = 0
elseif Iris._config.WindowTitleAlign == Enum.LeftRight.Center then
titleAlign = 0.5
else
titleAlign = 1
end

local Title: TextLabel = Instance.new("TextLabel")
Title.Name = "Title"
Title.AnchorPoint = Vector2.new(titleAlign, 0)
Title.Position = UDim2.fromScale(titleAlign, 0)
Title.AutomaticSize = Enum.AutomaticSize.XY
Title.BorderSizePixel = 0
Title.BackgroundTransparency = 1

Title.LayoutOrder = 1
Title.ClipsDescendants = true

widgets.UIPadding(Title, Vector2.yAxis * Iris._config.FramePadding.Y)
widgets.applyTextStyle(Title)
widgets.UIPadding(Title, Iris._config.FramePadding)
Title.TextXAlignment = Enum.TextXAlignment[Iris._config.WindowTitleAlign.Name] :: Enum.TextXAlignment

local TitleFlexItem: UIFlexItem = Instance.new("UIFlexItem")
TitleFlexItem.FlexMode = Enum.UIFlexMode.Fill
TitleFlexItem.ItemLineAlignment = Enum.ItemLineAlignment.Center

TitleFlexItem.Parent = Title

Title.Parent = TitleBar

Expand Down Expand Up @@ -740,20 +738,15 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
end

-- TitleBar buttons
local TitleButtonPaddingSize = Iris._config.FramePadding.X + Iris._config.TextSize + Iris._config.FramePadding.X * 2
if thisWidget.arguments.NoCollapse then
TitleBar.CollapseButton.Visible = false
TitleBar.Title.UIPadding.PaddingLeft = UDim.new(0, Iris._config.FramePadding.X)
else
TitleBar.CollapseButton.Visible = true
TitleBar.Title.UIPadding.PaddingLeft = UDim.new(0, TitleButtonPaddingSize)
end
if thisWidget.arguments.NoClose then
TitleBar.CloseButton.Visible = false
TitleBar.Title.UIPadding.PaddingRight = UDim.new(0, Iris._config.FramePadding.X)
else
TitleBar.CloseButton.Visible = true
TitleBar.Title.UIPadding.PaddingRight = UDim.new(0, TitleButtonPaddingSize)
end

Title.Text = thisWidget.arguments.Title or ""
Expand Down

0 comments on commit f0a9df2

Please sign in to comment.