-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: platform window title bar button add
- Loading branch information
Showing
7 changed files
with
456 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:platform_ui/platform_ui.dart'; | ||
import 'package:fluent_ui/fluent_ui.dart' as FluentUI; | ||
import 'package:platform_ui/src/specific/linux_window_button.dart'; | ||
import 'package:platform_ui/src/specific/windows_title_bar_icons.dart'; | ||
import 'package:platform_ui/src/tools/gesture_builder.dart'; | ||
|
||
class PlatformWindowButtons extends StatelessWidget | ||
with PlatformMixin<Widget> | ||
implements PreferredSizeWidget { | ||
final VoidCallback onClose; | ||
final VoidCallback onMinimize; | ||
final VoidCallback onMaximize; | ||
final bool isMaximized; | ||
const PlatformWindowButtons({ | ||
Key? key, | ||
required this.onClose, | ||
required this.onMinimize, | ||
required this.onMaximize, | ||
required this.isMaximized, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
height: preferredSize.height, | ||
child: getPlatformType(context), | ||
); | ||
} | ||
|
||
@override | ||
Size get preferredSize => const Size(110, 30); | ||
|
||
@override | ||
Widget android(BuildContext context) { | ||
return linux(context); | ||
} | ||
|
||
@override | ||
Widget ios(BuildContext context) { | ||
return macos(context); | ||
} | ||
|
||
@override | ||
Widget linux(BuildContext context) { | ||
return Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
AdwWindowButton( | ||
buttonType: WindowButtonType.minimize, | ||
onPressed: onMinimize, | ||
), | ||
AdwWindowButton( | ||
buttonType: WindowButtonType.maximize, | ||
onPressed: onMaximize, | ||
), | ||
AdwWindowButton( | ||
buttonType: WindowButtonType.close, | ||
onPressed: onClose, | ||
), | ||
], | ||
); | ||
} | ||
|
||
@override | ||
Widget macos(BuildContext context) { | ||
final decoration = BoxDecoration( | ||
color: Colors.red[400], | ||
borderRadius: BorderRadius.circular(18), | ||
); | ||
return Row( | ||
mainAxisSize: MainAxisSize.min, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
GestureBuilder( | ||
builder: (context, states) { | ||
return Container( | ||
height: 18, | ||
width: 18, | ||
decoration: states.isPressing | ||
? decoration.copyWith( | ||
color: Colors.red[800], | ||
) | ||
: decoration, | ||
); | ||
}, | ||
), | ||
const SizedBox(width: 4), | ||
GestureBuilder(builder: (context, states) { | ||
return Container( | ||
height: 18, | ||
width: 18, | ||
decoration: decoration.copyWith( | ||
color: | ||
states.isPressing ? Colors.orange[400] : Colors.orange[200], | ||
), | ||
); | ||
}), | ||
const SizedBox(width: 4), | ||
GestureBuilder(builder: (context, states) { | ||
return Container( | ||
height: 18, | ||
width: 18, | ||
decoration: decoration.copyWith( | ||
color: states.isPressing ? Colors.green[800] : Colors.green[400], | ||
), | ||
); | ||
}), | ||
], | ||
); | ||
} | ||
|
||
@override | ||
Widget windows(BuildContext context) { | ||
var buttonStyle = FluentUI.ButtonStyle( | ||
backgroundColor: FluentUI.ButtonState.resolveWith( | ||
(states) { | ||
if (states.contains(FluentUI.ButtonStates.focused) || | ||
states.contains(FluentUI.ButtonStates.focused)) { | ||
return Colors.black26; | ||
} else if (states.contains(FluentUI.ButtonStates.hovering)) { | ||
return Colors.black12; | ||
} | ||
return Colors.transparent; | ||
}, | ||
), | ||
shape: FluentUI.ButtonState.all( | ||
RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(0), | ||
), | ||
), | ||
border: FluentUI.ButtonState.all(BorderSide.none), | ||
); | ||
return Row( | ||
mainAxisSize: MainAxisSize.min, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
FluentUI.Button( | ||
style: buttonStyle, | ||
onPressed: onMinimize, | ||
child: | ||
MinimizeIcon(color: PlatformTextTheme.of(context).body!.color!), | ||
), | ||
FluentUI.Button( | ||
style: buttonStyle, | ||
onPressed: onMaximize, | ||
child: isMaximized | ||
? RestoreIcon(color: PlatformTextTheme.of(context).body!.color!) | ||
: MaximizeIcon(color: PlatformTextTheme.of(context).body!.color!), | ||
), | ||
FluentUI.Button( | ||
style: buttonStyle.copyWith( | ||
backgroundColor: FluentUI.ButtonState.resolveWith( | ||
(states) { | ||
if (states.contains(FluentUI.ButtonStates.hovering)) { | ||
return Colors.red; | ||
} | ||
return Colors.transparent; | ||
}, | ||
), | ||
), | ||
onPressed: onMinimize, | ||
child: CloseIcon(color: PlatformTextTheme.of(context).body!.color!), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_svg/flutter_svg.dart'; | ||
import 'package:libadwaita/libadwaita.dart'; | ||
|
||
enum WindowButtonType { close, maximize, minimize } | ||
|
||
class AdwWindowButton extends StatelessWidget { | ||
const AdwWindowButton({ | ||
Key? key, | ||
required this.buttonType, | ||
required this.onPressed, | ||
}) : super(key: key); | ||
|
||
/// Executed when this button is pressed | ||
final VoidCallback? onPressed; | ||
|
||
/// The WindowButtonType for this window | ||
final WindowButtonType buttonType; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return onPressed != null | ||
? AdwButton.circular( | ||
size: 24, | ||
margin: const EdgeInsets.all(4), | ||
onPressed: onPressed, | ||
child: Center( | ||
child: SvgPicture.asset( | ||
'packages/libadwaita/assets/icons/${buttonType.name}.svg', | ||
width: 16, | ||
height: 16, | ||
color: context.textColor, | ||
), | ||
), | ||
) | ||
: const SizedBox(); | ||
} | ||
} |
Oops, something went wrong.