Skip to content

Commit 3907dd9

Browse files
committed
Responsive Layout for desktop and custom title bar
1 parent f2f43e1 commit 3907dd9

File tree

8 files changed

+465
-196
lines changed

8 files changed

+465
-196
lines changed

lib/homepage.dart

Lines changed: 221 additions & 180 deletions
Large diffs are not rendered by default.

lib/main.dart

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@ import 'package:provider/provider.dart';
1010
import 'package:provider/single_child_widget.dart';
1111
import 'homepage.dart';
1212
import 'editor_drawer.dart';
13+
import 'package:bitsdojo_window/bitsdojo_window.dart';
1314

14-
void main() async{
15+
void main() async {
1516
runApp(const CoreCoderApp());
17+
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
18+
doWhenWindowReady(() {
19+
const initialSize = Size(800, 600);
20+
appWindow.minSize = const Size(256, 256);
21+
appWindow.size = initialSize;
22+
appWindow.alignment = Alignment.center;
23+
appWindow.show();
24+
});
25+
}
1626
}
1727

28+
const borderColor = Color(0xFF3BBA73);
1829

1930
class CoreCoderApp extends StatefulWidget {
2031
const CoreCoderApp({Key? key}) : super(key: key);
@@ -25,8 +36,10 @@ class CoreCoderApp extends StatefulWidget {
2536
}
2637
}
2738

