import 'dart:math' as math; import 'package:flutter/material.dart'; import 'package:pyramid/core/appearance.dart'; import 'package:pyramid/core/theme.dart'; import 'package:pyramid/widgets/spring_press.dart'; // Simple hover-aware widget for desktop hover effects class HoverRegion extends StatefulWidget { final Widget Function(BuildContext context, bool hovered) builder; final MouseCursor cursor; const HoverRegion({ super.key, required this.builder, this.cursor = SystemMouseCursors.click, }); @override State createState() => _HoverRegionState(); } class _HoverRegionState extends State { bool _hovered = false; @override Widget build(BuildContext context) { return MouseRegion( cursor: widget.cursor, onEnter: (_) => setState(() => _hovered = true), onExit: (_) => setState(() => _hovered = false), child: widget.builder(context, _hovered), ); } } // Icon button styled to match Pyramid's .icon-btn. // Handy-Layout (Bernds Feedback 2026-10-07: Symbole zu klein): Symbol 22 px // statt 16, Fläche mind. 40 px, Tippfläche mind. 44 px. Farben folgen dem // gewählten Farbmodus, Druck federt (SpringPress). class PyrIconBtn extends StatefulWidget { final Widget icon; final VoidCallback? onPressed; final String? tooltip; final bool active; final Color? activeColor; final Color? dangerColor; final double size; /// Symbolgröße; ohne Angabe 16 (PC) bzw. 22 (Handy-Layout). final double? iconSize; const PyrIconBtn({ super.key, required this.icon, this.onPressed, this.tooltip, this.active = false, this.activeColor, this.dangerColor, this.size = 32, this.iconSize, }); @override State createState() => _PyrIconBtnState(); } class _PyrIconBtnState extends State { bool _hovered = false; @override Widget build(BuildContext context) { final pt = PyramidTheme.of(context); final mobile = isMobileLayout(MediaQuery.sizeOf(context)); final color = widget.active ? (widget.activeColor ?? pt.accent) : _hovered ? pt.fg : pt.fgMuted; final boxSize = mobile ? math.max(widget.size, 40.0) : widget.size; final touchSize = mobile ? math.max(boxSize, 44.0) : boxSize; final iconSize = widget.iconSize ?? (mobile ? 22.0 : 16.0); final btn = MouseRegion( cursor: SystemMouseCursors.click, onEnter: (_) => setState(() => _hovered = true), onExit: (_) => setState(() => _hovered = false), child: GestureDetector( onTap: widget.onPressed, child: SpringPress( enabled: widget.onPressed != null, child: SizedBox( width: touchSize, height: touchSize, child: Center( child: AnimatedContainer( duration: const Duration(milliseconds: 150), curve: Curves.easeOutCubic, width: boxSize, height: boxSize, decoration: BoxDecoration( color: _hovered ? pt.bgHover : Colors.transparent, borderRadius: BorderRadius.circular(mobile ? boxSize / 2 : 7), ), child: Center( child: IconTheme( data: IconThemeData(color: color, size: iconSize), child: widget.icon, ), ), ), ), ), ), ), ); if (widget.tooltip != null) { return Tooltip( message: widget.tooltip!, waitDuration: const Duration(milliseconds: 500), child: btn, ); } return btn; } }