You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I want to make a textbox navigable only with the cursor
- What is the issue? Include screenshots / videos if possible!
I cant include screenshots but I can include the code so far
l
ocal TextService = game:GetService("TextService")
local scrollingFrame = script.Parent;
local textBox = scrollingFrame:WaitForChild("TextBox");
local function getTextSize(text)
return TextService:GetTextSize(text, textBox.TextSize, textBox.Font, textBox.AbsoluteSize)
end
local function getBoundsFromCursor()
local cursor = math.max(textBox.CursorPosition, textBox.SelectionStart);
if cursor == -1 then return end;
local lines = textBox.Text:sub(0, cursor - 1):split("\n");
local line = lines[#lines];
local lineIndex = #lines;
return Vector2.new(getTextSize(line).X, lineIndex * textBox.TextSize);
end
local function isInWindow(bounds)
local canvasPos = scrollingFrame.CanvasPosition;
local windowSize = scrollingFrame.AbsoluteWindowSize
return bounds.X >= canvasPos.X and bounds.X <= windowSize.X, bounds.Y >= canvasPos.Y and bounds.Y <= windowSize.Y
end
textBox:GetPropertyChangedSignal("TextBounds"):Connect(function()
scrollingFrame.CanvasSize = UDim2.fromOffset(textBox.TextBounds.X+1, textBox.TextBounds.Y+1)
end)
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(function()
if textBox:IsFocused() then
local cursorBounds = (getBoundsFromCursor());
local xInBounds, yInBounds = isInWindow(cursorBounds);
scrollingFrame.CanvasPosition = cursorBounds - Vector2.new(0, textBox.TextSize);
end
end)
scrollingFrame.CanvasSize = UDim2.fromOffset(textBox.TextBounds.X+1, textBox.TextBounds.Y+1)
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Basically this script is inside a scrollingframe with a textbox embedded inside it, the text is on the top left corner.
basically if I type to much to the point that the text goes off the screen, the canvasposition changes making the cursor and the text visible