mirror of
https://github.com/MeowLynxSea/vissh.git
synced 2025-07-09 11:34:35 +00:00
完成窗口管理部分
This commit is contained in:
parent
9480f7cc7b
commit
04b1944f84
269
lib/main.dart
269
lib/main.dart
@ -1,4 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'widgets/draggable_window.dart';
|
||||
import 'models/window_data.dart';
|
||||
import 'widgets/taskbar.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@ -7,116 +10,214 @@ void main() {
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
// This is the theme of your application.
|
||||
//
|
||||
// TRY THIS: Try running your application with "flutter run". You'll see
|
||||
// the application has a purple toolbar. Then, without quitting the app,
|
||||
// try changing the seedColor in the colorScheme below to Colors.green
|
||||
// and then invoke "hot reload" (save your changes or press the "hot
|
||||
// reload" button in a Flutter-supported IDE, or press "r" if you used
|
||||
// the command line to start the app).
|
||||
//
|
||||
// Notice that the counter didn't reset back to zero; the application
|
||||
// state is not lost during the reload. To reset the state, use hot
|
||||
// restart instead.
|
||||
//
|
||||
// This works for code too, not just values: Most code changes can be
|
||||
// tested with just a hot reload.
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: const WindowManager(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
class WindowManager extends StatefulWidget {
|
||||
const WindowManager({super.key});
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
State<WindowManager> createState() => _WindowManagerState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
class _WindowManagerState extends State<WindowManager> {
|
||||
final List<WindowData> _windows = [];
|
||||
int _nextWindowId = 0;
|
||||
|
||||
void _incrementCounter() {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_addWindow(
|
||||
'File Explorer',
|
||||
const Offset(100, 100),
|
||||
const Center(
|
||||
child: Text('View your files...', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
Icons.folder_open,
|
||||
);
|
||||
_addWindow(
|
||||
'Terminal',
|
||||
const Offset(150, 150),
|
||||
const Center(
|
||||
child: Text('Run your commands...', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
Icons.web,
|
||||
);
|
||||
}
|
||||
|
||||
void _addWindow(String title, Offset position, Widget child, IconData icon) {
|
||||
setState(() {
|
||||
// This call to setState tells the Flutter framework that something has
|
||||
// changed in this State, which causes it to rerun the build method below
|
||||
// so that the display can reflect the updated values. If we changed
|
||||
// _counter without calling setState(), then the build method would not be
|
||||
// called again, and so nothing would appear to happen.
|
||||
_counter++;
|
||||
final id = 'window_${_nextWindowId++}';
|
||||
_windows.add(
|
||||
WindowData(
|
||||
id: id,
|
||||
title: title,
|
||||
position: position,
|
||||
size: const Size(400, 300),
|
||||
child: child,
|
||||
icon: icon,
|
||||
),
|
||||
);
|
||||
_bringToFront(id);
|
||||
});
|
||||
}
|
||||
|
||||
void _bringToFront(String id) {
|
||||
final windowIndex = _windows.indexWhere((w) => w.id == id);
|
||||
if (windowIndex != -1) {
|
||||
final window = _windows[windowIndex];
|
||||
if(window.isMinimized) {
|
||||
window.isMinimized = false;
|
||||
}
|
||||
|
||||
if (windowIndex != _windows.length - 1) {
|
||||
final window = _windows.removeAt(windowIndex);
|
||||
_windows.add(window);
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
void _minimizeWindow(String id) {
|
||||
setState(() {
|
||||
final windowIndex = _windows.indexWhere((w) => w.id == id);
|
||||
if (windowIndex != -1) {
|
||||
_windows[windowIndex].isMinimized = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _onWindowIconTap(String id) {
|
||||
final windowIndex = _windows.indexWhere((w) => w.id == id);
|
||||
if (windowIndex == -1) return;
|
||||
|
||||
final window = _windows[windowIndex];
|
||||
final topMostIndex = _windows.lastIndexWhere((w) => !w.isMinimized);
|
||||
|
||||
setState(() {
|
||||
if (window.isMinimized) {
|
||||
window.isMinimized = false;
|
||||
_bringToFront(id);
|
||||
} else {
|
||||
if (topMostIndex != -1 && _windows[topMostIndex].id == id) {
|
||||
_minimizeWindow(id);
|
||||
} else {
|
||||
_bringToFront(id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _removeWindow(String id) {
|
||||
setState(() {
|
||||
_windows.removeWhere((w) => w.id == id);
|
||||
});
|
||||
}
|
||||
|
||||
void _updateWindowPosition(String id, Offset position) {
|
||||
final windowIndex = _windows.indexWhere((w) => w.id == id);
|
||||
if (windowIndex != -1) {
|
||||
setState(() {
|
||||
_windows[windowIndex].position = position;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _updateWindowSize(String id, Size size) {
|
||||
final windowIndex = _windows.indexWhere((w) => w.id == id);
|
||||
if (windowIndex != -1) {
|
||||
setState(() {
|
||||
_windows[windowIndex].size = size;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _updateWindowMaximizeState(String id, bool isMaximized) {
|
||||
final windowIndex = _windows.indexWhere((w) => w.id == id);
|
||||
if (windowIndex != -1) {
|
||||
setState(() {
|
||||
_windows[windowIndex].isMaximized = isMaximized;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// This method is rerun every time setState is called, for instance as done
|
||||
// by the _incrementCounter method above.
|
||||
//
|
||||
// The Flutter framework has been optimized to make rerunning build methods
|
||||
// fast, so that you can just rebuild anything that needs updating rather
|
||||
// than having to individually change instances of widgets.
|
||||
final sortedWindowsForTaskbar = List<WindowData>.from(_windows);
|
||||
sortedWindowsForTaskbar.sort((a, b) {
|
||||
final aId = int.tryParse(a.id.split('_').last) ?? 0;
|
||||
final bId = int.tryParse(b.id.split('_').last) ?? 0;
|
||||
return aId.compareTo(bId);
|
||||
});
|
||||
|
||||
final topMostIndex = _windows.lastIndexWhere((w) => !w.isMinimized);
|
||||
final activeWindowId = topMostIndex != -1 ? _windows[topMostIndex].id : null;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
// TRY THIS: Try changing the color here to a specific color (to
|
||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
||||
// change color while the other colors stay the same.
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: Text(widget.title),
|
||||
backgroundColor: Colors.blueGrey[900],
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: NetworkImage('https://www.meowdream.cn/background.jpg'),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
body: Center(
|
||||
// Center is a layout widget. It takes a single child and positions it
|
||||
// in the middle of the parent.
|
||||
child: Column(
|
||||
// Column is also a layout widget. It takes a list of children and
|
||||
// arranges them vertically. By default, it sizes itself to fit its
|
||||
// children horizontally, and tries to be as tall as its parent.
|
||||
//
|
||||
// Column has various properties to control how it sizes itself and
|
||||
// how it positions its children. Here we use mainAxisAlignment to
|
||||
// center the children vertically; the main axis here is the vertical
|
||||
// axis because Columns are vertical (the cross axis would be
|
||||
// horizontal).
|
||||
//
|
||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
||||
// action in the IDE, or press "p" in the console), to see the
|
||||
// wireframe for each widget.
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text('You have pushed the button this many times:'),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Stack(
|
||||
children: _windows.where((w) => !w.isMinimized).map((data) {
|
||||
final bool isActive = data.id == activeWindowId;
|
||||
return DraggableWindow(
|
||||
key: ValueKey(data.id),
|
||||
id: data.id,
|
||||
initialPosition: data.position,
|
||||
initialSize: data.size,
|
||||
title: data.title,
|
||||
icon: data.icon,
|
||||
isActive: isActive,
|
||||
isMaximized: data.isMaximized,
|
||||
onBringToFront: _bringToFront,
|
||||
onMinimize: _minimizeWindow,
|
||||
onClose: _removeWindow,
|
||||
onMove: _updateWindowPosition,
|
||||
onResize: _updateWindowSize,
|
||||
onMaximizeChanged: _updateWindowMaximizeState,
|
||||
child: data.child,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
Taskbar(
|
||||
windows: sortedWindowsForTaskbar,
|
||||
activeWindowId: activeWindowId,
|
||||
onWindowIconTap: _onWindowIconTap,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
floatingActionButton: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
FloatingActionButton(
|
||||
onPressed: () => _addWindow(
|
||||
'New Window',
|
||||
const Offset(200, 200),
|
||||
const Center(child: Text('This is the new window content area', style: TextStyle(color: Colors.white))),
|
||||
Icons.add_circle_outline,
|
||||
),
|
||||
tooltip: 'Add New Window',
|
||||
child: const Icon(Icons.add),
|
||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
23
lib/models/window_data.dart
Normal file
23
lib/models/window_data.dart
Normal file
@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class WindowData {
|
||||
final String id;
|
||||
final String title;
|
||||
final Widget child;
|
||||
final IconData icon;
|
||||
Offset position;
|
||||
Size size;
|
||||
bool isMinimized;
|
||||
bool isMaximized;
|
||||
|
||||
WindowData({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.child,
|
||||
required this.icon,
|
||||
required this.position,
|
||||
required this.size,
|
||||
this.isMinimized = false,
|
||||
this.isMaximized = false,
|
||||
});
|
||||
}
|
576
lib/widgets/draggable_window.dart
Normal file
576
lib/widgets/draggable_window.dart
Normal file
@ -0,0 +1,576 @@
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const double _kTitleBarHeight = 24.0;
|
||||
const double _kResizeHandleSize = 8.0;
|
||||
const double _kMinWindowWidth = 200.0;
|
||||
const double _kMinWindowHeight = 150.0;
|
||||
|
||||
class DraggableWindow extends StatefulWidget {
|
||||
final String id;
|
||||
final Offset initialPosition;
|
||||
final Size initialSize;
|
||||
final String title;
|
||||
final Widget child;
|
||||
final IconData icon;
|
||||
final bool isActive;
|
||||
final bool isMaximized;
|
||||
final Function(String, bool) onMaximizeChanged;
|
||||
final Function(String) onBringToFront;
|
||||
final Function(String) onClose;
|
||||
final Function(String) onMinimize;
|
||||
final Function(String, Offset) onMove;
|
||||
final Function(String, Size) onResize;
|
||||
|
||||
const DraggableWindow({
|
||||
super.key,
|
||||
required this.id,
|
||||
required this.initialPosition,
|
||||
required this.initialSize,
|
||||
required this.title,
|
||||
required this.child,
|
||||
required this.icon,
|
||||
required this.isActive,
|
||||
required this.onBringToFront,
|
||||
required this.onClose,
|
||||
required this.onMinimize,
|
||||
required this.onMove,
|
||||
required this.onResize,
|
||||
required this.isMaximized,
|
||||
required this.onMaximizeChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
State<DraggableWindow> createState() => _DraggableWindowState();
|
||||
}
|
||||
|
||||
class _DraggableWindowState extends State<DraggableWindow> {
|
||||
late double _top;
|
||||
late double _left;
|
||||
late double _width;
|
||||
late double _height;
|
||||
|
||||
bool _isMaximized = false;
|
||||
late double _preMaximizedTop;
|
||||
late double _preMaximizedLeft;
|
||||
late double _preMaximizedWidth;
|
||||
late double _preMaximizedHeight;
|
||||
|
||||
late double _preDragTop;
|
||||
late double _preDragLeft;
|
||||
|
||||
bool _isClosing = false;
|
||||
bool _isOpening = true;
|
||||
|
||||
bool _showMaximizePreview = false;
|
||||
Duration _animationDuration = Duration.zero;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_top = widget.initialPosition.dy;
|
||||
_left = widget.initialPosition.dx;
|
||||
_width = widget.initialSize.width;
|
||||
_height = widget.initialSize.height;
|
||||
|
||||
_isMaximized = widget.isMaximized;
|
||||
|
||||
if (_isMaximized) {
|
||||
_preMaximizedTop = _top;
|
||||
_preMaximizedLeft = _left;
|
||||
_preMaximizedWidth = _width;
|
||||
_preMaximizedHeight = _height;
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
final screenSize = MediaQuery.of(context).size;
|
||||
setState(() {
|
||||
_animationDuration = Duration.zero;
|
||||
_top = 0;
|
||||
_left = 0;
|
||||
_width = screenSize.width;
|
||||
_height = screenSize.height - 48.0;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_preDragTop = _top;
|
||||
_preDragLeft = _left;
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isOpening = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant DraggableWindow oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.initialPosition != oldWidget.initialPosition) {
|
||||
_top = widget.initialPosition.dy;
|
||||
_left = widget.initialPosition.dx;
|
||||
}
|
||||
if (widget.initialSize != oldWidget.initialSize) {
|
||||
_width = widget.initialSize.width;
|
||||
_height = widget.initialSize.height;
|
||||
}
|
||||
}
|
||||
|
||||
void _animateAndMinimize() {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isClosing = true;
|
||||
});
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 100), () {
|
||||
widget.onMinimize(widget.id);
|
||||
});
|
||||
}
|
||||
|
||||
void _toggleMaximize() {
|
||||
setState(() {
|
||||
_animationDuration = const Duration(milliseconds: 100);
|
||||
if (_isMaximized) {
|
||||
_top = _preMaximizedTop;
|
||||
_left = _preMaximizedLeft;
|
||||
_width = _preMaximizedWidth;
|
||||
_height = _preMaximizedHeight;
|
||||
_isMaximized = false;
|
||||
widget.onMove(widget.id, Offset(_left, _top));
|
||||
widget.onResize(widget.id, Size(_width, _height));
|
||||
} else {
|
||||
_preMaximizedTop = _top;
|
||||
_preMaximizedLeft = _left;
|
||||
_preMaximizedWidth = _width;
|
||||
_preMaximizedHeight = _height;
|
||||
|
||||
final screenSize = MediaQuery.of(context).size;
|
||||
_top = 0;
|
||||
_left = 0;
|
||||
_width = screenSize.width;
|
||||
_height = screenSize.height - 40;
|
||||
_isMaximized = true;
|
||||
}
|
||||
});
|
||||
widget.onMaximizeChanged(widget.id, _isMaximized);
|
||||
widget.onBringToFront(widget.id);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final borderRadius = _isMaximized ? BorderRadius.zero : BorderRadius.circular(8.0);
|
||||
|
||||
const animationDuration = Duration(milliseconds: 100);
|
||||
const animationCurve = Curves.easeOut;
|
||||
|
||||
return AnimatedOpacity(
|
||||
duration: animationDuration,
|
||||
curve: animationCurve,
|
||||
opacity: (_isClosing || _isOpening) ? 0.0 : 1.0,
|
||||
child: AnimatedContainer(
|
||||
duration: animationDuration,
|
||||
curve: animationCurve,
|
||||
transform: Matrix4.identity()..scale((_isClosing || _isOpening) ? 0.85 : 1.0),
|
||||
transformAlignment: Alignment.center,
|
||||
child: Stack(
|
||||
children: [
|
||||
if (_showMaximizePreview && !_isMaximized)
|
||||
Positioned.fill(
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
opacity: _showMaximizePreview ? 1.0 : 0.0,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.1),
|
||||
border: Border.all(color: Colors.white.withValues(alpha: 0.4), width: 1.0),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
AnimatedPositioned(
|
||||
duration: _animationDuration,
|
||||
curve: Curves.easeInOut,
|
||||
top: _top,
|
||||
left: _left,
|
||||
width: _width,
|
||||
height: _height,
|
||||
child: GestureDetector(
|
||||
onPanDown: (details) => widget.onBringToFront(widget.id),
|
||||
child: Stack(
|
||||
children: [
|
||||
AnimatedContainer(
|
||||
duration: _animationDuration,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: borderRadius,
|
||||
boxShadow: _isMaximized ? [] : [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: widget.isActive ? 0.4 : 0.2),
|
||||
blurRadius: 20,
|
||||
spreadRadius: 5,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: borderRadius,
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 20.0, sigmaY: 20.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.75),
|
||||
borderRadius: borderRadius,
|
||||
border: _isMaximized ? null : Border.all(color: Colors.white.withValues(alpha: 0.2)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTitleBar(),
|
||||
Expanded(child: widget.child),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!_isMaximized) ..._buildResizeHandles(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTitleBar() {
|
||||
final titleBarColor = widget.isActive
|
||||
? Colors.white.withValues(alpha: 0.2)
|
||||
: Colors.white.withValues(alpha: 0.05);
|
||||
|
||||
return GestureDetector(
|
||||
onDoubleTap: _toggleMaximize,
|
||||
child: AnimatedContainer(
|
||||
duration: _animationDuration,
|
||||
height: _kTitleBarHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: titleBarColor,
|
||||
borderRadius: _isMaximized
|
||||
? BorderRadius.zero
|
||||
: const BorderRadius.only(
|
||||
topLeft: Radius.circular(8.0),
|
||||
topRight: Radius.circular(8.0),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: Tooltip(
|
||||
message: '',
|
||||
child: Icon(
|
||||
widget.icon,
|
||||
color: Colors.white.withValues(alpha: 0.8),
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onPanStart: (details) {
|
||||
widget.onBringToFront(widget.id);
|
||||
if (_isMaximized) {
|
||||
final mouseX = details.globalPosition.dx;
|
||||
setState(() {
|
||||
_isMaximized = false;
|
||||
_animationDuration = Duration.zero;
|
||||
_width = _preMaximizedWidth;
|
||||
_height = _preMaximizedHeight;
|
||||
_left = mouseX - (_width / 2);
|
||||
_top = details.globalPosition.dy - (_kTitleBarHeight / 2);
|
||||
});
|
||||
widget.onMaximizeChanged(widget.id, false);
|
||||
} else {
|
||||
_preDragTop = _top;
|
||||
_preDragLeft = _left;
|
||||
}
|
||||
},
|
||||
onPanUpdate: (details) {
|
||||
if (_isMaximized) return;
|
||||
setState(() {
|
||||
_animationDuration = Duration.zero;
|
||||
_left += details.delta.dx;
|
||||
_top += details.delta.dy;
|
||||
|
||||
if (details.globalPosition.dy < 5) {
|
||||
if (!_showMaximizePreview) {
|
||||
setState(() => _showMaximizePreview = true);
|
||||
}
|
||||
} else {
|
||||
if (_showMaximizePreview) {
|
||||
setState(() => _showMaximizePreview = false);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
onPanEnd: (details) {
|
||||
if (!_isMaximized) {
|
||||
widget.onMove(widget.id, Offset(_left, _top));
|
||||
}
|
||||
|
||||
if (_showMaximizePreview && !_isMaximized) {
|
||||
setState(() {
|
||||
_preMaximizedTop = _preDragTop;
|
||||
_preMaximizedLeft = _preDragLeft;
|
||||
_preMaximizedWidth = _width;
|
||||
_preMaximizedHeight = _height;
|
||||
|
||||
final screenSize = MediaQuery.of(context).size;
|
||||
_top = 0;
|
||||
_left = 0;
|
||||
_width = screenSize.width;
|
||||
_height = screenSize.height - 48.0;
|
||||
_isMaximized = true;
|
||||
_animationDuration = const Duration(milliseconds: 100);
|
||||
});
|
||||
widget.onMaximizeChanged(widget.id, true);
|
||||
widget.onBringToFront(widget.id);
|
||||
widget.onMove(widget.id, Offset(_left, _top));
|
||||
widget.onResize(widget.id, Size(_width, _height));
|
||||
}
|
||||
|
||||
if (_showMaximizePreview) {
|
||||
setState(() {
|
||||
_showMaximizePreview = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
widget.title,
|
||||
style: const TextStyle(
|
||||
color: Colors.white, fontWeight: FontWeight.w400, fontSize: 12),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildControlButton(Icons.minimize, _animateAndMinimize, Colors.black12),
|
||||
_buildControlButton(
|
||||
_isMaximized ? Icons.filter_none : Icons.check_box_outline_blank,
|
||||
_toggleMaximize,
|
||||
Colors.black12
|
||||
),
|
||||
_buildControlButton(Icons.close, () => widget.onClose(widget.id), Colors.redAccent, isLast: true,),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildControlButton(IconData icon, VoidCallback onPressed, Color hoverColor, {bool isLast = false}) {
|
||||
final BorderRadius borderRadius = isLast
|
||||
? const BorderRadius.only(
|
||||
topRight: Radius.circular(8.0),
|
||||
)
|
||||
: BorderRadius.zero;
|
||||
|
||||
return SizedBox(
|
||||
width: 40,
|
||||
height: _kTitleBarHeight,
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
borderRadius: borderRadius,
|
||||
child: InkWell(
|
||||
hoverColor: hoverColor,
|
||||
onTap: onPressed,
|
||||
customBorder: RoundedRectangleBorder(
|
||||
borderRadius: borderRadius,
|
||||
),
|
||||
child: Icon(icon, color: Colors.white, size: 12),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildResizeHandles() {
|
||||
void handleResizeEnd() {
|
||||
widget.onResize(widget.id, Size(_width, _height));
|
||||
}
|
||||
|
||||
void handleMoveEnd() {
|
||||
widget.onMove(widget.id, Offset(_left, _top));
|
||||
}
|
||||
|
||||
return [
|
||||
// Right-Bottom
|
||||
Positioned(
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
width: _kResizeHandleSize,
|
||||
height: _kResizeHandleSize,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeDownRight,
|
||||
child: GestureDetector(
|
||||
onPanStart: (d) { widget.onBringToFront(widget.id); _animationDuration = Duration.zero; },
|
||||
onPanUpdate: (details) {
|
||||
setState(() {
|
||||
_width = (_width + details.delta.dx).clamp(_kMinWindowWidth, double.infinity);
|
||||
_height = (_height + details.delta.dy).clamp(_kMinWindowHeight, double.infinity);
|
||||
});
|
||||
},
|
||||
onPanEnd: (d) => handleResizeEnd(),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Right
|
||||
Positioned(
|
||||
right: 0,
|
||||
top: _kTitleBarHeight,
|
||||
bottom: _kResizeHandleSize,
|
||||
width: _kResizeHandleSize,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeRight,
|
||||
child: GestureDetector(
|
||||
onPanStart: (d) { widget.onBringToFront(widget.id); _animationDuration = Duration.zero; },
|
||||
onPanUpdate: (details) {
|
||||
setState(() {
|
||||
_width = (_width + details.delta.dx).clamp(_kMinWindowWidth, double.infinity);
|
||||
});
|
||||
},
|
||||
onPanEnd: (d) => handleResizeEnd(),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Bottom
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: _kResizeHandleSize,
|
||||
right: _kResizeHandleSize,
|
||||
height: _kResizeHandleSize,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeDown,
|
||||
child: GestureDetector(
|
||||
onPanStart: (d) { widget.onBringToFront(widget.id); _animationDuration = Duration.zero; },
|
||||
onPanUpdate: (details) {
|
||||
setState(() {
|
||||
_height = (_height + details.delta.dy).clamp(_kMinWindowHeight, double.infinity);
|
||||
});
|
||||
},
|
||||
onPanEnd: (d) => handleResizeEnd(),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Top
|
||||
Positioned(
|
||||
top: 0,
|
||||
left: _kResizeHandleSize,
|
||||
right: _kResizeHandleSize,
|
||||
height: _kResizeHandleSize,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeUp,
|
||||
child: GestureDetector(
|
||||
onPanStart: (d) { widget.onBringToFront(widget.id); _animationDuration = Duration.zero; },
|
||||
onPanUpdate: (details) {
|
||||
setState(() {
|
||||
final newHeight = (_height - details.delta.dy).clamp(_kMinWindowHeight, double.infinity);
|
||||
_top += _height - newHeight;
|
||||
_height = newHeight;
|
||||
});
|
||||
},
|
||||
onPanEnd: (d) { handleResizeEnd(); handleMoveEnd(); },
|
||||
),
|
||||
),
|
||||
),
|
||||
// Left-Bottom
|
||||
Positioned(
|
||||
left: 0,
|
||||
bottom: 0,
|
||||
width: _kResizeHandleSize,
|
||||
height: _kResizeHandleSize,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeDownLeft,
|
||||
child: GestureDetector(
|
||||
onPanStart: (d) { widget.onBringToFront(widget.id); _animationDuration = Duration.zero; },
|
||||
onPanUpdate: (details) {
|
||||
setState(() {
|
||||
final newWidth = (_width - details.delta.dx).clamp(_kMinWindowWidth, double.infinity);
|
||||
_left += _width - newWidth;
|
||||
_width = newWidth;
|
||||
_height = (_height + details.delta.dy).clamp(_kMinWindowHeight, double.infinity);
|
||||
});
|
||||
},
|
||||
onPanEnd: (d) { handleResizeEnd(); handleMoveEnd(); },
|
||||
),
|
||||
),
|
||||
),
|
||||
// Left
|
||||
Positioned(
|
||||
left: 0,
|
||||
top: _kTitleBarHeight,
|
||||
bottom: _kResizeHandleSize,
|
||||
width: _kResizeHandleSize,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeLeft,
|
||||
child: GestureDetector(
|
||||
onPanStart: (d) { widget.onBringToFront(widget.id); _animationDuration = Duration.zero; },
|
||||
onPanUpdate: (details) {
|
||||
setState(() {
|
||||
final newWidth = (_width - details.delta.dx).clamp(_kMinWindowWidth, double.infinity);
|
||||
_left += _width - newWidth;
|
||||
_width = newWidth;
|
||||
});
|
||||
},
|
||||
onPanEnd: (d) { handleResizeEnd(); handleMoveEnd(); },
|
||||
),
|
||||
),
|
||||
),
|
||||
// Left-Top
|
||||
Positioned(
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: _kResizeHandleSize,
|
||||
height: _kResizeHandleSize,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeUpLeft,
|
||||
child: GestureDetector(
|
||||
onPanStart: (d) { widget.onBringToFront(widget.id); _animationDuration = Duration.zero; },
|
||||
onPanUpdate: (details) {
|
||||
setState(() {
|
||||
final newWidth = (_width - details.delta.dx).clamp(_kMinWindowWidth, double.infinity);
|
||||
final newHeight = (_height - details.delta.dy).clamp(_kMinWindowHeight, double.infinity);
|
||||
_left += _width - newWidth;
|
||||
_top += _height - newHeight;
|
||||
_width = newWidth;
|
||||
_height = newHeight;
|
||||
});
|
||||
},
|
||||
onPanEnd: (d) { handleResizeEnd(); handleMoveEnd(); },
|
||||
),
|
||||
),
|
||||
),
|
||||
// Right-Top
|
||||
Positioned(
|
||||
right: 0,
|
||||
top: 0,
|
||||
width: _kResizeHandleSize,
|
||||
height: _kResizeHandleSize,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeUpRight,
|
||||
child: GestureDetector(
|
||||
onPanStart: (d) { widget.onBringToFront(widget.id); _animationDuration = Duration.zero; },
|
||||
onPanUpdate: (details) {
|
||||
setState(() {
|
||||
final newHeight = (_height - details.delta.dy).clamp(_kMinWindowHeight, double.infinity);
|
||||
_top += _height - newHeight;
|
||||
_width = (_width + details.delta.dx).clamp(_kMinWindowWidth, double.infinity);
|
||||
_height = newHeight;
|
||||
});
|
||||
},
|
||||
onPanEnd: (d) { handleResizeEnd(); handleMoveEnd(); },
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
91
lib/widgets/taskbar.dart
Normal file
91
lib/widgets/taskbar.dart
Normal file
@ -0,0 +1,91 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/window_data.dart';
|
||||
|
||||
class Taskbar extends StatefulWidget {
|
||||
final List<WindowData> windows;
|
||||
final String? activeWindowId;
|
||||
final Function(String) onWindowIconTap;
|
||||
final double height;
|
||||
|
||||
const Taskbar({
|
||||
super.key,
|
||||
required this.windows,
|
||||
required this.onWindowIconTap,
|
||||
this.activeWindowId,
|
||||
this.height = 48.0,
|
||||
});
|
||||
|
||||
@override
|
||||
State<Taskbar> createState() => _TaskbarState();
|
||||
}
|
||||
|
||||
class _TaskbarState extends State<Taskbar> {
|
||||
late Timer _timer;
|
||||
String _currentTime = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_updateTime();
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) => _updateTime());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _updateTime() {
|
||||
if (!mounted) return;
|
||||
final now = DateTime.now();
|
||||
final hour = now.hour.toString().padLeft(2, '0');
|
||||
final minute = now.minute.toString().padLeft(2, '0');
|
||||
setState(() {
|
||||
_currentTime = '$hour:$minute';
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: widget.height,
|
||||
color: Colors.black.withValues(alpha: 0.8),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: widget.windows.map((window) {
|
||||
final isActive = widget.activeWindowId == window.id && !window.isMinimized;
|
||||
return InkWell(
|
||||
onTap: () => widget.onWindowIconTap(window.id),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
|
||||
decoration: BoxDecoration(
|
||||
color: isActive ? Colors.white.withValues(alpha: 0.08) : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(4.0),
|
||||
),
|
||||
child: Tooltip(
|
||||
message: window.title,
|
||||
child: Icon(window.icon, color: window.isMinimized ? Colors.white.withAlpha(150) : Colors.white.withAlpha(220), size: 24),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Text(
|
||||
_currentTime,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
69
pubspec.yaml
69
pubspec.yaml
@ -1,89 +1,22 @@
|
||||
name: vissh
|
||||
description: "A new Flutter project."
|
||||
# The following line prevents the package from being accidentally published to
|
||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
publish_to: 'none'
|
||||
|
||||
# The following defines the version and build number for your application.
|
||||
# A version number is three numbers separated by dots, like 1.2.43
|
||||
# followed by an optional build number separated by a +.
|
||||
# Both the version and the builder number may be overridden in flutter
|
||||
# build by specifying --build-name and --build-number, respectively.
|
||||
# In Android, build-name is used as versionName while build-number used as versionCode.
|
||||
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
|
||||
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
|
||||
# Read more about iOS versioning at
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.8.1
|
||||
|
||||
# Dependencies specify other packages that your package needs in order to work.
|
||||
# To automatically upgrade your package dependencies to the latest versions
|
||||
# consider running `flutter pub upgrade --major-versions`. Alternatively,
|
||||
# dependencies can be manually updated by changing the version numbers below to
|
||||
# the latest version available on pub.dev. To see which dependencies have newer
|
||||
# versions available, run `flutter pub outdated`.
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.8
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
# The "flutter_lints" package below contains a set of recommended lints to
|
||||
# encourage good coding practices. The lint set provided by the package is
|
||||
# activated in the `analysis_options.yaml` file located at the root of your
|
||||
# package. See that file for information about deactivating specific lint
|
||||
# rules and activating additional ones.
|
||||
flutter_lints: ^5.0.0
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
# The following section is specific to Flutter packages.
|
||||
flutter:
|
||||
|
||||
# The following line ensures that the Material Icons font is
|
||||
# included with your application, so that you can use the icons in
|
||||
# the material Icons class.
|
||||
uses-material-design: true
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/to/resolution-aware-images
|
||||
|
||||
# For details regarding adding assets from package dependencies, see
|
||||
# https://flutter.dev/to/asset-from-package
|
||||
|
||||
# To add custom fonts to your application, add a fonts section here,
|
||||
# in this "flutter" section. Each entry in this list should have a
|
||||
# "family" key with the font family name, and a "fonts" key with a
|
||||
# list giving the asset and other descriptors for the font. For
|
||||
# example:
|
||||
# fonts:
|
||||
# - family: Schyler
|
||||
# fonts:
|
||||
# - asset: fonts/Schyler-Regular.ttf
|
||||
# - asset: fonts/Schyler-Italic.ttf
|
||||
# style: italic
|
||||
# - family: Trajan Pro
|
||||
# fonts:
|
||||
# - asset: fonts/TrajanPro.ttf
|
||||
# - asset: fonts/TrajanPro_Bold.ttf
|
||||
# weight: 700
|
||||
#
|
||||
# For details regarding fonts from package dependencies,
|
||||
# see https://flutter.dev/to/font-from-package
|
||||
|
@ -27,7 +27,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
|
||||
FlutterWindow window(project);
|
||||
Win32Window::Point origin(10, 10);
|
||||
Win32Window::Size size(1280, 720);
|
||||
if (!window.Create(L"vissh", origin, size)) {
|
||||
if (!window.Create(L"Visual SSH", origin, size)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
window.SetQuitOnClose(true);
|
||||
|
Loading…
Reference in New Issue
Block a user