28-
class CoreCoderAppState extends State<CoreCoderApp>{
39+
class CoreCoderAppState extends State<CoreCoderApp> {
2940
String themeName = "core-coder-dark";
41+
var borderColor = Colors.black;
42+
3043
@override
3144
void initState() {
3245
super.initState();
@@ -35,7 +48,7 @@ class CoreCoderAppState extends State<CoreCoderApp>{
3548
themeName = ThemeManager.currentTheme.value;
3649
});
3750
});
38-
if(Platform.isWindows) {
51+
if (Platform.isWindows) {
3952
/// On windows, get the runtime arguments
4053
/// this is provided by windows when you "Open with" CoreCoder
4154
/// the result is a string to the absolute path of the file
@@ -50,22 +63,73 @@ class CoreCoderAppState extends State<CoreCoderApp>{
5063
@override
5164
Widget build(BuildContext context) {
5265
return MultiProvider(
53-
child: MaterialApp(
54-
debugShowCheckedModeBanner: false,
55-
title: 'CoreCoder Develop',
56-
theme: ThemeManager.getThemeData(themeName:themeName),
57-
//home: HomePage(),
58-
initialRoute: "/",
59-
routes: {
60-
"/": (context) => HomePage(),
61-
EditorPage.routeName: (context) => const EditorPage(),
62-
PluginsBrowser.routeName: (context) => const PluginsBrowser()
63-
},
64-
),
66+
child: WindowBorder(
67+
color: borderColor,
68+
child: MaterialApp(
69+
debugShowCheckedModeBanner: false,
70+
title: 'CoreCoder Develop',
71+
theme: ThemeManager.getThemeData(themeName: themeName),
72+
//home: HomePage(),
73+
initialRoute: "/",
74+
routes: {
75+
"/": (context) => HomePage(),
76+
EditorPage.routeName: (context) => const EditorPage(),
77+
PluginsBrowser.routeName: (context) => const PluginsBrowser()
78+
},
79+
builder: (BuildContext context, Widget? widget) {
80+
borderColor = Theme.of(context).primaryColor;
81+
return Container(
82+
color: Theme.of(context).colorScheme.background,
83+
child: Column(
84+
children: [
85+
// The title bar
86+
WindowTitleBarBox(
87+
child: Row(children: [
88+
Expanded(child: MoveWindow(child: Row(children:[
89+
const SizedBox(width: 16.0,),
90+
Image.asset("assets/logo.png",width: 20,height: 20,),
91+
const SizedBox(width: 16.0,),
92+
Text("CoreCoder v0.0.1", style: Theme.of(context).textTheme.bodyText1!,)
93+
]),)),
94+
const WindowButtons()
95+
])),
96+
if (widget != null) Expanded(child: widget)
97+
],
98+
));
99+
},
100+
)),
65101
providers: <SingleChildWidget>[
66102
ChangeNotifierProvider<DrawerStateInfo>(
67103
create: (_) => DrawerStateInfo()),
68104
],
69105
);
70106
}
71107
}
108+
109+
final buttonColors = WindowButtonColors(
110+
iconNormal: borderColor,
111+
mouseOver: Color(0xFFF6A00C),
112+
mouseDown: Color(0xFF805306),
113+
iconMouseOver: Color(0xFF805306),
114+
iconMouseDown: Color(0xFFFFD500));
115+
116+
final closeButtonColors = WindowButtonColors(
117+
mouseOver: const Color(0xFFD32F2F),
118+
mouseDown: const Color(0xFFB71C1C),
119+
iconNormal: borderColor,
120+
iconMouseOver: Colors.white);
121+
122+
class WindowButtons extends StatelessWidget {
123+
const WindowButtons({Key? key}) : super(key: key);
124+
125+
@override
126+
Widget build(BuildContext context) {
127+
return Row(
128+
children: [
129+
MinimizeWindowButton(colors: buttonColors),
130+
MaximizeWindowButton(colors: buttonColors),
131+
CloseWindowButton(colors: closeButtonColors),
132+
],
133+
);
134+
}
135+
}

lib/util/desktop_tabbar.dart

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import 'package:corecoder_develop/util/theme_manager.dart';
2+
import 'package:flutter/cupertino.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:tabbed_view/tabbed_view.dart';
5+
6+
class DesktopTabBar extends StatefulWidget {
7+
final double tabSize;
8+
final List<Widget> content;
9+
final List<DesktopTabData> tabs;
10+
11+
const DesktopTabBar(
12+
{Key? key,
13+
this.tabSize = 256.0,
14+
required this.content,
15+
required this.tabs})
16+
: super(key: key);
17+
18+
@override
19+
State createState() => DesktopTabBarState();
20+
}
21+
22+
class DesktopTabBarState extends State<DesktopTabBar> {
23+
Color? colorBackground;
24+
Color? colorBackgroundSecondary;
25+
int selectedTab = 0;
26+
27+
List<Widget> get tabs {
28+
return List.generate(widget.tabs.length, (index) {
29+
var item = widget.tabs[index];
30+
return DesktopTab(
31+
icon: item.icon, title: item.title, onClick: () {
32+
setState(() {
33+
selectedTab = index;
34+
});
35+
}, isActive: selectedTab == index);
36+
});
37+
}
38+
39+
@override
40+
void initState() {
41+
super.initState();
42+
}
43+
44+
@override
45+
Widget build(BuildContext context) {
46+
var query = MediaQuery.of(context);
47+
48+
colorBackground = ThemeManager.getThemeSchemeColor("backgroundTertiary");
49+
colorBackgroundSecondary =
50+
ThemeManager.getThemeSchemeColor("backgroundSecondary");
51+
return Container(
52+
color: colorBackground,
53+
constraints: BoxConstraints(maxHeight: query.size.height - 200),
54+
child: Flex(
55+
direction: Axis.horizontal,
56+
crossAxisAlignment: CrossAxisAlignment.stretch,
57+
children: <Widget>[
58+
Container(
59+
padding: const EdgeInsets.all(16.0),
60+
child: SingleChildScrollView(
61+
child: Column(
62+
children: tabs,
63+
crossAxisAlignment: CrossAxisAlignment.stretch,
64+
),
65+
),
66+
constraints: BoxConstraints(
67+
minWidth: widget.tabSize, maxWidth: widget.tabSize),
68+
),
69+
Expanded(
70+
child: Container(
71+
color: colorBackgroundSecondary,
72+
child: widget.content[selectedTab],
73+
))
74+
],
75+
));
76+
}
77+
}
78+
79+
class DesktopTabData {
80+
final Widget icon, title;
81+
82+
DesktopTabData({required this.icon, required this.title});
83+
}
84+
85+
class DesktopTab extends StatelessWidget {
86+
final Widget icon, title;
87+
final Function() onClick;
88+
final bool isActive;
89+
90+
const DesktopTab(
91+
{Key? key,
92+
required this.icon,
93+
required this.title,
94+
required this.onClick,
95+
required this.isActive})
96+
: super(key: key);
97+
98+
@override
99+
Widget build(BuildContext context) {
100+
return TextButton(
101+
style: ButtonStyle(
102+
backgroundColor:(isActive)? MaterialStateProperty.all(Theme.of(context).canvasColor) : null,
103+
padding: MaterialStateProperty.all(const EdgeInsets.all(16.0)),
104+
foregroundColor: MaterialStateProperty.all(
105+
Theme.of(context).textTheme.bodyText1?.color)),
106+
onPressed: onClick,
107+
child: Row(
108+
children: [
109+
icon,
110+
const SizedBox(
111+
width: 16.0,
112+
),
113+
title
114+
],
115+
),
116+
);
117+
}
118+
}

pubspec.lock

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,41 @@ packages:
2929
url: "https://pub.dartlang.org"
3030
source: hosted
3131
version: "2.8.2"
32+
bitsdojo_window:
33+
dependency: "direct main"
34+
description:
35+
name: bitsdojo_window
36+
url: "https://pub.dartlang.org"
37+
source: hosted
38+
version: "0.1.1+1"
39+
bitsdojo_window_linux:
40+
dependency: transitive
41+
description:
42+
name: bitsdojo_window_linux
43+
url: "https://pub.dartlang.org"
44+
source: hosted
45+
version: "0.1.1"
46+
bitsdojo_window_macos:
47+
dependency: transitive
48+
description:
49+
name: bitsdojo_window_macos
50+
url: "https://pub.dartlang.org"
51+
source: hosted
52+
version: "0.1.0"
53+
bitsdojo_window_platform_interface:
54+
dependency: transitive
55+
description:
56+
name: bitsdojo_window_platform_interface
57+
url: "https://pub.dartlang.org"
58+
source: hosted
59+
version: "0.1.0"
60+
bitsdojo_window_windows:
61+
dependency: transitive
62+
description:
63+
name: bitsdojo_window_windows
64+
url: "https://pub.dartlang.org"
65+
source: hosted
66+
version: "0.1.0"
3267
boolean_selector:
3368
dependency: transitive
3469
description:

pubspec.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ dependencies:
6161
github: ^8.4.0
6262
archive: ^3.1.6
6363
android_intent_plus: ^3.0.2
64+
bitsdojo_window: ^0.1.1+1
6465

6566
dev_dependencies:
6667
flutter_test:
@@ -84,7 +85,8 @@ flutter:
8485
uses-material-design: true
8586

8687
# To add assets to your application, add an assets section, like this:
87-
# assets:
88+
assets:
89+
- assets/logo.png
8890
# - images/a_dot_burr.jpeg
8991
# - images/a_dot_ham.jpeg
9092

windows/flutter/generated_plugin_registrant.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
910
#include <flutter_jscore/flutter_jscore_plugin.h>
1011
#include <url_launcher_windows/url_launcher_windows.h>
1112

1213
void RegisterPlugins(flutter::PluginRegistry* registry) {
14+
BitsdojoWindowPluginRegisterWithRegistrar(
15+
registry->GetRegistrarForPlugin("BitsdojoWindowPlugin"));
1316
FlutterJscorePluginRegisterWithRegistrar(
1417
registry->GetRegistrarForPlugin("FlutterJscorePlugin"));
1518
UrlLauncherWindowsRegisterWithRegistrar(

windows/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
bitsdojo_window_windows
67
flutter_jscore
78
url_launcher_windows
89
)

windows/runner/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
#include "flutter_window.h"
88
#include "utils.h"
9+
10+
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
11+
auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);
12+
13+
914
wchar_t* convertCharArrayToLPCWSTR(const char* charArray)
1015
{
1116
wchar_t* wString = new wchar_t[4096];

0 commit comments

Comments
 (0)