SpatialButton constructor

SpatialButton({
  1. String name = 'button',
  2. required Transform3D? transform,
  3. required String label,
  4. required dynamic panel,
  5. Color labelColor = const Color(0xFFFFFFFF),
  6. Color idleColor = const Color(0xE0161B22),
  7. Color hoverColor = const Color(0xE01C2333),
  8. Color pressColor = const Color(0xE02E90FA),
  9. void onPress(
    1. Node
    )?,
})

Implementation

SpatialButton({
  super.name = 'button',
  required super.transform,
  required this.label,
  required panel,
  this.labelColor = const Color(0xFFFFFFFF),
  this.idleColor = const Color(0xE0161B22),
  this.hoverColor = const Color(0xE01C2333),
  this.pressColor = const Color(0xE02E90FA),
  void Function(Node)? onPress,
}) : _panel = panel {
  pointable = Pointable(
    node: this,
    onHoverEnter: (_) => _panel.backgroundColor = hoverColor,
    onHoverExit: (_) => _panel.backgroundColor = idleColor,
    onPress: (node, hit) {
      _panel.backgroundColor = pressColor;
      onPress?.call(node);
    },
    onRelease: (_) => _panel.backgroundColor = hoverColor,
  );

  _panel.backgroundColor = idleColor;
  _panel.onRenderContent = _renderLabel;
  addChild(_panel);
}