This module allows for manipulation of the layout tree.
Summary
Functions
Returns a Node struct, or {:error, :node_not_found} or {:error, :no_children}.
Takes in a layout and a pane_id to close. Returns a new layout with the pane with the specified pane_id removed from the tree.
Finds a pane with the specified pane_id in the tree. Returns a pane struct or {:error, :pane_not_found}
Returns {:ok, pane_id} with pane_id being the id of the pane in focus. Could also return nil if there are no panes.
Returns pane_id in focus or nil.
Queries whether a pane is in focus or not. Returns a boolean or {:error, :pane_not_found} if the pane_id doesn't exist
Takes an empty layout and a pane and returns the layout with the pane.
Creates a new empty layout
Creates a new Layout with a single pane
Returns a list of pane_ids that exist in the layout tree
Returns a Node struct, or {:error, :pane_not_found} or {:error, :no_parent}.
Takes in a layout, a pane ID and a new pane ID to split it with. Returns an updated layout with the specified pane split into a node with 2 panes.
Swaps the positions of panes. For now you can only swap panes on the same node.
Validates the layout based on specified invariants on nodes, panes and other crucial elements
Types
@type tree() :: Bsp.Pane.t() | Bsp.Node.t()
Functions
@spec children( %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}, String.t() ) :: {:ok, [Bsp.Pane.t()]} | {:error, :node_not_found} | {:error, :no_children}
Returns a Node struct, or {:error, :node_not_found} or {:error, :no_children}.
@spec close( %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}, Types.Id.t() ) :: {:ok, %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}} | {:error, :pane_not_found}
Takes in a layout and a pane_id to close. Returns a new layout with the pane with the specified pane_id removed from the tree.
@spec find(%Bsp.Layout{focused: term(), pane_ids: term(), root: term()}, Types.Id.t()) :: Bsp.Pane.t() | {:error, :pane_not_found}
Finds a pane with the specified pane_id in the tree. Returns a pane struct or {:error, :pane_not_found}
@spec focused(%Bsp.Layout{focused: term(), pane_ids: term(), root: term()}) :: {:ok, Types.Id.t()}
Returns {:ok, pane_id} with pane_id being the id of the pane in focus. Could also return nil if there are no panes.
@spec focused!(%Bsp.Layout{focused: term(), pane_ids: term(), root: term()}) :: Types.Id.t()
Returns pane_id in focus or nil.
@spec focused?( %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}, Types.Id.t() ) :: boolean()
Queries whether a pane is in focus or not. Returns a boolean or {:error, :pane_not_found} if the pane_id doesn't exist
@spec insert(t(), Bsp.Pane.t()) :: t() | {:error, :invalid_layout}
Takes an empty layout and a pane and returns the layout with the pane.
Examples
iex> Bsp.Layout.insert(%Bsp.Layout{root: nil, focused: nil, pane_ids: []}, %Bsp.Pane{id: "temp"})
%Bsp.Layout{root: %Bsp.Pane{id: "temp"}, focused: "temp", pane_ids: ["temp"]}
Creates a new empty layout
@spec new(Bsp.Pane.t()) :: %Bsp.Layout{ focused: term(), pane_ids: term(), root: term() }
Creates a new Layout with a single pane
@spec panes(%Bsp.Layout{focused: term(), pane_ids: term(), root: term()}) :: [ Types.Id.t() ]
Returns a list of pane_ids that exist in the layout tree
@spec parent( %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}, Types.Id.t() ) :: {:ok, Bsp.Node.t()} | {:error, :pane_not_found} | {:error, :no_parent}
Returns a Node struct, or {:error, :pane_not_found} or {:error, :no_parent}.
@spec split( %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}, Types.Id.t(), Types.Id.t() ) :: {:ok, %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}} | {:error, :pane_not_found} | {:error, :duplicate_pane_id}
Takes in a layout, a pane ID and a new pane ID to split it with. Returns an updated layout with the specified pane split into a node with 2 panes.
@spec swap( %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}, Types.Id.t(), Types.Id.t() ) :: {:ok, %Bsp.Layout{focused: term(), pane_ids: term(), root: term()}} | {:error, :pane_not_found} | {:error, :swap_failed}
Swaps the positions of panes. For now you can only swap panes on the same node.
@spec validate(%Bsp.Layout{focused: term(), pane_ids: term(), root: term()}) :: {:ok, :valid} | {:error, :invalid}
Validates the layout based on specified invariants on nodes, panes and other crucial elements