mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Can move window
This commit is contained in:
parent
b40308c9e4
commit
ef186f79d2
@ -1,10 +1,13 @@
|
||||
import 'package:comunic/ui/screens/call_screen.dart';
|
||||
import 'package:comunic/ui/widgets/tablet_mode/calls/calls_area.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Call window widget
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
const _WindowSize = Size(500, 200);
|
||||
|
||||
class CallWindowWidget extends StatefulWidget {
|
||||
final int convID;
|
||||
|
||||
@ -19,14 +22,59 @@ class CallWindowWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _CallWindowWidgetState extends State<CallWindowWidget> {
|
||||
double _left, _top;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
// Initialize window coordinates
|
||||
_top = 10;
|
||||
_left = MediaQuery.of(context).size.width - 10 - _WindowSize.width;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Positioned(
|
||||
width: 500,
|
||||
height: 200,
|
||||
right: 10,
|
||||
top: 10,
|
||||
child: Card(child: CallScreen(convID: widget.convID)),
|
||||
width: _WindowSize.width,
|
||||
height: _WindowSize.height,
|
||||
left: _left,
|
||||
top: _top,
|
||||
child: Draggable(
|
||||
child: Card(child: CallScreen(convID: widget.convID)),
|
||||
feedback: Container(
|
||||
width: _WindowSize.width,
|
||||
height: _WindowSize.height,
|
||||
color: Colors.red,
|
||||
),
|
||||
onDragEnd: _moveEnd,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Compute new window position
|
||||
void _moveEnd(DraggableDetails details) {
|
||||
// Determine the limits of containing stack
|
||||
RenderBox renderBox = context
|
||||
.findAncestorStateOfType<CallsAreaState>()
|
||||
.context
|
||||
.findRenderObject();
|
||||
final size = renderBox.size;
|
||||
final offset = renderBox.localToGlobal(Offset.zero);
|
||||
|
||||
// Determine new window position
|
||||
_top = details.offset.dy - offset.dy;
|
||||
_left = details.offset.dx - offset.dx;
|
||||
|
||||
// Force the window to appear completely on the screen
|
||||
if (_top + _WindowSize.height >= size.height)
|
||||
_top = size.height - _WindowSize.height;
|
||||
if (_left + _WindowSize.width >= size.width)
|
||||
_left = size.width - _WindowSize.width;
|
||||
|
||||
if (_top < 0) _top = 0;
|
||||
if (_left < 0) _left = 0;
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user