Cool! Good for UI Designing
Works perfectly fine!
Very awesome!
I would like for there to be an option to automatically convert any newly inserted UI elements to scale so I don’t have to do that manually. Then I would definitely get this.
Really cool! Thank you so much for making this plugin!! ;D
I actually started working on that yesterday lol, going to release it today.
Edit: Released the new update but the settings toggle doesn’t seem to be working, will fix tomorrow.
This plugin will make a fine addition to my collection
Awesome, I’ve been looking for something like this for ages. My attempts at UI design had been previously slaughtered by it looking funky on different size screens, and I never did get these UI constraint things. Thank you, this will be very helpful.
Hi everyone, the new update has arrived and the setting now works.
Click the Settings button at the plugin tab to open this gui, your settings are saved through the plugin. Please tell me if you experience crashes when clicking the button.
This. Is. Amazing.
This actually helps a lot- great time saver.
So helpful! Thank you!
Np, if you have any feature suggestions just message me <3
Yeah I noticed default scale would just make images or frames WAY too big and messing around with it can get really confusing and time consuming thanks for making this plugin, I’ll use it a lot
The AutoScale feature has actually transformed my UI design completely, and scalability is excellent now, so thank you!
One gripe I have about GUIs is that TextScaled is kinda limited; if you have a row of TextButtons, and each is set to automatically scale, they’re all going to have different text sizes and look terrible. Right now, I circumvent this in my game by changing the TextSize every time the game resolution is changed until TextFits = false for every TextLabel in the same “group”, and then use the the biggest TextSize that fits all the TextLabels in the group. Have you had any experience dealing with this? I hope it’s not too off-topic, but if no functionality exists (well… that I’m aware of) I feel like this would be a good concept for a public module (not sure how a plug-in would work).
Useful for new developers! Great job!
I’ve definitely experienced this before, I’ll look into how I could implement a fix into a plugin. Thanks!
(Might make a viewport frame plugin soon)
I thought of doing it as a module, where you have a method like Module:AddTextGroup(group), where group is an array of TextLabels/Buttons that must be the same size. Every time the method is called it scales the text group to the same, largest possible size, and every time the game resolution changes, it does the same for all added text groups
Actually, I think I’m gonna make this now, lol, I already do a similar thing for my game GUI, but it’s cumbersome having to connect to my custom ResolutionChanged event every time.
UITextSizeConstraints will help with this
I just learned about that, but I’m not sure if I should use them or not, since it doesn’t seem like it’s going to be much more efficient or easy.
This currently works quite well for me, but it’s not really the most efficient; around 1% script usage for me when vigorously changing the resolution, and that’s with only 2 text label groups, but I think it should be OK since a small performance hit can generally be ignored when you’re resizing your game for half a second.
Would appreciate thoughts on if there’s a better way to do this though
Example place Smart Text Scaler.rbxl (20.2 KB)
Module modelSmartTextScaler.rbxm (2.8 KB)
Text scaling with module (updates with resolution):
Regular TextScaled:
Here is the module;
--[[
SmartTextHandler module by Bobby_Darin
This simulates the TextScaled property for TextButtons and TextLabels,
but allows you to set a "group" of TextButtons and TextLabels
which will all scale to the same size (the largest size possible,
without any one member of the group having a text size too big for
their gui object).
By default, the TextSize will update every time the game resolution
is changed by the player.
This works by finding the longest TextLabel/TextButton of the group,
and then finding the largest possible text size for this TextObject
(without the text escaping the bounds of the gui container),
and then setting all the TextObjects in the group to that size.
To use, Module:NewGroup(object : table)
The object dictionary argument should consist of;
Required properties
array TextObjects : all TextLabels and TextButtons in the same
"group," which will all maintain the same text size whenever
the resolution is changed.
Optional properties
bool OnlyUpdateWhenVisible (false)
When the game resolution is changed, the text group
size will only update if at least one member of
TextObjects is visible.
bool UpdateWhenMadeVisible (false)
Update the text group size whenever a member of
TextObjects is made visible, in addition to
whenever the resolution is changed
int MinTextSize (1)
int MaxTextSize(1)
Vector2 TextBorderSize (2, 2)
number SizeModifier (0.95)
Example usage:
----
Module:NewGroup{
TextObjects = {
TextLabel1,
TextLabel2,
TextButton1
},
MaxTextSize = 50,
}
----
TextLabel1, TextLabel2, and TextButton1 will now be automatically scaled,
and all maintain the same text size too.
--]]
------------------------------------------
local SmartTextHandler = {}
local text_service = game:GetService("TextService")
local GetTextSize = text_service.GetTextSize
------------------------------------------
-- Methods
function SmartTextHandler:NewGroup(object)
if not object then
return
end
if not object.TextObjects then
return
end
setmetatable(object, self)
self.__index = self
object.MinTextSize = object.MinTextSize or 1
object.MaxTextSize = object.MaxTextSize or 100
object.TextBorderSize = object.TextBorderSize or Vector2.new(2, 2)
object.SizeModifier = object.SizeModifier or 0.95
object:Update()
if object.UpdateWhenMadeVisible then
for k,text_object in next, object.TextObjects do
text_object.Changed:connect(function(property)
if property ~= "Visible" or not text_object.Visible then
return
end
object:Update()
end)
end
end
workspace.CurrentCamera.Changed:connect(function(property)
if property ~= "ViewportSize" then
return
end
-- property == "ViewportSize"
if not object.OnlyUpdateWhenVisible then
object:Update()
return
end
-- object.OnlyUpdateWhenVisible == true
for k,text_object in next, object.TextObjects do
if text_object.Visible then
-- a TextObject is visible, so update the group
object:Update()
return
end
end
end)
return object
end
function SmartTextHandler:GetLongestTextObject()
local longest_object = nil
local longest_object_str_length = 0
for k,text_object in next, self.TextObjects do
if #text_object.Text > longest_object_str_length then
longest_object = text_object
longest_object_str_length = #text_object.Text
end
end
return longest_object
end
function SmartTextHandler:Update()
local best_size = 0
-- Text sizing is based off of the TextObject with
-- the most characters, as this object will have a lower possible
-- font size than the rest of the group
local longest_object = self:GetLongestTextObject()
local text = longest_object.Text
local font = longest_object.Font
local bounds = (longest_object.AbsoluteSize - self.TextBorderSize) * self.SizeModifier
local wrap_size = Vector2.new(bounds.X, 1e4)
for font_size = self.MinTextSize + 1, self.MaxTextSize + 1 do
local text_size = GetTextSize(
text_service,
text,
font_size,
font,
wrap_size
)
if text_size.X >= bounds.X or text_size.Y >= bounds.Y then
best_size = font_size - 1
break
end
end
for k,text_object in next, self.TextObjects do
text_object.TextScaled = false
text_object.TextWrapped = true
text_object.TextSize = best_size
end
if self.OnUpdate then
self:OnUpdate()
end
end
return SmartTextHandler