Skip to content

Refactor volume knob interaction into explicit controller and normalize mouse behavior#17

Draft
Copilot wants to merge 7 commits into
masterfrom
copilot/remake-volume-knob-behavior
Draft

Refactor volume knob interaction into explicit controller and normalize mouse behavior#17
Copilot wants to merge 7 commits into
masterfrom
copilot/remake-volume-knob-behavior

Conversation

Copilot AI commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

The volume knob interaction was hard to reason about and felt inconsistent with mouse input. This change makes knob behavior explicit and predictable: click-to-set, drag-to-adjust, release-to-stop.

  • Interaction model (OOP)

    • Introduced VolumeKnobController (volume_knob.py) to own knob semantics:
      • hit-testing (contains, configurable hit_padding)
      • drag lifecycle (start_drag, drag, stop_drag)
      • angle/value mapping and clamping
      • sprite rotation mapping (sprite_rotation_degrees)
    • Moved knob math/state transitions out of the main event loop into named methods.
  • Main loop integration

    • Replaced ad-hoc knob handling in main.py with controller calls.
    • Volume now updates immediately on knob press (not only after motion), and continuously during drag.
    • Centralized mixer update via _apply_volume_from_knob() to avoid duplicated apply logic.
    • Drag updates now apply only when knob value actually changes.
  • UI/UX consistency

    • Preserved existing layout and element positions (no new overlapping UI).
    • Slightly expanded effective knob hit area for easier grabbing without changing rendered geometry.
  • Docs + focused coverage

    • Updated README usage text from drag-only to click-or-drag behavior.
    • Added focused unit tests for controller behavior (tests/test_volume_knob.py): hit area, immediate click update, drag gating, and rotation mapping.
# main.py (event handling)
if event.type == MOUSEBUTTONDOWN and event.button == 1:
    if volume_knob.start_drag(mouse_pos):
        _apply_volume_from_knob()

elif event.type == MOUSEMOTION:
    if volume_knob.drag(mouse_pos):
        _apply_volume_from_knob()

elif event.type == MOUSEBUTTONUP and event.button == 1:
    volume_knob.stop_drag()

Copilot AI linked an issue Apr 15, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix volume knob behavior for better user experience Refactor volume knob interaction into explicit controller and normalize mouse behavior Apr 15, 2026
Copilot finished work on behalf of JP1Q April 15, 2026 16:36
Copilot AI requested a review from JP1Q April 15, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Volume knob

2 participants