layout.py

layout.py - UI Layout Managers for LunaEngine

ENGINE PATH:
lunaengine -> ui -> layout.py

DESCRIPTION:
This module provides layout management classes that automatically arrange
UI elements according to specified rules, simplifying the process of creating
structured and responsive user interfaces.

LIBRARIES USED:
- typing: For type hints and type annotations

MAIN CLASSES:

1. UILayout:
  - Base class for all layout managers
  - Provides common functionality for element management
  - Handles element addition and removal

2. VerticalLayout:
  - Arranges elements vertically with consistent spacing
  - Automatically positions elements from top to bottom

3. HorizontalLayout:
  - Arranges elements horizontally with consistent spacing
  - Automatically positions elements from left to right

4. GridLayout:
  - Arranges elements in a grid pattern with specified columns
  - Supports custom cell dimensions and spacing
  - Automatically wraps elements to new rows

5. JustifiedLayout:
  - Distributes elements with equal spacing
  - Supports both horizontal and vertical justification
  - Fills available space evenly

This module simplifies UI composition by providing automatic positioning
and alignment of elements, reducing manual coordinate calculations.

class AnimationTypes

Description

No documentation

Attributes
LINEAR: Any = 'LINEAR'
BOUNCE: Any = 'BOUNCE'
ELASTIC: Any = 'ELASTIC'
BACK: Any = 'BACK'
EASE_IN: Any = 'EASE_IN'
EASE_OUT: Any = 'EASE_OUT'
EASE_IN_OUT: Any = 'EASE_IN_OUT'
EASE: Any = 'EASE_IN_OUT'
Methods

No methods defined.

class UILayout

Description

Base class for UI layout managers.

Methods
def __init__(self: Any, x: int = 0, y: int = 0) -> Any
Initialize a layout manager.

Args:
   x (int): Starting X coordinate for the layout.
   y (int): Starting Y coordinate for the layout.
def add_element(self: Any, element: UIElement) -> Any
Add an element to the layout.

Args:
   element (UIElement): The UI element to add to the layout.
def remove_element(self: Any, element: UIElement) -> Any
Remove an element from the layout.

Args:
   element (UIElement): The UI element to remove from the layout.
def _update_layout(self: Any) -> Any
Update element positions based on layout rules.

class VerticalLayout

Description

Layout that arranges elements vertically.

Methods
def __init__(self: Any, x: int = 0, y: int = 0, spacing: int = 10) -> Any
Initialize a vertical layout.

Args:
   x (int): Starting X coordinate.
   y (int): Starting Y coordinate.
   spacing (int): Space between elements in pixels.
def _update_layout(self: Any) -> Any
Arrange elements vertically with spacing.

class HorizontalLayout

Description

Layout that arranges elements horizontally.

Methods
def __init__(self: Any, x: int = 0, y: int = 0, spacing: int = 10) -> Any
Initialize a horizontal layout.

Args:
   x (int): Starting X coordinate.
   y (int): Starting Y coordinate.
   spacing (int): Space between elements in pixels.
def _update_layout(self: Any) -> Any
Arrange elements horizontally with spacing.

class GridLayout

Description

Layout that arranges elements in a grid.

Methods
def __init__(self: Any, x: int = 0, y: int = 0, cols: int = 2, cell_width: int = 100, cell_height: int = 100, h_spacing: int = 5, v_spacing: int = 5) -> Any
Initialize a grid layout.

Args:
   x (int): Starting X coordinate.
   y (int): Starting Y coordinate.
   cols (int): Number of columns in the grid.
   cell_width (int): Width of each cell.
   cell_height (int): Height of each cell.
   h_spacing (int): Horizontal spacing between cells.
   v_spacing (int): Vertical spacing between cells.
def _update_layout(self: Any) -> Any
Arrange elements in a grid pattern.

class JustifiedLayout

Description

Layout that justifies elements with equal spacing.

Methods
def __init__(self: Any, x: int = 0, y: int = 0, justify_x: bool = True, justify_y: bool = False) -> Any
Initialize a justified layout.

Args:
   x (int): Starting X coordinate.
   y (int): Starting Y coordinate.
   justify_x (bool): Whether to justify horizontally.
   justify_y (bool): Whether to justify vertically.
def _update_layout(self: Any) -> Any
Arrange elements with justified spacing.

class Animation

Description

No documentation

Attributes
duration: float = None
start_time: float = None
end_time: float = None
animation_type: AnimationTypes = None
Methods

No methods defined.

Back to Ui Module