Clipping And Scrolling (frames)
OSL provides a powerful frame system for clipping content and creating scrollable areas in your applications.
Basic Clipping
The frame
command lets you define a rectangular area that clips (masks) any content drawn inside it. Content outside the frame's boundaries will not be visible.
Syntax
The frame boundaries are defined by four coordinates:
left
: Left edge position (x-coordinate)top
: Top edge position (y-coordinate)right
: Right edge position (x-coordinate)bottom
: Bottom edge position (y-coordinate)
Example: Basic Clipping
Scrollable Frames
You can create scrollable areas in two ways:
Two-dimensional scrolling with content width and height
Vertical-only scrolling with just content height
Two-Dimensional Scrolling Syntax
Additional parameters:
[content_width, content_height]
: Dimensions of the scrollable content area"frame_id"
: Unique identifier for the scrollable frame
Vertical-Only Scrolling Syntax
Additional parameters:
content_height
: Total height of the scrollable content (integer)"frame_id"
: Unique identifier for the scrollable frame
Example: Two-Dimensional Scrolling
Example: Vertical-Only Scrolling
Important Notes
Frame Coordinates
Coordinates are relative to the center of the screen
Positive Y goes up, negative Y goes down
Frame size = (right - left) × (top - bottom)
Scrolling Behavior
Scrollbars appear automatically when content exceeds frame size
Scroll position is tracked via
scroll_x
andscroll_y
variablesContent coordinates are relative to scroll position
Best Practices
Use meaningful frame IDs for easier management
Consider padding inside frames for better appearance
Update content layout based on scroll position
Clean up or reset scroll position when needed
Common Use Cases
Long text documents
Image galleries
Lists and menus
Content that exceeds screen size
Last updated
Was this helpful?