Raxol.Core.Events.Event (Raxol v0.4.0)

View Source

Defines the structure for events in the Raxol system, providing a standardized format for key presses, mouse actions, and other UI events that components need to process.

Events are structs with a :type and :data field, where :type indicates the event category (e.g., :key, :mouse, :resize) and :data contains the event-specific details.

Summary

Functions

Creates a simple custom event.

Creates a custom event.

Creates a focus event.

Creates a simple key event with pressed state and no modifiers.

Creates a keyboard event.

Creates a simple mouse event with pressed state and no modifiers.

Creates a mouse event with drag state.

Creates a new event with the given type and data. Optionally accepts a timestamp (defaults to now).

Creates a paste event.

Creates a selection event.

Creates a simple timer event.

Creates a timer event.

Creates a simple window event.

Creates a window event.

Types

cursor_event()

@type cursor_event() :: %{
  visible: boolean(),
  style: :block | :line | :underscore,
  blink: boolean(),
  position: {non_neg_integer(), non_neg_integer()}
}

event_data()

@type event_data() :: any()

event_type()

@type event_type() :: atom()

focus_event()

@type focus_event() :: %{target: focus_target(), focused: boolean()}

focus_target()

@type focus_target() :: :component | :window | :application

key()

@type key() :: atom() | String.t()

key_event()

@type key_event() :: %{key: key(), state: key_state(), modifiers: modifiers()}

key_state()

@type key_state() :: :pressed | :released | :repeat

modifiers()

@type modifiers() :: [atom()]

mouse_button()

@type mouse_button() :: :left | :right | :middle

mouse_event()

@type mouse_event() :: %{
  button: mouse_button() | nil,
  state: mouse_state() | nil,
  position: mouse_position(),
  modifiers: modifiers()
}

mouse_position()

@type mouse_position() :: {non_neg_integer(), non_neg_integer()}

mouse_state()

@type mouse_state() :: :pressed | :released | :double_click

paste_event()

@type paste_event() :: %{
  text: String.t(),
  position: {non_neg_integer(), non_neg_integer()}
}

scroll_direction()

@type scroll_direction() :: :vertical | :horizontal

scroll_event()

@type scroll_event() :: %{
  direction: scroll_direction(),
  delta: integer(),
  position: {non_neg_integer(), non_neg_integer()}
}

selection_event()

@type selection_event() :: %{
  start_pos: {non_neg_integer(), non_neg_integer()},
  end_pos: {non_neg_integer(), non_neg_integer()},
  text: String.t()
}

t()

@type t() :: %Raxol.Core.Events.Event{
  data: event_data(),
  timestamp: DateTime.t(),
  type: event_type()
}

window_event()

@type window_event() :: %{
  width: non_neg_integer(),
  height: non_neg_integer(),
  action: :resize | :focus | :blur
}

Functions

cursor_event(visible, style, blink, position)

Creates a cursor event.

Parameters

  • visible - Whether cursor is visible
  • style - Cursor style
  • blink - Whether cursor should blink
  • position - Cursor position

custom(data)

Creates a simple custom event.

custom_event(data)

Creates a custom event.

Parameters

  • data - Custom event data

focus_event(target, focused)

Creates a focus event.

Parameters

  • target - What received/lost focus
  • focused - Whether focus was gained (true) or lost (false)

key(key)

Creates a simple key event with pressed state and no modifiers.

key_event(key, state, modifiers \\ [])

Creates a keyboard event.

Parameters

  • key - The key that was pressed/released (e.g. :enter, :backspace, "a")
  • state - The state of the key (:pressed, :released, :repeat)
  • modifiers - List of active modifiers (e.g. [:shift, :ctrl])

mouse(button, position)

Creates a simple mouse event with pressed state and no modifiers.

mouse(button, position, list)

Creates a mouse event with drag state.

mouse_event(button, position, state \\ :pressed, modifiers \\ [])

Creates a mouse event.

Parameters

  • button - The mouse button (:left, :right, :middle)
  • position - The mouse position as {x, y}
  • state - The button state (:pressed, :released, :double_click)
  • modifiers - List of active modifiers (e.g. [:shift, :ctrl])

new(type, data, timestamp \\ DateTime.utc_now())

Creates a new event with the given type and data. Optionally accepts a timestamp (defaults to now).

paste_event(text, position)

Creates a paste event.

Parameters

  • text - Pasted text
  • position - Paste position

scroll_event(direction, delta, position)

Creates a scroll event.

Parameters

  • direction - Scroll direction
  • delta - Amount scrolled (positive or negative)
  • position - Current scroll position

selection_event(start_pos, end_pos, text)

Creates a selection event.

Parameters

  • start_pos - Selection start position
  • end_pos - Selection end position
  • text - Selected text

timer(data)

Creates a simple timer event.

timer_event(data)

Creates a timer event.

Parameters

  • data - Timer-specific data

window(width, height, action)

Creates a simple window event.

window_event(width, height, action)

Creates a window event.

Parameters

  • width - The window width
  • height - The window height
  • action - The window action (:resize, :focus, :blur)