Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

Commit 210c779

Browse files
committed
Added aspect ratio support.
1 parent fe618c5 commit 210c779

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local choices = {
2+
{ Id = "1", Value = 0.5, Text = "1:2" },
3+
{ Id = "2", Value = 0.563, Text = "9:16" },
4+
{ Id = "3", Value = 0.625, Text = "10:16" },
5+
{ Id = "4", Value = 0.75, Text = "3:4" },
6+
{ Id = "5", Value = 1, Text = "1:1" },
7+
{ Id = "6", Value = 1.333, Text = "4:3" },
8+
{ Id = "7", Value = 1.6, Text = "16:10" },
9+
{ Id = "8", Value = 1.7, Text = "16:9" },
10+
{ Id = "9", Value = 2, Text = "2:1" },
11+
}
12+
13+
return choices

src/SignsInternal/PluginGui/GuiObjectPart.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ local Selection = game:GetService("Selection")
1313
GuiObjectPart = {}
1414
GuiObjectPart.__index = GuiObjectPart
1515

16-
function GuiObjectPart.new(label: GuiObject, autoLocalize: boolean?, lightInfluence: number?, alwaysOnTop: boolean?)
16+
function GuiObjectPart.new(label: GuiObject, autoLocalize: boolean?, lightInfluence: number?, alwaysOnTop: boolean?, size: Vector2)
1717
local self = {}
1818
setmetatable(self, GuiObjectPart)
1919

2020
local camera = workspace.CurrentCamera or Instance.new("Camera")
2121

