Skip to content

Search documentation

Enter at least two characters.

    Split

    Legacy address for preview.2 documentation. Use the versioned page. The API is the same.

    Optional app library · SDK 0.1.0-preview.2.

    Track one primary-mouse divider drag. Your view supplies input positions and applies the returned ratio; the module does not create or own that view.

    From the extracted SDK folder, create a sibling app with ./lui.cmd new ../MyWorkbench --template workbench. Keep its Vendor files, lui.json, module lock and SDK pin together. See library setup.

    Import require("@LuiWorkbench/Split") after the project declares that library. An import copied into a basic starter is not enough.

    Replace Src/Main.luau in that prepared project with this complete file.

    local Window = Instance.new("Window", {Title = "Library example", Size = UDim2.fromOffset(640, 300)})
    local Status = Instance.new("TextLabel", {Parent = Window, Text = "Ready",
    Position = UDim2.fromOffset(16, 190), Size = UDim2.fromOffset(600, 72)})
    local Split = require("@LuiWorkbench/Split")
    local Drag = Split.New()
    local Ratio: number = 0.5
    local Width = 600
    local Grip = Instance.new("Frame", {Parent = Window, BackgroundColor3 = Color3.fromRGB(100, 120, 180),
    Position = UDim2.fromOffset(Ratio * (Width - 8), 0), Size = UDim2.fromOffset(8, 160)})
    local function Apply(Next: number?)
    if Next then Ratio = Next; Grip.Position = UDim2.fromOffset(Ratio * (Width - 8), 0) end
    Status.Text = "Divider ratio: " .. Ratio
    end
    Grip.InputBegan:Connect(function(Input)
    if Input.Device == "Mouse" then Drag:Begin(Input, Grip.AbsolutePosition.X + Input.Position.X, Width, Ratio) end
    end)
    Grip.InputChanged:Connect(function(Input)
    if Input.Device == "Mouse" then Apply(Drag:Move(Input, Grip.AbsolutePosition.X + Input.Position.X, Width)) end
    end)
    Grip.InputEnded:Connect(function(Input) Apply(Drag:Finish(Input)) end)
    Window.Destroying:Connect(function() Drag:Dispose() end)
    Window.Visible = true

    Expected result: Drag the thin divider with the primary mouse button. The example uses a fixed 600-unit viewport; a responsive view must cancel an active drag when that viewport changes.

    Split.New(): Gesture

    Workspace owns presentation IDs only. Add registers up to 32 unique UTF-8 IDs (128 bytes each) in Left or Right; default Left. Remove unregisters an ID and repairs active selection. Dock moves a known ID to a side and optional final 1-based position, default end. Activate selects the visible tab in its side. Snapshot returns a deeply frozen Version 1 layout. Restore validates the entire snapshot before mutation: exact known identity set, unique dense arrays, valid active tabs, finite Ratio in 0.1–0.9, no unknown fields or metatables. It returns false, InvalidLayout on incompatible data, preserving current presentation. It never opens documents from stored IDs.

    SetRatio stores presentation intent. Layout(Width) returns logical widths and whether to display two panes; at least 240 units per pane plus an 8-unit divider are required. With two populated groups below 488 units, it returns a single left-sized viewport. The view must show its selected tab there, including a tab from the Right group. A single populated group receives the full width. Encode/Decode use the bounded LUIW1 length-prefixed UTF-8 format, maximum 8192 bytes, with no native paths, document contents or executable objects. Truncated, extra, unknown-version and incompatible identity data are refused atomically.

    Split.New() provides Begin(Input, WindowX, Width, Ratio), Move(Input, WindowX, Width), Finish(Input), Cancel() and Dispose(). Begin accepts one primary mouse contact at a time. Use window-relative logical X for both Begin and Move. Movement returns a clamped ratio; matching primary release commits it. Native cancellation, invalid coordinates or a resized viewport returns the original ratio and retires the gesture. Other contacts/buttons cannot finish it. Call Cancel on other presentation changes and apply its returned original ratio. Dispose retires without invoking callbacks. The view owns the existing input signal connections; no native capture API is introduced.

    Exported type declarations — advanced reference

    These types describe returned models/controllers and their options. They are not additional classes to create.

    export type Gesture = {
    Begin: (Self: Gesture, Input: InputEvent, X: number, Width: number, Ratio: number) -> boolean,
    Move: (Self: Gesture, Input: InputEvent, X: number, Width: number) -> number?,
    Finish: (Self: Gesture, Input: InputEvent) -> number?,
    Cancel: (Self: Gesture) -> number?,
    Dispose: (Self: Gesture) -> (),
    }

    The library source is useful when extending the framework or understanding cleanup. Private support modules such as Scope/State are implementation details, not additional supported app APIs.