Keep even 16px window margins for top bars on wide windows
On a wide window (both sides at least 600 logical px) every SegmentedBar keeps the floating tab bar's 16px from the top and the sides, in every pane and page. A root WindowMargins scope adds the extra 8px to the top media padding, so Cupertino's fixed reserved bar height, list clearances, pinned headers and measured overlays all move together; the bar and the TopGlassStrip read the 16px side inset from the same scope, and sticky section chevrons keep 16px from the trailing edge. Phones keep 8/12.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import '../ui/adaptive/platform.dart';
|
||||
import '../ui/adaptive/window_margins.dart';
|
||||
import '../ui/theme/app_font_controller.dart';
|
||||
import '../ui/theme/app_theme.dart';
|
||||
import '../ui/scale/ui_scale.dart';
|
||||
@@ -102,6 +103,7 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
bool get _platformIsCupertino => prefersCupertino();
|
||||
|
||||
static Widget _scaled(BuildContext context, Widget? child) =>
|
||||
UiScaleHost(child: child ?? const SizedBox.shrink());
|
||||
static Widget _scaled(BuildContext context, Widget? child) => UiScaleHost(
|
||||
child: WindowMargins(child: child ?? const SizedBox.shrink()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import '../core/servers/chat/chat_server_pool.dart';
|
||||
import '../ui/adaptive/platform.dart';
|
||||
import '../ui/adaptive/window_margins.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -370,16 +371,18 @@ class _PipelinesRootState extends State<PipelinesRoot> {
|
||||
builder: (context, _) => _cupertino
|
||||
? CupertinoApp(
|
||||
title: 'Pipelines',
|
||||
builder: (context, child) =>
|
||||
UiScaleHost(child: child ?? const SizedBox.shrink()),
|
||||
builder: (context, child) => UiScaleHost(
|
||||
child: WindowMargins(child: child ?? const SizedBox.shrink()),
|
||||
),
|
||||
theme: appCupertinoThemeWith(fontFamily: fonts.family),
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: flow,
|
||||
)
|
||||
: MaterialApp(
|
||||
title: 'Pipelines',
|
||||
builder: (context, child) =>
|
||||
UiScaleHost(child: child ?? const SizedBox.shrink()),
|
||||
builder: (context, child) => UiScaleHost(
|
||||
child: WindowMargins(child: child ?? const SizedBox.shrink()),
|
||||
),
|
||||
theme: appLightTheme(fontFamily: fonts.family),
|
||||
darkTheme: appDarkTheme(fontFamily: fonts.family),
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'segmented_bar_overflow.dart';
|
||||
import 'segmented_bar_motion.dart';
|
||||
import 'segmented_bar_pieces.dart';
|
||||
import 'window_controls.dart';
|
||||
import 'window_margins.dart';
|
||||
|
||||
export 'segmented_bar_overflow.dart'
|
||||
show
|
||||
@@ -43,8 +44,9 @@ export 'segmented_bar_pieces.dart' show SegmentedBackButton, SegmentedPill;
|
||||
/// [CupertinoPageScaffold.navigationBar], which inset the content by the
|
||||
/// bar's height through [MediaQuery.paddingOf], so a page keeps its
|
||||
/// scaffold's structure; [SegmentedBarOverlay] does the same anywhere else.
|
||||
/// It handles the top safe area itself, and keeps its pieces clear of the
|
||||
/// system's window controls ([WindowControlsClearance]).
|
||||
/// It handles the top safe area itself, keeps its pieces clear of the
|
||||
/// system's window controls ([WindowControlsClearance]), and on a wide window
|
||||
/// keeps the wider [WindowMargins] from the top and the sides.
|
||||
class SegmentedBar extends StatefulWidget
|
||||
implements ObstructingPreferredSizeWidget {
|
||||
const SegmentedBar({
|
||||
@@ -142,7 +144,7 @@ class SegmentedBar extends StatefulWidget
|
||||
/// top edge (a page's own tint, such as a chat's colour). It takes no taps.
|
||||
final Widget? backdrop;
|
||||
|
||||
static const double _topPadding = 8;
|
||||
static const double _topPadding = WindowMargins.narrowTop;
|
||||
|
||||
/// The share of the bar the title always keeps beside the actions.
|
||||
static const double minTitleShare = 0.25;
|
||||
@@ -530,6 +532,9 @@ class _SegmentedBarState extends State<SegmentedBar> {
|
||||
);
|
||||
final background = widget._background(context);
|
||||
final inset = MediaQuery.paddingOf(context).top;
|
||||
// A wide window's extra top margin arrives in the top padding (see
|
||||
// WindowMargins), so the reserved height stays the bar's own.
|
||||
final side = WindowMargins.sideOf(context);
|
||||
return Stack(
|
||||
children: [
|
||||
// The scrim: the page's background, opaque at the edge and fading out
|
||||
@@ -570,9 +575,9 @@ class _SegmentedBarState extends State<SegmentedBar> {
|
||||
bottom: false,
|
||||
child: Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(
|
||||
12,
|
||||
side,
|
||||
SegmentedBar._topPadding,
|
||||
12,
|
||||
side,
|
||||
bottomPadding,
|
||||
),
|
||||
// In a window, iPadOS draws its window controls over the top
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'glass_pill.dart';
|
||||
import 'window_margins.dart';
|
||||
|
||||
/// The corner radius of a [TopGlassStrip].
|
||||
const double kTopGlassStripRadius = 22;
|
||||
@@ -11,8 +12,8 @@ const double kTopGlassStripRadius = 22;
|
||||
///
|
||||
/// Float it with `FloatingBarOverlay(edge: FloatingBarEdge.top)`: the strip
|
||||
/// sits below the bar and the content's top padding grows by the strip's
|
||||
/// height, so at rest nothing is hidden. It starts at the bar's 12px side
|
||||
/// inset, is as wide as its content up to [maxWidth] (and the area), and is
|
||||
/// height, so at rest nothing is hidden. It starts at the bar's side inset
|
||||
/// ([WindowMargins.sideOf]), is as wide as its content up to [maxWidth] (and the area), and is
|
||||
/// only as tall as its content; the space beside it passes taps through.
|
||||
class TopGlassStrip extends StatelessWidget {
|
||||
const TopGlassStrip({
|
||||
@@ -35,8 +36,14 @@ class TopGlassStrip extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final insets = MediaQuery.paddingOf(context);
|
||||
final side = WindowMargins.sideOf(context);
|
||||
return Padding(
|
||||
padding: EdgeInsets.fromLTRB(12 + insets.left, 0, 12 + insets.right, 8),
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
side + insets.left,
|
||||
0,
|
||||
side + insets.right,
|
||||
8,
|
||||
),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
heightFactor: 1,
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'floating_bar_layout.dart';
|
||||
|
||||
/// The margins the app's chrome keeps from the window's edges.
|
||||
///
|
||||
/// On a phone the top bar's pieces sit 8 px below the safe area and 12 px
|
||||
/// from the sides. On a wide window (a desktop, a tablet, an unfolded fold:
|
||||
/// both sides at least [kFloatingBarWideWidth]) every piece keeps the
|
||||
/// floating tab bar's [kFloatingBarMargin] from the top and the sides
|
||||
/// instead, in every pane and page.
|
||||
///
|
||||
/// The extra top margin is added to the subtree's [MediaQuery] padding, like
|
||||
/// a taller safe area: a scaffold reserves a bar's fixed preferred height
|
||||
/// plus that padding, so every bar, and everything that clears or aligns
|
||||
/// with a bar (list clearances, pinned headers, overlays measuring the bar),
|
||||
/// moves down together without knowing about the margin.
|
||||
///
|
||||
/// Place it once at the app's root, below the interface-scale host, so the
|
||||
/// width is the scaled one and pushed pages, dialogs and sheets share it.
|
||||
class WindowMargins extends StatelessWidget {
|
||||
const WindowMargins({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
/// A bar piece's distance from the top (below the safe area) and from the
|
||||
/// sides on a phone.
|
||||
static const double narrowTop = 8;
|
||||
static const double narrowSide = 12;
|
||||
|
||||
/// The same distances on a wide window.
|
||||
static const double wideMargin = kFloatingBarMargin;
|
||||
|
||||
/// What the wide window adds to the top padding: the bar's own top inset
|
||||
/// stays [narrowTop].
|
||||
static const double wideExtraTop = wideMargin - narrowTop;
|
||||
|
||||
/// Whether [size] is a wide window.
|
||||
static bool isWide(Size size) => size.shortestSide >= kFloatingBarWideWidth;
|
||||
|
||||
/// Whether the margins above [context] are the wide ones; false without a
|
||||
/// [WindowMargins] (a bar in isolation keeps the phone's).
|
||||
static bool wideOf(BuildContext context) =>
|
||||
context.dependOnInheritedWidgetOfExactType<_WindowMarginsScope>()?.wide ??
|
||||
false;
|
||||
|
||||
/// A top bar piece's distance from the sides at [context].
|
||||
static double sideOf(BuildContext context) =>
|
||||
wideOf(context) ? wideMargin : narrowSide;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final media = MediaQuery.of(context);
|
||||
final wide = isWide(media.size);
|
||||
final extra = wide ? wideExtraTop : 0.0;
|
||||
// The same tree either way, so crossing the width never remounts the app.
|
||||
return _WindowMarginsScope(
|
||||
wide: wide,
|
||||
child: MediaQuery(
|
||||
data: media.copyWith(
|
||||
padding: media.padding.copyWith(top: media.padding.top + extra),
|
||||
viewPadding: media.viewPadding.copyWith(
|
||||
top: media.viewPadding.top + extra,
|
||||
),
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _WindowMarginsScope extends InheritedWidget {
|
||||
const _WindowMarginsScope({required this.wide, required super.child});
|
||||
|
||||
final bool wide;
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(_WindowMarginsScope oldWidget) =>
|
||||
wide != oldWidget.wide;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../adaptive/host.dart';
|
||||
import '../adaptive/window_margins.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../motion/motion.dart';
|
||||
import 'section_heading.dart';
|
||||
@@ -197,8 +198,13 @@ class StickySectionTitle extends StatelessWidget {
|
||||
color: muted,
|
||||
),
|
||||
);
|
||||
// On a wide window the chevron keeps the title's 16 px from the edge, in
|
||||
// line with the top bar's trailing piece; a phone keeps it closer.
|
||||
final row = Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 16, end: 8),
|
||||
padding: EdgeInsetsDirectional.only(
|
||||
start: 16,
|
||||
end: WindowMargins.wideOf(context) ? 16 : 8,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
|
||||
Reference in New Issue
Block a user