-
Notifications
You must be signed in to change notification settings - Fork 282
GLFW Plugin example
The dart code cannot control the glfw.Window
size, position, ...
To gain control over the glfw.Window
we need to build your own plugin in order to access the underlying API, please read the plugin wiki in order to learn more about the plugin architecture.
In this example, we answer the issue #126, How to make the window not resizable.
To make the window not resizable for the entire lifetime of the application, there is no need to use the dart and Golang platform-channels (one time call, no communication needed).
Using hover the file to edit is desktop/cmd/options.go
.
By creating a custom GLFW Plugin, we gain access to the glfw.Window
interface. Having access to the glfw.Window interface allows users to customize the window to their needs.
Source code:
package main
import (
"github.com/go-flutter-desktop/go-flutter"
"github.com/go-flutter-desktop/go-flutter/plugin"
"github.com/go-gl/glfw/v3.2/glfw"
)
var options = []flutter.Option{
flutter.WindowInitialDimensions(800, 600),
flutter.AddPlugin(&WindowNotResizable{}),
// ...
}
type WindowNotResizable struct{}
var _ flutter.Plugin = &WindowNotResizable{} // compile-time type check
var _ flutter.PluginGLFW = &WindowNotResizable{} // compile-time type check
// WindowNotResizable struct must implement InitPlugin and InitPluginGLFW
func (p *WindowNotResizable) InitPlugin(messenger plugin.BinaryMessenger) error {
// nothing to do
return nil
}
func (p *WindowNotResizable) InitPluginGLFW(window *glfw.Window) error {
window.SetSizeLimits(800, 600, 800, 600)
return nil
}
In this example, we answer the issue #214, how to drag undecorated window.
go-flutter has multiples option, one of them been flutter.WindowMode(flutter.WindowModeBorderless)
.
When this option is set, the window decoration (title bar, close/maximize/.. buttons) isn't displayed, meaning the window can't be dragged around
, maximize
, closed
,.. using 'classic' mouse interaction.
Wouldn't be natural to use the AppBar
widget to move the window?
Well, it has been implemented has a example. If you launch dragable_borderless, grab the AppBar
and start dragging, the window will follow your cursor!
In order to implement this feature, a GLFW Plugin has been created, the plugin code source is available directly in options.go, it is a good GLFW Plugin example.