Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- **BREAKING** feat: `TreeViewItem.children` is now unmodifiable. Use `TreeViewController` methods (`addItem()`, `addItems()`, `removeItem()`, `moveItem()`) to modify tree structure.
- feat: `TitleBar` now supports double-click callback to maximize or restore the window ([#1298](https://github.com/bdlukaa/fluent_ui/issues/1298))
- fix: Correctly apply `TitleBar`'s `isBackButtonEnabled` ([#1298](https://github.com/bdlukaa/fluent_ui/issues/1298))
- fix: `TitleBar` height no longer shrinks when the window is resized to a smaller width ([#1340](https://github.com/bdlukaa/fluent_ui/issues/1340))

## 4.14.0

Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
appTheme.mode = ThemeMode.light;
}
},
child: const Icon(WindowsIcons.lightbulb),
child: const Icon(WindowsIcons.lightbulb, size: 16),
),
),
captionControls: const WindowButtons(),
Expand Down
47 changes: 30 additions & 17 deletions lib/src/controls/navigation/navigation_view/title_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TitleBar extends StatelessWidget {
this.subtitle,
this.content,
this.endHeader,
this.height,
this.captionControls,
this.onDragStarted,
this.onDragEnded,
Expand Down Expand Up @@ -84,8 +85,20 @@ class TitleBar extends StatelessWidget {
/// Usually an [AutoSuggestBox] widget.
final Widget? content;

/// The right header widget.
///
/// Usually an [Icon] widget.
final Widget? endHeader;

/// The height of the title bar.
///
/// If not provided, the height is calculated based on the [content].
///
/// See also:
///
/// * [calculateHeight], which calculates the height based on the content.
final double? height;

/// The controls of the window, if any.
final Widget? captionControls;

Expand All @@ -104,6 +117,15 @@ class TitleBar extends StatelessWidget {
/// The callback that is called when the title bar is double-tapped.
final VoidCallback? onDoubleTap;

static double calculateHeight(Widget? titleBar) {
if (titleBar == null) return 0;
if (titleBar is TitleBar) {
if (titleBar.height != null) return titleBar.height!;
if (titleBar.content != null) return 48;
}
return 32;
}

@override
Widget build(BuildContext context) {
assert(debugCheckHasFluentTheme(context));
Expand All @@ -121,11 +143,10 @@ class TitleBar extends StatelessWidget {
onPanUpdate: (_) => onDragUpdated?.call(),
onDoubleTap: () => onDoubleTap?.call(),
child: ConstrainedBox(
constraints: BoxConstraints(
constraints: BoxConstraints.tightFor(
// according to documentation, increase the size of the title bar if
// there is content
minHeight: content != null ? 48 : 32,
maxHeight: 48,
height: TitleBar.calculateHeight(this),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
Expand Down Expand Up @@ -331,13 +352,9 @@ class _RenderTitleSubtitleOverflow extends RenderBox
var height = 0.0;
var child = firstChild;
while (child != null) {
final childParentData =
child.parentData! as _TitleSubtitleOverflowParentData;
if (!childParentData.isHidden) {
height = height > child.getMinIntrinsicHeight(width)
? height
: child.getMinIntrinsicHeight(width);
}
height = height > child.getMinIntrinsicHeight(width)
? height
: child.getMinIntrinsicHeight(width);
child = childAfter(child);
}
return height;
Expand All @@ -348,13 +365,9 @@ class _RenderTitleSubtitleOverflow extends RenderBox
var height = 0.0;
var child = firstChild;
while (child != null) {
final childParentData =
child.parentData! as _TitleSubtitleOverflowParentData;
if (!childParentData.isHidden) {
height = height > child.getMaxIntrinsicHeight(width)
? height
: child.getMaxIntrinsicHeight(width);
}
height = height > child.getMaxIntrinsicHeight(width)
? height
: child.getMaxIntrinsicHeight(width);
child = childAfter(child);
}
return height;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/controls/navigation/navigation_view/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ class NavigationView extends StatefulWidget {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('titleBar', titleBar))
..add(DiagnosticsProperty('pane', pane))
..add(
DiagnosticsProperty(
Expand Down Expand Up @@ -825,7 +824,7 @@ class NavigationViewState extends State<NavigationView> {
children: [
Padding(
padding: EdgeInsetsDirectional.only(
top: 38,
top: TitleBar.calculateHeight(widget.titleBar),
start: pane.size?.compactWidth ?? kCompactNavigationPaneWidth,
),
child: content,
Expand Down
Loading
Loading