Skip to content

Commit

Permalink
Added ContentHeight config.
Browse files Browse the repository at this point in the history
Support for multiline and readonly InputText widgets and customisable widget heights.
  • Loading branch information
SirMallard committed Aug 6, 2024
1 parent 639c3f2 commit 4eb3244
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 36 deletions.
4 changes: 3 additions & 1 deletion lib/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ return function(Iris: Types.Iris)
hasState = true
Arguments = {
Text: string? = "InputText",
TextHint: string? = "" -- a hint to display when the text box is empty.
TextHint: string? = "", -- a hint to display when the text box is empty.
ReadOnly: boolean? = false,
MultiLine: boolean? = false
}
Events = {
textChanged: () -> boolean, -- whenever the textbox looses focus and a change was made.
Expand Down
3 changes: 3 additions & 0 deletions lib/Types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export type Arguments = {
[string]: Argument,
Text: string,
TextHint: string,
ReadOnly: boolean,
MultiLine: boolean,
Wrapped: boolean,
Color: Color3,
RichText: boolean,
Expand Down Expand Up @@ -607,6 +609,7 @@ export type Config = {
-- Sizes
ItemWidth: UDim,
ContentWidth: UDim,
ContentHeight: UDim,

WindowPadding: Vector2,
WindowResizePadding: Vector2,
Expand Down
2 changes: 2 additions & 0 deletions lib/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ local TemplateConfig = {
sizeDefault = { -- Dear, ImGui default
ItemWidth = UDim.new(1, 0),
ContentWidth = UDim.new(0.65, 0),
ContentHeight = UDim.new(0, 0),

WindowPadding = Vector2.new(8, 8),
WindowResizePadding = Vector2.new(6, 6),
Expand Down Expand Up @@ -218,6 +219,7 @@ local TemplateConfig = {
sizeClear = { -- easier to read and manuveure
ItemWidth = UDim.new(1, 0),
ContentWidth = UDim.new(0.65, 0),
ContentHeight = UDim.new(0, 0),

WindowPadding = Vector2.new(12, 8),
WindowResizePadding = Vector2.new(8, 8),
Expand Down
47 changes: 47 additions & 0 deletions lib/demoWindow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,53 @@ return function(Iris: Types.Iris)
Iris.PopConfig()
end
Iris.End()

Iris.Tree({ "Content Height" })
do
local text = Iris.State("a single line")
local value = Iris.State(50)
local index = Iris.State(Enum.Axis.X)
local progress = Iris.State(0)

-- formula to cycle between 0 and 100 linearly
local newValue = math.clamp((math.abs((os.clock() * 15) % 100 - 50)) - 7.5, 0, 35) / 35
progress:set(newValue)

Iris.Text({ "The Content Height is a size property that determines the minimum size of certain widgets." })
Iris.Text({ "By default the value is UDim.new(0, 0), so there is no minimum height." })
Iris.Text({ "We use Iris.PushConfig() to change this value." })

Iris.Separator()
Iris.SameLine()
do
Iris.Text({ "Content Height = 0 pixels" })
helpMarker("UDim.new(0, 0)")
end
Iris.End()

Iris.InputText({ "text" }, { text = text })
Iris.ProgressBar({ "progress" }, { progress = progress })
Iris.DragNum({ "number", 1, 0, 100 }, { number = value })
Iris.ComboEnum({ "axis" }, { index = index }, Enum.Axis)

Iris.SameLine()
do
Iris.Text({ "Content Height = 60 pixels" })
helpMarker("UDim.new(0, 60)")
end
Iris.End()

Iris.PushConfig({ ContentHeight = UDim.new(0, 60) })
Iris.InputText({ "text", nil, nil, true }, { text = text })
Iris.ProgressBar({ "progress" }, { progress = progress })
Iris.DragNum({ "number", 1, 0, 100 }, { number = value })
Iris.ComboEnum({ "axis" }, { index = index }, Enum.Axis)
Iris.PopConfig()

Iris.Text({ "This property can be used to force the height of a text box." })
Iris.Text({ "Just make sure you enable the MultiLine argument." })
end
Iris.End()
end
Iris.End()
end
Expand Down
13 changes: 7 additions & 6 deletions lib/widgets/Combo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local PreviewLabel: TextLabel = Instance.new("TextLabel")
PreviewLabel.Name = "PreviewLabel"
PreviewLabel.Size = UDim2.new(1, 0, 0, 0)
PreviewLabel.Size = UDim2.new(UDim.new(1, 0), Iris._config.ContentHeight)
PreviewLabel.AutomaticSize = Enum.AutomaticSize.Y
PreviewLabel.BackgroundColor3 = Iris._config.FrameBgColor
PreviewLabel.BackgroundTransparency = Iris._config.FrameBgTransparency
Expand All @@ -265,7 +265,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local DropdownButton: TextLabel = Instance.new("TextLabel")
DropdownButton.Name = "DropdownButton"
DropdownButton.Size = UDim2.new(0, frameHeight, 0, frameHeight)
DropdownButton.Size = UDim2.new(0, frameHeight, Iris._config.ContentHeight.Scale, math.max(Iris._config.ContentHeight.Offset, frameHeight))
DropdownButton.BorderSizePixel = 0
DropdownButton.BackgroundColor3 = Iris._config.ButtonColor
DropdownButton.BackgroundTransparency = Iris._config.ButtonTransparency
Expand All @@ -276,8 +276,9 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local Dropdown: ImageLabel = Instance.new("ImageLabel")
Dropdown.Name = "Dropdown"
Dropdown.AnchorPoint = Vector2.new(0.5, 0.5)
Dropdown.Size = UDim2.fromOffset(dropdownSize, dropdownSize)
Dropdown.Position = UDim2.fromOffset(padding, padding)
Dropdown.Position = UDim2.fromScale(0.5, 0.5)
Dropdown.BackgroundTransparency = 1
Dropdown.BorderSizePixel = 0
Dropdown.ImageColor3 = Iris._config.TextColor
Expand Down Expand Up @@ -379,11 +380,11 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

if thisWidget.arguments.NoButton then
DropdownButton.Visible = false
PreviewLabel.Size = UDim2.new(1, 0, 0, 0)
PreviewLabel.Size = UDim2.new(UDim.new(1, 0), PreviewLabel.Size.Height)
else
DropdownButton.Visible = true
local DropdownButtonSize = Iris._config.TextSize + 2 * Iris._config.FramePadding.Y
PreviewLabel.Size = UDim2.new(1, -DropdownButtonSize, 0, 0)
PreviewLabel.Size = UDim2.new(UDim.new(1, -DropdownButtonSize), PreviewLabel.Size.Height)
end

if thisWidget.arguments.NoPreview then
Expand All @@ -392,7 +393,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
PreviewContainer.AutomaticSize = Enum.AutomaticSize.XY
else
PreviewLabel.Visible = true
PreviewContainer.Size = UDim2.new(Iris._config.ContentWidth, UDim.new(0, 0))
PreviewContainer.Size = UDim2.new(Iris._config.ContentWidth, Iris._config.ContentHeight)
PreviewContainer.AutomaticSize = Enum.AutomaticSize.Y
end
end,
Expand Down
46 changes: 21 additions & 25 deletions lib/widgets/Input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local SubButton = widgets.abstractButton.Generate(thisWidget) :: TextButton
SubButton.Name = "SubButton"
SubButton.ZIndex = thisWidget.ZIndex + 5
SubButton.LayoutOrder = thisWidget.ZIndex + 5
SubButton.ZIndex = 5
SubButton.LayoutOrder = 5
SubButton.TextXAlignment = Enum.TextXAlignment.Center
SubButton.Text = "-"
SubButton.Size = UDim2.fromOffset(Iris._config.TextSize + 2 * Iris._config.FramePadding.Y, Iris._config.TextSize)
Expand All @@ -219,8 +219,8 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local AddButton = widgets.abstractButton.Generate(thisWidget) :: TextButton
AddButton.Name = "AddButton"
AddButton.ZIndex = thisWidget.ZIndex + 6
AddButton.LayoutOrder = thisWidget.ZIndex + 6
AddButton.ZIndex = 6
AddButton.LayoutOrder = 6
AddButton.TextXAlignment = Enum.TextXAlignment.Center
AddButton.Text = "+"
AddButton.Size = UDim2.fromOffset(Iris._config.TextSize + 2 * Iris._config.FramePadding.Y, Iris._config.TextSize)
Expand Down Expand Up @@ -292,9 +292,9 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
InputField.Name = "InputField" .. tostring(index)
InputField.LayoutOrder = index
if index == components then
InputField.Size = UDim2.new(lastComponentWidth, UDim.new())
InputField.Size = UDim2.new(lastComponentWidth, Iris._config.ContentHeight)
else
InputField.Size = UDim2.new(componentWidth, UDim.new())
InputField.Size = UDim2.new(componentWidth, Iris._config.ContentHeight)
end
InputField.AutomaticSize = Enum.AutomaticSize.Y
InputField.BackgroundColor3 = Iris._config.FrameBgColor
Expand Down Expand Up @@ -346,11 +346,10 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local TextLabel: TextLabel = Instance.new("TextLabel")
TextLabel.Name = "TextLabel"
TextLabel.Size = UDim2.fromOffset(0, textHeight)
TextLabel.BackgroundTransparency = 1
TextLabel.BorderSizePixel = 0
TextLabel.LayoutOrder = 7
TextLabel.AutomaticSize = Enum.AutomaticSize.X
TextLabel.AutomaticSize = Enum.AutomaticSize.XY

widgets.applyTextStyle(TextLabel)

Expand Down Expand Up @@ -581,9 +580,9 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
DragField.Name = "DragField" .. tostring(index)
DragField.LayoutOrder = index
if index == components then
DragField.Size = UDim2.new(lastComponentWidth, UDim.new())
DragField.Size = UDim2.new(lastComponentWidth, Iris._config.ContentHeight)
else
DragField.Size = UDim2.new(componentWidth, UDim.new())
DragField.Size = UDim2.new(componentWidth, Iris._config.ContentHeight)
end
DragField.AutomaticSize = Enum.AutomaticSize.Y
DragField.BackgroundColor3 = Iris._config.FrameBgColor
Expand Down Expand Up @@ -680,11 +679,10 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local TextLabel: TextLabel = Instance.new("TextLabel")
TextLabel.Name = "TextLabel"
TextLabel.Size = UDim2.fromOffset(0, textHeight)
TextLabel.BackgroundTransparency = 1
TextLabel.BorderSizePixel = 0
TextLabel.LayoutOrder = 6
TextLabel.AutomaticSize = Enum.AutomaticSize.X
TextLabel.AutomaticSize = Enum.AutomaticSize.XY

widgets.applyTextStyle(TextLabel)

Expand Down Expand Up @@ -944,8 +942,6 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
local UIListLayout: UIListLayout = widgets.UIListLayout(Slider, Enum.FillDirection.Horizontal, UDim.new(0, Iris._config.ItemInnerSpacing.X))
UIListLayout.VerticalAlignment = Enum.VerticalAlignment.Center

local textHeight: number = Iris._config.TextSize + 2 * Iris._config.FramePadding.Y

-- we divide the total area evenly between each field. This includes accounting for any additional boxes and the offset.
-- for the final field, we make sure it's flush by calculating the space avaiable for it. This only makes the Vector2 box
-- 4 pixels shorter, all for the sake of flush.
Expand All @@ -958,9 +954,9 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
SliderField.Name = "SliderField" .. tostring(index)
SliderField.LayoutOrder = index
if index == components then
SliderField.Size = UDim2.new(lastComponentWidth, UDim.new())
SliderField.Size = UDim2.new(lastComponentWidth, Iris._config.ContentHeight)
else
SliderField.Size = UDim2.new(componentWidth, UDim.new())
SliderField.Size = UDim2.new(componentWidth, Iris._config.ContentHeight)
end
SliderField.AutomaticSize = Enum.AutomaticSize.Y
SliderField.BackgroundColor3 = Iris._config.FrameBgColor
Expand Down Expand Up @@ -1072,11 +1068,10 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local TextLabel: TextLabel = Instance.new("TextLabel")
TextLabel.Name = "TextLabel"
TextLabel.Size = UDim2.fromOffset(0, textHeight)
TextLabel.BackgroundTransparency = 1
TextLabel.BorderSizePixel = 0
TextLabel.LayoutOrder = 5
TextLabel.AutomaticSize = Enum.AutomaticSize.X
TextLabel.AutomaticSize = Enum.AutomaticSize.XY

widgets.applyTextStyle(TextLabel)

Expand Down Expand Up @@ -1276,13 +1271,15 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
Iris.WidgetConstructor("SliderRect", generateSliderScalar("Rect", 4, Rect.new(0, 0, 0, 0)))
-- Iris.WidgetConstructor("SliderEnum", generateSliderScalar("Enum", 4, 0))

--stylua: ignore
-- stylua: ignore
Iris.WidgetConstructor("InputText", {
hasState = true,
hasChildren = false,
Args = {
["Text"] = 1,
["TextHint"] = 2,
["ReadOnly"] = 3,
["MultiLine"] = 4,
},
Events = {
["textChanged"] = {
Expand Down Expand Up @@ -1311,16 +1308,14 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local InputField: TextBox = Instance.new("TextBox")
InputField.Name = "InputField"
InputField.Size = UDim2.new(Iris._config.ContentWidth, UDim.new(0, 0))
InputField.Size = UDim2.new(Iris._config.ContentWidth, Iris._config.ContentHeight)
InputField.AutomaticSize = Enum.AutomaticSize.Y
InputField.BackgroundColor3 = Iris._config.FrameBgColor
InputField.BackgroundTransparency = Iris._config.FrameBgTransparency
InputField.Text = ""
InputField.TextYAlignment = Enum.TextYAlignment.Top
InputField.PlaceholderColor3 = Iris._config.TextDisabledColor
InputField.TextTruncate = Enum.TextTruncate.AtEnd
InputField.ClearTextOnFocus = false
InputField.ZIndex = thisWidget.ZIndex + 1
InputField.LayoutOrder = thisWidget.ZIndex + 1
InputField.ClipsDescendants = true

widgets.applyFrameStyle(InputField)
Expand All @@ -1343,8 +1338,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
TextLabel.AutomaticSize = Enum.AutomaticSize.X
TextLabel.BackgroundTransparency = 1
TextLabel.BorderSizePixel = 0
TextLabel.ZIndex = thisWidget.ZIndex + 4
TextLabel.LayoutOrder = thisWidget.ZIndex + 4
TextLabel.LayoutOrder = 1

widgets.applyTextStyle(TextLabel)

Expand All @@ -1359,6 +1353,8 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

TextLabel.Text = thisWidget.arguments.Text or "Input Text"
InputField.PlaceholderText = thisWidget.arguments.TextHint or ""
InputField.TextEditable = not thisWidget.arguments.ReadOnly
InputField.MultiLine = thisWidget.arguments.MultiLine
end,
Discard = function(thisWidget: Types.Widget)
thisWidget.Instance:Destroy()
Expand Down
10 changes: 6 additions & 4 deletions lib/widgets/Plot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local Bar: Frame = Instance.new("Frame")
Bar.Name = "Bar"
Bar.Size = UDim2.new(Iris._config.ContentWidth, UDim.new())
Bar.Size = UDim2.new(Iris._config.ContentWidth, Iris._config.ContentHeight)
Bar.BackgroundColor3 = Iris._config.FrameBgColor
Bar.BackgroundTransparency = Iris._config.FrameBgTransparency
Bar.BorderSizePixel = 0
Expand All @@ -47,10 +47,11 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local Progress: TextLabel = Instance.new("TextLabel")
Progress.Name = "Progress"
Progress.AutomaticSize = Enum.AutomaticSize.Y
Progress.Size = UDim2.new(UDim.new(0, 0), Iris._config.ContentHeight)
Progress.BackgroundColor3 = Iris._config.PlotHistogramColor
Progress.BackgroundTransparency = Iris._config.PlotHistogramTransparency
Progress.BorderSizePixel = 0
Progress.AutomaticSize = Enum.AutomaticSize.Y

widgets.applyTextStyle(Progress)
widgets.UIPadding(Progress, Iris._config.FramePadding)
Expand All @@ -62,6 +63,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
local Value: TextLabel = Instance.new("TextLabel")
Value.Name = "Value"
Value.AutomaticSize = Enum.AutomaticSize.XY
Value.Size = UDim2.new(UDim.new(0, 0), Iris._config.ContentHeight)
Value.BackgroundTransparency = 1
Value.BorderSizePixel = 0
Value.ZIndex = 1
Expand All @@ -73,8 +75,8 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)

local TextLabel: TextLabel = Instance.new("TextLabel")
TextLabel.Name = "TextLabel"
TextLabel.AnchorPoint = Vector2.new(0, 0.5)
TextLabel.AutomaticSize = Enum.AutomaticSize.XY
TextLabel.AnchorPoint = Vector2.new(0, 0.5)
TextLabel.BackgroundTransparency = 1
TextLabel.BorderSizePixel = 0
TextLabel.LayoutOrder = 1
Expand Down Expand Up @@ -121,7 +123,7 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
Value.Position = UDim2.new(progress, 0, 0, 0)
end

Progress.Size = UDim2.fromScale(progress, 0)
Progress.Size = UDim2.new(UDim.new(progress, 0), Progress.Size.Height)
if thisWidget.arguments.Format ~= nil and typeof(thisWidget.arguments.Format) == "string" then
Value.Text = thisWidget.arguments.Format
else
Expand Down
Loading

0 comments on commit 4eb3244

Please sign in to comment.