electrosim.ui.controls#

Functions

handle_events(pg, sim, input_state, ...)

Process pygame events to drive simulation state and UI interactions.

render_hover_tooltip(screen, font, sim, ...)

Render an informational tooltip with local E-field and nearest particle.

render_placement_preview(screen, ...)

Render a live preview for particle placement with initial velocity.

Classes

InputState([placing, place_start_px, ...])

UI state for placement, dragging and tooltips across frames.

class InputState(placing=False, place_start_px=(0, 0), place_current_px=(0, 0), placing_negative=False, placing_fixed=False, tooltip_enabled=True, overlay_enabled=True, mouse_pos_px=(0, 0), dragging_selected=False, drag_prev_fixed=False, drag_prev_velocity_mps=None)[source]#

Bases: object

UI state for placement, dragging and tooltips across frames.

Parameters:
  • placing (bool)

  • place_start_px (Tuple[int, int])

  • place_current_px (Tuple[int, int])

  • placing_negative (bool)

  • placing_fixed (bool)

  • tooltip_enabled (bool)

  • overlay_enabled (bool)

  • mouse_pos_px (Tuple[int, int])

  • dragging_selected (bool)

  • drag_prev_fixed (bool)

  • drag_prev_velocity_mps (Tuple[float, float] | None)

placing#

Whether a placement gesture is in progress.

Type:

bool

place_start_px, place_current_px

Drag start and current pixels during placement.

Type:

tuple[int,int]

placing_negative#

If True, next placed particle is negative.

Type:

bool

placing_fixed#

If True, next placed particle starts fixed.

Type:

bool

tooltip_enabled#

Show or hide hover tooltip.

Type:

bool

overlay_enabled#

Show or hide information overlay.

Type:

bool

mouse_pos_px#

Last mouse position.

Type:

tuple[int,int]

dragging_selected#

Whether a drag of the selected particle is active.

Type:

bool

drag_prev_fixed#

Stored fixed state before drag (restored on release).

Type:

bool

drag_prev_velocity_mps#

Stored velocity before drag (restored on release).

Type:

tuple[float,float] | None

placing: bool = False#
place_start_px: Tuple[int, int] = (0, 0)#
place_current_px: Tuple[int, int] = (0, 0)#
placing_negative: bool = False#
placing_fixed: bool = False#
tooltip_enabled: bool = True#
overlay_enabled: bool = True#
mouse_pos_px: Tuple[int, int] = (0, 0)#
dragging_selected: bool = False#
drag_prev_fixed: bool = False#
drag_prev_velocity_mps: Tuple[float, float] | None = None#
handle_events(pg, sim, input_state, pixels_per_meter)[source]#

Process pygame events to drive simulation state and UI interactions.

Parameters:
  • pg (pygame module) – Pygame module for quitting.

  • sim (Simulation) – Simulation instance to manipulate.

  • input_state (InputState) – Mutable UI state across frames.

  • pixels_per_meter (float) – Pixels-per-meter scale.

Return type:

None

render_placement_preview(screen, input_state, pixels_per_meter)[source]#

Render a live preview for particle placement with initial velocity.

Parameters:
  • screen (pygame.Surface) – Target surface.

  • input_state (InputState) – Current UI placement state.

  • pixels_per_meter (float) – Pixels-per-meter scale.

Return type:

None

render_hover_tooltip(screen, font, sim, input_state, pixels_per_meter)[source]#

Render an informational tooltip with local E-field and nearest particle.

Parameters:
  • screen (pygame.Surface) – Target surface.

  • font (pygame.font.Font) – Font used for text rendering.

  • sim (Simulation) – Simulation to query.

  • input_state (InputState) – Current UI state (mouse position and toggles).

  • pixels_per_meter (float) – Pixels-per-meter scale.

Return type:

None