Skip to content

Commit

Permalink
chore: fix window resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jan 12, 2025
1 parent 3649b67 commit 5930c34
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 352 deletions.
13 changes: 0 additions & 13 deletions lib/collections/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 0 additions & 73 deletions lib/components/titlebar/mouse_state.dart

This file was deleted.

17 changes: 11 additions & 6 deletions lib/components/titlebar/titlebar.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
import 'package:shadcn_flutter/shadcn_flutter_extension.dart';
import 'package:spotube/components/button/back_button.dart';
import 'package:spotube/components/titlebar/titlebar_buttons.dart';
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
Expand Down Expand Up @@ -49,7 +50,7 @@ class TitleBar extends HookConsumerWidget implements PreferredSizeWidget {
this.height,
this.surfaceBlur,
this.surfaceOpacity,
this.useSafeArea = true,
this.useSafeArea = false,
});

void onDrag(WidgetRef ref) {
Expand All @@ -66,7 +67,7 @@ class TitleBar extends HookConsumerWidget implements PreferredSizeWidget {
final lastClicked = useRef<int>(DateTime.now().millisecondsSinceEpoch);

return SizedBox(
height: height ?? 56,
height: height ?? (48 * context.theme.scaling),
child: LayoutBuilder(
builder: (context, constraints) {
final hasFullscreen =
Expand Down Expand Up @@ -102,18 +103,22 @@ class TitleBar extends HookConsumerWidget implements PreferredSizeWidget {
: leading,
trailing: [
...trailing,
WindowTitleBarButtons(foregroundColor: foregroundColor),
Align(
alignment: Alignment.topRight,
child:
WindowTitleBarButtons(foregroundColor: foregroundColor),
),
],
title: title,
header: header,
subtitle: subtitle,
trailingExpanded: trailingExpanded,
alignment: alignment,
padding: padding,
padding: padding ?? EdgeInsets.zero,
backgroundColor: backgroundColor,
leadingGap: leadingGap,
trailingGap: trailingGap,
height: height,
height: height ?? (48 * context.theme.scaling),
surfaceBlur: surfaceBlur,
surfaceOpacity: surfaceOpacity,
useSafeArea: useSafeArea,
Expand All @@ -127,5 +132,5 @@ class TitleBar extends HookConsumerWidget implements PreferredSizeWidget {
}

@override
Size get preferredSize => Size.fromHeight(height ?? 56.0);
Size get preferredSize => Size.fromHeight(height ?? 48);
}
144 changes: 68 additions & 76 deletions lib/components/titlebar/titlebar_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shadcn_flutter/shadcn_flutter_extension.dart';
import 'package:spotube/components/hover_builder.dart';
import 'package:spotube/components/titlebar/titlebar.dart';
import 'package:spotube/components/titlebar/titlebar_icon_buttons.dart';
import 'package:spotube/components/titlebar/window_button.dart';

import 'package:spotube/hooks/configurators/use_window_listener.dart';
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
import 'package:spotube/utils/platform.dart';
import 'package:titlebar_buttons/titlebar_buttons.dart';
Expand All @@ -22,12 +24,20 @@ class WindowTitleBarButtons extends HookConsumerWidget {
final preferences = ref.watch(userPreferencesProvider);
final isMaximized = useState<bool?>(null);
const type = ThemeType.auto;
final scale = context.theme.scaling;

Future<void> onClose() async {
await windowManager.close();
}

useWindowListener(
onWindowMaximize: () {
isMaximized.value = true;
},
onWindowUnmaximize: () {
isMaximized.value = false;
},
);

useEffect(() {
if (kIsDesktop) {
windowManager.isMaximized().then((value) {
Expand All @@ -42,86 +52,68 @@ class WindowTitleBarButtons extends HookConsumerWidget {
}

if (kIsWindows) {
final theme = Theme.of(context);
final colors = WindowButtonColors(
normal: Colors.transparent,
iconNormal: foregroundColor ?? theme.colorScheme.onSurface,
mouseOver: theme.colorScheme.onSurface.withAlpha(25),
mouseDown: theme.colorScheme.onSurface.withAlpha(51),
iconMouseOver: theme.colorScheme.onSurface,
iconMouseDown: theme.colorScheme.onSurface,
);

final closeColors = WindowButtonColors(
normal: Colors.transparent,
iconNormal: foregroundColor ?? theme.colorScheme.onSurface,
mouseOver: Colors.red,
mouseDown: Colors.red[800]!,
iconMouseOver: Colors.white,
iconMouseDown: Colors.black,
);

return Transform(
transform: Matrix4.translationValues(18, -12, 0) * scale,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MinimizeWindowButton(
onPressed: windowManager.minimize,
colors: colors,
),
if (isMaximized.value != true)
MaximizeWindowButton(
colors: colors,
onPressed: () {
windowManager.maximize();
isMaximized.value = true;
},
)
else
RestoreWindowButton(
colors: colors,
onPressed: () {
windowManager.unmaximize();
isMaximized.value = false;
},
),
CloseWindowButton(
colors: closeColors,
onPressed: onClose,
),
],
),
);
}

return Transform(
transform: Matrix4.translationValues(18, -12, 0) * scale,
child: Row(
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DecoratedMinimizeButton(
type: type,
ShadcnWindowButton(
icon: MinimizeIcon(color: context.theme.colorScheme.foreground),
onPressed: windowManager.minimize,
),
DecoratedMaximizeButton(
type: type,
onPressed: () async {
if (await windowManager.isMaximized()) {
await windowManager.unmaximize();
isMaximized.value = false;
} else {
await windowManager.maximize();
if (isMaximized.value != true)
ShadcnWindowButton(
icon: MaximizeIcon(color: context.theme.colorScheme.foreground),
onPressed: () {
windowManager.maximize();
isMaximized.value = true;
}
},
),
DecoratedCloseButton(
type: type,
onPressed: onClose,
),
},
)
else
ShadcnWindowButton(
icon: RestoreIcon(color: context.theme.colorScheme.foreground),
onPressed: () {
windowManager.unmaximize();
isMaximized.value = false;
},
),
HoverBuilder(builder: (context, isHovered) {
return ShadcnWindowButton(
icon: CloseIcon(
color: isHovered
? Colors.white
: context.theme.colorScheme.foreground,
),
onPressed: onClose,
hoverBackgroundColor: const Color(0xFFD32F2F),
);
}),
],
),
);
}

return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DecoratedMinimizeButton(
type: type,
onPressed: windowManager.minimize,
),
DecoratedMaximizeButton(
type: type,
onPressed: () async {
if (await windowManager.isMaximized()) {
await windowManager.unmaximize();
isMaximized.value = false;
} else {
await windowManager.maximize();
isMaximized.value = true;
}
},
),
DecoratedCloseButton(
type: type,
onPressed: onClose,
),
],
);
}
}
Loading

0 comments on commit 5930c34

Please sign in to comment.