Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d70365fa
Commit
d70365fa
authored
Feb 09, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1708 from abarth/wm
Make the Mozart demo more like a real window manager
parents
8fdaf4af
657eadcd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
184 additions
and
34 deletions
+184
-34
mozart.dart
examples/widgets/mozart.dart
+184
-34
No files found.
examples/widgets/mozart.dart
View file @
d70365fa
...
@@ -2,52 +2,188 @@
...
@@ -2,52 +2,188 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
import
'dart:math'
as
math
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
const
List
<
String
>
_kKnownApps
=
const
<
String
>[
class
LauncherData
{
'mojo:noodles_view'
,
const
LauncherData
({
this
.
url
,
this
.
title
});
'mojo:shapes_view'
,
final
String
url
;
final
String
title
;
}
const
List
<
LauncherData
>
_kLauncherData
=
const
<
LauncherData
>[
const
LauncherData
(
url:
'mojo:noodles_view'
,
title:
'Noodles'
),
const
LauncherData
(
url:
'mojo:shapes_view'
,
title:
'Shapes'
),
];
];
const
Size
_kSmallWindowSize
=
const
Size
(
400.0
,
400.0
);
const
Size
_kInitialWindowSize
=
const
Size
(
200.0
,
200.0
);
const
Size
_kBigWindowSize
=
const
Size
(
600.0
,
600.0
);
const
double
_kWindowPadding
=
10.0
;
enum
WindowSide
{
topCenter
,
topRight
,
bottomRight
,
}
class
WindowDecoration
extends
StatelessComponent
{
WindowDecoration
({
Key
key
,
this
.
side
,
this
.
color
,
this
.
onTap
,
this
.
onPanUpdate
})
:
super
(
key:
key
);
final
WindowSide
side
;
final
Color
color
;
final
GestureTapCallback
onTap
;
final
GesturePanUpdateCallback
onPanUpdate
;
Widget
build
(
BuildContext
context
)
{
double
top
,
right
,
bottom
,
left
,
width
,
height
;
height
=
_kWindowPadding
*
2.0
;
if
(
side
==
WindowSide
.
topCenter
||
side
==
WindowSide
.
topRight
)
top
=
0.0
;
if
(
side
==
WindowSide
.
topRight
||
side
==
WindowSide
.
bottomRight
)
{
right
=
0.0
;
width
=
_kWindowPadding
*
2.0
;
}
if
(
side
==
WindowSide
.
topCenter
)
{
left
=
_kWindowPadding
;
right
=
_kWindowPadding
;
}
if
(
side
==
WindowSide
.
bottomRight
)
bottom
=
0.0
;
return
new
Positioned
(
top:
top
,
right:
right
,
bottom:
bottom
,
left:
left
,
width:
width
,
height:
height
,
child:
new
GestureDetector
(
onTap:
onTap
,
onPanUpdate:
onPanUpdate
,
child:
new
Container
(
decoration:
new
BoxDecoration
(
backgroundColor:
color
)
)
)
);
}
}
class
Window
extends
StatefulComponent
{
class
Window
extends
StatefulComponent
{
Window
({
Key
key
,
this
.
child
})
:
super
(
key:
key
);
Window
({
Key
key
,
this
.
child
,
this
.
onClose
})
:
super
(
key:
key
);
final
ChildViewConnection
child
;
final
ChildViewConnection
child
;
final
ValueChanged
<
ChildViewConnection
>
onClose
;
_WindowState
createState
()
=>
new
_WindowState
();
_WindowState
createState
()
=>
new
_WindowState
();
}
}
class
_WindowState
extends
State
<
Window
>
{
class
_WindowState
extends
State
<
Window
>
{
Offset
_offset
=
Offset
.
zero
;
Offset
_offset
=
Offset
.
zero
;
bool
_isSmall
=
tru
e
;
Size
_size
=
_kInitialWindowSiz
e
;
void
_handle
PanUpdate
(
Offset
delta
)
{
void
_handle
ResizerDrag
(
Offset
delta
)
{
setState
(()
{
setState
(()
{
_offset
+=
delta
;
_size
=
new
Size
(
math
.
max
(
0.0
,
_size
.
width
+
delta
.
dx
),
math
.
max
(
0.0
,
_size
.
height
+
delta
.
dy
)
);
});
});
}
}
void
_handle
Tap
(
)
{
void
_handle
RepositionDrag
(
Offset
delta
)
{
setState
(()
{
setState
(()
{
_
isSmall
=
!
_isSmall
;
_
offset
+=
delta
;
});
});
}
}
void
_handleClose
()
{
config
.
onClose
(
config
.
child
);
}
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
Size
size
=
_isSmall
?
_kSmallWindowSize
:
_kBigWindowSize
;
return
new
Positioned
(
return
new
Positioned
(
left:
_offset
.
dx
,
left:
_offset
.
dx
,
top:
_offset
.
dy
,
top:
_offset
.
dy
,
width:
size
.
width
,
width:
_size
.
width
+
_kWindowPadding
*
2.0
,
height:
size
.
height
,
height:
_size
.
height
+
_kWindowPadding
*
2.0
,
child:
new
GestureDetector
(
child:
new
Stack
(
onPanUpdate:
_handlePanUpdate
,
children:
<
Widget
>[
onTap:
_handleTap
,
new
WindowDecoration
(
side:
WindowSide
.
topCenter
,
onPanUpdate:
_handleRepositionDrag
,
color:
Colors
.
green
[
200
]
),
new
WindowDecoration
(
side:
WindowSide
.
topRight
,
onTap:
_handleClose
,
color:
Colors
.
red
[
200
]
),
new
WindowDecoration
(
side:
WindowSide
.
bottomRight
,
onPanUpdate:
_handleResizerDrag
,
color:
Colors
.
blue
[
200
]
),
new
Container
(
padding:
const
EdgeDims
.
all
(
_kWindowPadding
),
child:
new
Material
(
elevation:
8
,
child:
new
ChildView
(
child:
config
.
child
)
child:
new
ChildView
(
child:
config
.
child
)
)
)
)
]
)
);
}
}
class
LauncherItem
extends
StatelessComponent
{
LauncherItem
({
Key
key
,
this
.
url
,
this
.
child
,
this
.
onLaunch
})
:
super
(
key:
key
);
final
String
url
;
final
Widget
child
;
final
ValueChanged
<
ChildViewConnection
>
onLaunch
;
Widget
build
(
BuildContext
context
)
{
return
new
RaisedButton
(
onPressed:
()
{
onLaunch
(
new
ChildViewConnection
(
url:
url
));
},
child:
child
);
}
}
class
Launcher
extends
StatelessComponent
{
Launcher
({
Key
key
,
this
.
items
})
:
super
(
key:
key
);
final
List
<
Widget
>
items
;
Widget
build
(
BuildContext
context
)
{
return
new
Row
(
justifyContent:
FlexJustifyContent
.
center
,
children:
items
);
);
}
}
}
}
...
@@ -59,27 +195,41 @@ class WindowManager extends StatefulComponent {
...
@@ -59,27 +195,41 @@ class WindowManager extends StatefulComponent {
class
_WindowManagerState
extends
State
<
WindowManager
>
{
class
_WindowManagerState
extends
State
<
WindowManager
>
{
List
<
ChildViewConnection
>
_windows
=
<
ChildViewConnection
>[];
List
<
ChildViewConnection
>
_windows
=
<
ChildViewConnection
>[];
void
_handleTap
()
{
void
_handleLaunch
(
ChildViewConnection
child
)
{
setState
(()
{
_windows
.
add
(
child
);
});
}
void
_handleClose
(
ChildViewConnection
child
)
{
setState
(()
{
setState
(()
{
_windows
.
add
(
new
ChildViewConnection
(
url:
_kKnownApps
[
_windows
.
length
%
_kKnownApps
.
length
])
);
_windows
.
remove
(
child
);
});
});
}
}
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
new
GestureDetector
(
return
new
Material
(
onTap:
_handleTap
,
child:
new
Container
(
decoration:
new
BoxDecoration
(
backgroundColor:
Colors
.
blue
[
500
]
),
child:
new
Stack
(
child:
new
Stack
(
children:
_windows
.
map
((
ChildViewConnection
child
)
{
children:
<
Widget
>[
new
Positioned
(
left:
0.0
,
right:
0.0
,
bottom:
0.0
,
child:
new
Launcher
(
items:
_kLauncherData
.
map
((
LauncherData
data
)
{
return
new
LauncherItem
(
url:
data
.
url
,
onLaunch:
_handleLaunch
,
child:
new
Text
(
data
.
title
)
);
}).
toList
())
)
]..
addAll
(
_windows
.
map
((
ChildViewConnection
child
)
{
return
new
Window
(
return
new
Window
(
key:
new
ObjectKey
(
child
),
key:
new
ObjectKey
(
child
),
onClose:
_handleClose
,
child:
child
child:
child
);
);
}).
toList
()
}))
)
)
)
);
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment