GUIAdapter

GUI/Adapters~GUIAdapter~ GUIAdapter

🔧 Primary GUI Extension Point

Translates user intents to domain operations (commands) or view operations. This is the main class developers will work with to customize GUI behavior, add new menu actions, or integrate custom interaction patterns.

Core Concepts

  • Event-driven execution (actions come from config-driven UI).
  • Command injection via GUICommandRegistry.
  • Undo/Redo via CommandHistory.

Extension Points for Developers:

  • Add new menu actions via action configuration
  • Register custom commands in GUICommandRegistry
  • Override or extend interaction handlers
  • Customize keyboard shortcuts and bindings

Responsibilities

  1. Event Translation: Convert UI events (mouse, keyboard, menu) to semantic actions
  2. Command Orchestration: Route actions to appropriate commands via GUICommandRegistry
  3. State Management: Manage interaction states (wire mode, element placement, selection)
  4. Canvas Coordination: Integrate with CircuitRenderer for visual updates
  5. History Management: Coordinate undo/redo operations via CommandHistory
  6. Property Panel Integration: Manage property panel interactions

Key Extension Patterns:

Constructor

new GUIAdapter()

Source:
Examples
// Adding custom action handlers
const guiAdapter = new GUIAdapter(canvas, circuitService, elementRegistry,
                                  rendererFactory, guiCommandRegistry);

// Custom actions are defined in menu.config.yaml and handled automatically
guiAdapter.handleAction('custom.myAction');

// Custom commands should be registered in GUICommandRegistry
guiCommandRegistry.register('myCommand', (services) =>
  new MyCustomCommand(services.circuitService, services.circuitRenderer));
// Extending keyboard shortcuts (done in configuration)
// In menu.config.yaml:
// shortcuts:
//   'Ctrl+Shift+N': 'insert.customElement'
//   'F1': 'help.show'

// Or programmatically (for dynamic bindings):
guiAdapter.bindShortcuts({
  'Ctrl+Alt+C': 'circuit.compile',
  'F2': 'element.properties'
});
// Listening to adapter state changes
guiAdapter.circuitService.on('update', (event) => {
  console.log('Circuit updated:', event.type);
  // Custom reaction to circuit changes
});

// Accessing current interaction state
const isWireMode = guiAdapter.wireDrawingMode;
const placingElement = guiAdapter.placingElement;
const selectedElements = guiAdapter.circuitRenderer.getSelectedElements();