Skip to content

GLFW Plugin example

Pierre Champion edited this page Jul 15, 2019 · 25 revisions

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.

Examples

Case study #1

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 our 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
}
Clone this wiki locally