Skip to content

Commit

Permalink
fix(desktop): set initial and minimum window sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
JagandeepBrar committed Mar 26, 2022
1 parent 12fab1d commit dd30c3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
20 changes: 14 additions & 6 deletions lib/core/system/window_manager/platform/window_manager_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class IO implements LunaWindowManager {
Future<void> initialize() async {
await windowManager.ensureInitialized();
windowManager.waitUntilReadyToShow().then((_) async {
const Size minSize = Size(
LunaWindowManager.MINIMUM_WINDOW_SIZE,
LunaWindowManager.MINIMUM_WINDOW_SIZE,
);

await windowManager.setMinimumSize(minSize);
setWindowSize();
setWindowTitle('LunaSea');

windowManager.show();
Expand All @@ -40,4 +35,17 @@ class IO implements LunaWindowManager {
.waitUntilReadyToShow()
.then((_) async => await windowManager.setTitle(title));
}

Future<void> setWindowSize() async {
const min = LunaWindowManager.MINIMUM_WINDOW_SIZE;
const init = LunaWindowManager.INITIAL_WINDOW_SIZE;
const minSize = Size(min, min);
const initSize = Size(init, init);

await windowManager.setSize(initSize);
// Currently broken on Linux
if (!LunaPlatform().isLinux) {
await windowManager.setMinimumSize(minSize);
}
}
}
4 changes: 3 additions & 1 deletion lib/core/system/window_manager/window_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'platform/window_manager_stub.dart'
if (dart.library.html) 'platform/window_manager_html.dart';

abstract class LunaWindowManager {
static const double MINIMUM_WINDOW_SIZE = 400;
// Need to change `windows/runner/main.cpp` and `linux/my_application.cc` manually if this wants to be changed
static const double INITIAL_WINDOW_SIZE = 700;
static const double MINIMUM_WINDOW_SIZE = 500;

static bool get isSupported => isPlatformSupported();
factory LunaWindowManager() => getWindowManager();
Expand Down
2 changes: 1 addition & 1 deletion windows/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,

FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
Win32Window::Size size(700, 700);
if (!window.CreateAndShow(L"lunasea", origin, size)) {
return EXIT_FAILURE;
}
Expand Down

0 comments on commit dd30c3a

Please sign in to comment.