Raxol.Core.Renderer.View (Raxol v0.4.0)
View SourceMain facade module for the Raxol view system. Provides a unified interface for creating and managing views.
Summary
Types
Style options for a view. Typically a list of atoms, e.g., [:bold, :underline].
See Raxol.Core.Renderer.View.Types.style/0
for details.
Functions
Wraps a view with a border using a block style.
Wraps a view with a border using a bold style.
Creates a new border around a view.
Macro for creating a border around a view with a do-block for children, allowing style and other options.
Macro for creating a border around a view with a do-block for children.
Creates a new box view with padding and optional border.
Wraps a view with a border using a double line style.
Macro for creating a flex layout with a do-block for children.
Creates a new grid layout.
Macro for creating a grid layout with a do-block for children.
Applies layout to a view, calculating absolute positions for all elements. Delegates to Raxol.Renderer.Layout.apply_layout/2.
Creates a new view with the specified type and options.
Creates a new panel view (box with border and children).
Wraps a view with a border using a rounded style.
Creates a new row layout.
Macro for creating a row layout with a do-block for children.
Creates a new scrollable view.
Macro for creating a scrollable view with a do-block for children.
Wraps a view with a border using a simple style.
Creates a new text view.
Wraps a view with a border, optionally with a title and style.
Types
@type style() :: Raxol.Core.Renderer.View.Types.style()
Style options for a view. Typically a list of atoms, e.g., [:bold, :underline].
See Raxol.Core.Renderer.View.Types.style/0
for details.
Functions
Wraps a view with a border using a block style.
Parameters
view
- The view to wrap with a borderopts
- Options for the border:title
- Optional title to display in the border:align
- Title alignment (:left
,:center
,:right
)
Examples
View.block_border(view)
View.block_border(view, title: "Title")
Wraps a view with a border using a bold style.
Parameters
view
- The view to wrap with a borderopts
- Options for the border:title
- Optional title to display in the border:align
- Title alignment (:left
,:center
,:right
)
Examples
View.bold_border(view)
View.bold_border(view, title: "Title")
Creates a new border around a view.
Options
:style
- Border style:title
- Title for the border:fg
- Foreground color:bg
- Background color
Examples
View.border(view, style: :single)
View.border(view, title: "Title", style: :double)
Macro for creating a border around a view with a do-block for children, allowing style and other options.
Examples
View.border :single, size: {5,5}, title: "Box" do
View.text("Content")
end
Macro for creating a border around a view with a do-block for children.
Examples
View.border_wrap style: [:bold] do
[View.text("A"), View.text("B")]
end
View.border_wrap :single, style: [:bold] do
[View.text("A"), View.text("B")]
end
Creates a new box view with padding and optional border.
Parameters
opts
- Options for the box:padding
- Padding around the content (default: 0):border
- Border style (:none
,:single
,:double
,:rounded
,:bold
,:block
,:simple
)
Examples
View.box(padding: 2)
View.box(padding: 2, border: :single)
Wraps a view with a border using a double line style.
Parameters
view
- The view to wrap with a borderopts
- Options for the border:title
- Optional title to display in the border:align
- Title alignment (:left
,:center
,:right
)
Examples
View.double_border(view)
View.double_border(view, title: "Title")
Macro for creating a flex layout with a do-block for children.
Examples
View.flex direction: :row do
[View.text("A"), View.text("B")]
end
Creates a new grid layout.
Options
:columns
- Number of columns or list of column sizes:rows
- Number of rows or list of row sizes:gap
- Gap between grid items:align
- Alignment of items within cells:justify
- Justification of items within cells:children
- Child views
Examples
View.grid(columns: 3, rows: 2)
View.grid(columns: [1, 2, 1], rows: ["auto", "1fr"])
Macro for creating a grid layout with a do-block for children.
Examples
View.grid columns: 3 do
[View.text("A"), View.text("B"), View.text("C")]
end
Applies layout to a view, calculating absolute positions for all elements. Delegates to Raxol.Renderer.Layout.apply_layout/2.
Creates a new view with the specified type and options.
Options
:type
- The type of view to create:position
- Position of the view {x, y}:z_index
- Z-index for layering:size
- Size of the view {width, height}:style
- Style options for the view:fg
- Foreground color:bg
- Background color:border
- Border style:padding
- Padding around the view:margin
- Margin around the view:children
- Child views:content
- Content for the view
Examples
View.new(:box, size: {80, 24})
View.new(:text, content: "Hello", fg: :red)
Creates a new panel view (box with border and children).
Options
:children
- Child views:border
- Border style (default: :single):padding
- Padding inside the panel (default: 1):style
- Additional style options:title
- Optional title for the panel:fg
- Foreground color:bg
- Background color
Examples
View.panel(children: [View.text("Hello")])
View.panel(border: :double, title: "Panel")
NOTE: Only panel/1 (with a keyword list) is supported. Update any panel/2 usages to panel/1.
Wraps a view with a border using a rounded style.
Parameters
view
- The view to wrap with a borderopts
- Options for the border:title
- Optional title to display in the border:align
- Title alignment (:left
,:center
,:right
)
Examples
View.rounded_border(view)
View.rounded_border(view, title: "Title")
Creates a new row layout.
Options
:children
- Child views:align
- Alignment of children:justify
- Justification of children:gap
- Gap between children
Examples
View.row do
[text("Hello"), text("World")]
end
View.row align: :center, gap: 2 do
[text("A"), text("B")]
end
Macro for creating a row layout with a do-block for children.
Examples
View.row style: [:bold] do
[View.text("A"), View.text("B")]
end
Creates a new scrollable view.
Options
:viewport
- Viewport size {width, height}:offset
- Initial scroll offset {x, y}:scrollbars
- Whether to show scrollbars:fg
- Foreground color:bg
- Background color
Examples
View.scroll(view, viewport: {80, 24})
View.scroll(view, offset: {0, 10}, scrollbars: true)
Macro for creating a scrollable view with a do-block for children.
Examples
View.scroll_wrap viewport: {80, 24} do
[View.text("A"), View.text("B")]
end
Wraps a view with a border using a simple style.
Parameters
view
- The view to wrap with a borderopts
- Options for the border:title
- Optional title to display in the border:align
- Title alignment (:left
,:center
,:right
)
Examples
View.simple_border(view)
View.simple_border(view, title: "Title")
Creates a new text view.
Options
:content
- The text content:fg
- Foreground color:bg
- Background color:style
- Text style options:align
- Text alignment:wrap
- Text wrapping mode
Examples
View.text("Hello", fg: :red)
View.text("World", style: [bold: true, underline: true])
Wraps a view with a border, optionally with a title and style.
Parameters
view
- The view to wrap with a borderopts
- Options for the border:title
- Optional title to display in the border:style
- Border style (:single
,:double
,:rounded
,:bold
,:block
,:simple
):align
- Title alignment (:left
,:center
,:right
)
Examples
View.border_wrap(view, style: :single)
View.border_wrap(view, title: "Title", style: :double)