Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7fe16d6

Browse files
committed
Add support for setting window size limits for glfw
Add a function to the window which calls the glfw function for fixing the size limits of the window. This can then be called after window creation.
1 parent 89dd067 commit 7fe16d6

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

shell/platform/glfw/flutter_glfw.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ using UniqueGLFWwindowPtr = std::unique_ptr<GLFWwindow, void (*)(GLFWwindow*)>;
3434

3535
static_assert(FLUTTER_ENGINE_VERSION == 1, "");
3636

37+
const int kFlutterDesktopDontCare = GLFW_DONT_CARE;
38+
3739
static constexpr double kDpPerInch = 160.0;
3840

3941
// Struct for storing state within an instance of the GLFW Window.
@@ -736,6 +738,14 @@ void FlutterDesktopWindowSetPixelRatioOverride(
736738
}
737739
}
738740

741+
void FlutterDesktopWindowSetSizeLimits(FlutterDesktopWindowRef flutter_window,
742+
FlutterDesktopSize minimum_size,
743+
FlutterDesktopSize maximum_size) {
744+
glfwSetWindowSizeLimits(flutter_window->window, minimum_size.width,
745+
minimum_size.height, maximum_size.width,
746+
maximum_size.height);
747+
}
748+
739749
bool FlutterDesktopRunWindowEventLoopWithTimeout(
740750
FlutterDesktopWindowControllerRef controller,
741751
uint32_t timeout_milliseconds) {

shell/platform/glfw/public/flutter_glfw.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
extern "C" {
1717
#endif
1818

19+
extern const int kFlutterDesktopDontCare;
20+
1921
// Opaque reference to a Flutter window controller.
2022
typedef struct FlutterDesktopWindowControllerState*
2123
FlutterDesktopWindowControllerRef;
@@ -26,6 +28,12 @@ typedef struct FlutterDesktopWindow* FlutterDesktopWindowRef;
2628
// Opaque reference to a Flutter engine instance.
2729
typedef struct FlutterDesktopEngineState* FlutterDesktopEngineRef;
2830

31+
// Properties representing a generic rectangular size.
32+
typedef struct {
33+
int32_t width;
34+
int32_t height;
35+
} FlutterDesktopSize;
36+
2937
// Properties for configuring a Flutter engine instance.
3038
typedef struct {
3139
// The path to the flutter_assets folder for the application to be run.
@@ -167,6 +175,13 @@ FLUTTER_EXPORT void FlutterDesktopWindowSetPixelRatioOverride(
167175
FlutterDesktopWindowRef flutter_window,
168176
double pixel_ratio);
169177

178+
// Sets the min/max size of |flutter_window| in pixels. Use
179+
// kFlutterDesktopDontCare for any dimension you wish to leave unconstrained.
180+
FLUTTER_EXPORT void FlutterDesktopWindowSetSizeLimits(
181+
FlutterDesktopWindowRef flutter_window,
182+
FlutterDesktopSize minimum_size,
183+
FlutterDesktopSize maximum_size);
184+
170185
// Runs an instance of a headless Flutter engine.
171186
//
172187
// Returns a null pointer in the event of an error.

0 commit comments

Comments
 (0)