import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'terminal_layout.dart'; /// Margin a maximised window keeps from the edges of the app. const double terminalFloatMargin = 8; /// [rect] moved and shrunk to fit inside [bounds], at least the minimum /// window size where the bounds allow it. Rect fitTerminalFloat(Rect rect, Size bounds) { final width = rect.width .clamp(terminalFloatMinSize.width, double.infinity) .clamp(0.0, bounds.width); final height = rect.height .clamp(terminalFloatMinSize.height, double.infinity) .clamp(0.0, bounds.height); final left = rect.left.clamp(0.0, bounds.width - width); final top = rect.top.clamp(0.0, bounds.height - height); return Rect.fromLTWH(left, top, width, height); } /// The window's card: a Material surface with elevation, or a Cupertino /// rounded box with a hairline and shadow. Widget terminalFloatChrome(BuildContext context, bool cupertino, Widget child) { if (!cupertino) { return Material( elevation: 8, clipBehavior: Clip.antiAlias, borderRadius: BorderRadius.circular(12), color: Theme.of(context).colorScheme.surfaceContainer, child: child, ); } return DecoratedBox( decoration: BoxDecoration( color: CupertinoColors.secondarySystemBackground.resolveFrom(context), borderRadius: BorderRadius.circular(12), border: Border.all(color: CupertinoColors.separator.resolveFrom(context)), boxShadow: const [BoxShadow(blurRadius: 16, color: Color(0x33000000))], ), child: ClipRRect( borderRadius: BorderRadius.circular(12), child: Material(type: MaterialType.transparency, child: child), ), ); }