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

Fix AutoComplete Menu Max Size #268

Merged
merged 5 commits into from
Jul 5, 2023
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
36 changes: 29 additions & 7 deletions Cmdr/CmdrClient/CmdrInterface/AutoComplete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ return function(Cmdr)
local Entry = Gui.Parent:WaitForChild("Frame"):WaitForChild("Entry")
AutoItem.Parent = nil

local defaultBarThickness = Gui.ScrollBarThickness

-- Helper function that sets text and resizes labels
local function SetText(obj, textObj, text, sizeFromContents)
obj.Visible = text ~= nil
Expand All @@ -33,6 +35,15 @@ return function(Cmdr)
end
end

local function UpdateContainerSize()
Gui.Size = UDim2.new(
0,
math.max(Title.Field.TextBounds.X + Title.Field.Type.TextBounds.X, Gui.Size.X.Offset),
0,
math.min(Gui.UIListLayout.AbsoluteContentSize.Y, Gui.Parent.AbsoluteSize.Y - Gui.AbsolutePosition.Y - 10)
)
end

-- Update the info display (Name, type, and description) based on given options.
local function UpdateInfoDisplay(options)
-- Update the objects' text and sizes
Expand All @@ -45,11 +56,6 @@ return function(Cmdr)
SetText(Description, Description.Label, options.description)

Description.Label.TextColor3 = options.invalid and Color3.fromRGB(255, 73, 73) or Color3.fromRGB(255, 255, 255)

-- Calculate needed width and height
local infoWidth = Title.Field.TextBounds.X + Title.Field.Type.TextBounds.X

local guiWidth = math.max(infoWidth, Gui.Size.X.Offset)
Description.Size = UDim2.new(1, 0, 0, 40)

-- Flow description text
Expand All @@ -62,9 +68,10 @@ return function(Cmdr)
end

-- Update container
wait()
task.wait()
Gui.UIListLayout:ApplyLayout()
Gui.Size = UDim2.new(0, guiWidth, 0, Gui.UIListLayout.AbsoluteContentSize.Y)
UpdateContainerSize()
Gui.ScrollBarThickness = defaultBarThickness
end

--- Shows the auto complete menu with the given list and possible options
Expand Down Expand Up @@ -101,6 +108,8 @@ return function(Cmdr)
-- Generate the new option labels
local autocompleteWidth = 200

Gui.ScrollBarThickness = 0

for i, item in pairs(self.Items) do
local leftText = item[1]
local rightText = item[2]
Expand Down Expand Up @@ -185,10 +194,23 @@ return function(Cmdr)
item.gui.BackgroundTransparency = i == self.SelectedItem and 0.5 or 1
end

Gui.CanvasPosition = Vector2.new(
0,
math.max(
0,
Title.Size.Y.Offset
+ Description.Size.Y.Offset
+ self.SelectedItem * AutoItem.Size.Y.Offset
- Gui.Size.Y.Offset
)
)

if self.Items[self.SelectedItem] and self.Items[self.SelectedItem].options then
UpdateInfoDisplay(self.Items[self.SelectedItem].options or {})
end
end

Gui.Parent:GetPropertyChangedSignal("AbsoluteSize"):Connect(UpdateContainerSize)

return AutoComplete
end
7 changes: 6 additions & 1 deletion Cmdr/CreateGui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ return function()
Frame.AutomaticCanvasSize = Enum.AutomaticSize.Y
Frame.Parent = Cmdr

local Autocomplete = Instance.new("Frame")
local Autocomplete = Instance.new("ScrollingFrame")
Autocomplete.BackgroundColor3 = Color3.fromRGB(59, 59, 59)
Autocomplete.BackgroundTransparency = 0.5
Autocomplete.BorderSizePixel = 0
Autocomplete.CanvasSize = UDim2.new(0, 0, 0, 0)
Autocomplete.Name = "Autocomplete"
Autocomplete.Position = UDim2.new(0, 167, 0, 75)
Autocomplete.ScrollBarThickness = 6
Autocomplete.ScrollingDirection = Enum.ScrollingDirection.Y
Autocomplete.Selectable = false
Autocomplete.Size = UDim2.new(0, 200, 0, 200)
Autocomplete.Visible = false
Autocomplete.AutomaticCanvasSize = Enum.AutomaticSize.Y
Autocomplete.Parent = Cmdr

local UIListLayout = Instance.new("UIListLayout")
Expand Down