Raxol.UI.Layout.SplitPane.Resize (Raxol v2.6.0)

View Source

Helpers for interactive split pane resize in TEA applications.

Resize is handled at the app level via TEA update/2 -- the SplitPane element is stateless (takes ratio from app model). This module provides the math.

Summary

Functions

Checks if a mouse position hits a divider.

Computes divider positions for hit testing.

Functions

calculate_ratio(drag_pos, direction, origin, total_size, pane_count, min_size \\ 5)

Calculates a new ratio tuple from a drag position.

Parameters

  • drag_pos - Current mouse {x, y} position
  • direction - :horizontal or :vertical
  • origin - {x, y} of the split pane's top-left corner
  • total_size - Total width (horizontal) or height (vertical)
  • pane_count - Number of panes
  • min_size - Minimum pane size in characters

Returns a ratio tuple with integer parts proportional to the drag position.

check_divider_hit(mouse_pos, dividers, direction)

Checks if a mouse position hits a divider.

Returns {:hit, pane_index} if the position is on a divider, or :miss.

Parameters

  • mouse_pos - {x, y} mouse coordinates
  • dividers - List of divider rects from divider_positions/3
  • direction - :horizontal or :vertical

divider_positions(direction, ratio, space)

Computes divider positions for hit testing.

Returns a list of {x, y, width, height, pane_index} tuples.

Parameters

  • direction - :horizontal or :vertical
  • ratio - Ratio tuple
  • space - Available space map with :x, :y, :width, :height

handle_keyboard_resize(key_event, direction, current_ratio, step \\ 0.05)

Handles keyboard-based resize.

Returns {:ok, new_ratio} if the key event triggers a resize, or :ignore.

Parameters

  • key_event - A key event map with :key, :char, and :ctrl fields
  • direction - :horizontal or :vertical
  • current_ratio - Current ratio tuple
  • step - Adjustment step as float proportion (default 0.05)