22+
local partSizeX = label.AbsoluteSize.X / 50
23+
local partSizeY = label.AbsoluteSize.Y / 50
2224
local part = Instance.new("Part")
2325
part.Name = "SignPart"
2426
part.Anchored = true
2527
part.Parent = workspace
2628
part.Transparency = 1
27-
part.Size = Vector3.new(4, 4, 0)
29+
part.Size = Vector3.new(partSizeX, partSizeY, 0)
2830
part.Position = (camera.CFrame + camera.CFrame.LookVector * 10).Position
2931
local yCameraRotation = camera.CFrame.Rotation.Y
3032
local yRotation = math.floor(yCameraRotation/90 + 0.5) * 90
@@ -33,7 +35,8 @@ function GuiObjectPart.new(label: GuiObject, autoLocalize: boolean?, lightInflue
3335
CollectionService:AddTag(part, "_Sign")
3436

3537
local surfaceGui = Instance.new("SurfaceGui")
36-
surfaceGui.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
38+
-- surfaceGui.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
39+
surfaceGui.CanvasSize = size or Vector2.new(200, 200)
3740
surfaceGui.LightInfluence = lightInfluence or 0
3841
surfaceGui.AlwaysOnTop = alwaysOnTop or false
3942
surfaceGui.AutoLocalize = autoLocalize or true

src/SignsInternal/PluginGui/init.lua

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ local Color = require(script.Color)
1515
local FontFace = require(script.FontFace)
1616
local GuiObjectPart = require(script.GuiObjectPart)
1717
local LineJoinMode = require(script.LineJoinMode)
18+
local AspectRatio = require(script.AspectRatio)
1819
local TextXAlignment = require(script.TextXAlignment)
1920
local TextYAlignment = require(script.TextYAlignment)
2021

@@ -246,6 +247,23 @@ function PluginGui:newPluginGui(widgetGui)
246247
end
247248
colorStrokeChoice:GetFrame().Parent = strokeCollapse:GetContentsFrame()
248249

250+
local sizeCollapse = CollapsibleTitledSection.new( -- Fonts collapse
251+
"SizeCollapse", -- name suffix of the gui object
252+
"Size", -- the text displayed beside the collapsible arrow
253+
true, -- have the content frame auto-update its size?
254+
true, -- minimizable?
255+
true -- minimized by default?
256+
)
257+
listFrame:AddChild(sizeCollapse:GetSectionFrame()) -- add child to expanding VerticallyScalingListFrame
258+
259+
local ratioChoice = LabeledMultiChoice.new(
260+
"RatioChoice", -- name suffix of gui object
261+
"Aspect Ratio", -- title text of the multi choice
262+
AspectRatio, -- choices array
263+
5 -- the starting index of the selection
264+
)
265+
ratioChoice:GetFrame().Parent = sizeCollapse:GetContentsFrame()
266+
249267
local backgroundCollapse = CollapsibleTitledSection.new( -- Fonts collapse
250268
"BackgroundCollapse", -- name suffix of the gui object
251269
"Background", -- the text displayed beside the collapsible arrow
@@ -318,7 +336,8 @@ function PluginGui:newPluginGui(widgetGui)
318336
local influence = ((influenceSlider:GetValue() - 1) / 4)
319337
local top = topCheckbox:GetValue()
320338
local localize = localizeCheckbox:GetValue()
321-
GuiObjectPart.new(label, localize, influence, top)
339+
local size = CustomTextLabel:GetLabel().AbsoluteSize
340+
GuiObjectPart.new(label, localize, influence, top, size)
322341
end)
323342

324343
textInput:SetValueChangedFunction(function(newValue)
@@ -415,6 +434,11 @@ function PluginGui:newPluginGui(widgetGui)
415434
local newValue = Color[newIndex].Color
416435
CustomTextLabel:UpdateBackgroundColor3(newValue)
417436
end)
437+
438+
ratioChoice:SetValueChangedFunction(function(newIndex)
439+
local newValue = AspectRatio[newIndex].Value
440+
CustomTextLabel:UpdateAspectRatio(newValue)
441+
end)
418442
end
419443

420444
function PluginGui:destoryPluginGui(widgetGui)

src/SignsInternal/StudioWidgets/CustomTextLabel.lua

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,24 @@ function CustomTextLabelClass.new(nameSuffix, height)
1414
local self = {}
1515
setmetatable(self, CustomTextLabelClass)
1616

17-
local frame = GuiUtilities.MakeFixedHeightFrame("TextLabel " .. nameSuffix, height)
17+
local background = GuiUtilities.MakeFixedHeightFrame("TextLabel " .. nameSuffix, height)
18+
background.Size = UDim2.new(1, 0, 0, height)
19+
background.BackgroundTransparency = 1
20+
self._background = background
21+
22+
local frame = Instance.new("Frame")
1823
frame.BorderSizePixel = 1
19-
frame.Size = UDim2.new(1, 0, 0, height)
24+
frame.Size = UDim2.new(0, height, 0, height)
25+
frame.AnchorPoint = Vector2.new(0.5, 0.5)
26+
frame.Position = UDim2.new(0.5, 0, 0.5, 0)
27+
frame.Parent = background
2028
GuiUtilities.syncGuiElementShadowColor(frame)
29+
GuiUtilities.syncGuiElementScrollBarBackgroundColor(frame)
2130
self._frame = frame
2231

32+
local aspectRatio = Instance.new("UIAspectRatioConstraint")
33+
aspectRatio.Parent = frame
34+
2335
local label = Instance.new("TextLabel")
2436
label.Text = "Preview"
2537
label.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
@@ -43,6 +55,10 @@ function CustomTextLabelClass.new(nameSuffix, height)
4355
end
4456
self._stroke = stroke
4557

58+
function CustomTextLabelClass:UpdateAspectRatio(newValue: number)
59+
aspectRatio.AspectRatio = newValue
60+
end
61+
4662
function CustomTextLabelClass:UpdateTextRotation(newValue: number)
4763
label.Rotation = newValue
4864
end
@@ -160,7 +176,7 @@ function CustomTextLabelClass.new(nameSuffix, height)
160176
end
161177

162178
function CustomTextLabelClass:GetFrame()
163-
return frame
179+
return background
164180
end
165181

166182
return self

0 commit comments

Comments
 (0)