windower

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2022 License: MIT Imports: 4 Imported by: 1

README

Windower

Simple interface for creating windows across multiple platforms

Supported Platforms

  • Windows (win32)
    • Windows 2000+
  • Darwin (Cocoa)
    • Mac 10.8+

Each supported platform has its own problems with full interfacing but almost all functions work as expected and any issues are denoted here and in comments.

Windows and Darwin require no extra packages to compile.

Examples:

example contains a go package that can be run normally and displays how the module works. This example works on all supported platforms as expected.

  cd examples/
  go run .

Platform-specific window objects can be operated manually by using go-build options targeting the specific platform and then creating the window and casting it to the wanted platform window object.

//go:build windows

package main

import (
  "fmt"
  "git.sr.ht/~mia/w32"
  "git.sr.ht/~mia/windower"
)

func main() {
  // Create and cast the window object
  window := windower.CreateNewWindow(&windower.WindowOptions{
    NSApp:  nil,
    Title:  "This is a test",
    Width:  1000,
    Height: 1000,
    Style: windower.WindowStyle{
      Minimizable:    false,
      Maximizable:    false,
      NotClosable:    false,
      Resizable:      true,
      DisplayMenuBar: false,
    },
    MenuBar: []windower.MenuBarElementItem{},
  }).(*windower.WindowsWindow)

  // do stuff with the raw window pointer directly
  fmt.Println(w32.GetWindowText(window.Window))

  // normal window functions still work as expected
  fmt.Println(window.GetTitle())
}

Windows

Windows support is done via win32 API.

Win32 supports Windows 2000 and newer.

Requirements
  • None!
Issues
  • None at the moment though lets hope memory leaks aren't a thing.

Darwin

Darwin support for Mac is done via Cocoa and may support other platforms that also have Cocoa (ios, etc) but have not been tested.

Cocoa supports Mac 10.8 and newer.

Requirements
  • None!
Issues
  • Can not support setting an active window's Title, Position, nor Size.

Future

  • Support of Linux via GTK3(4?)
  • Invest more time into Cocoa threading issues

Technical Things

Win32

Win32 API communication is done via a cgo package I modified slightly found here: https://git.sr.ht/~mia/w32

Cocoa

Cocoa API communication is done via a cgo package found here: https://github.com/progrium/macdriver

Threading

I attempt to force-multithread the window to its own, standalone go thread and manage the thread internally to the package. This makes it look like there is no weird things going on but also won't ever block the main go thread without you explicitly telling it to do so and as a result will never be blocked by the execution of code on the main go thread.

If you need manual control over the Platform-specific window object be aware of this, but it should not and has not caused any problems for me.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {
	GetType() EventType
	GetTimestamp() time.Time
}

type EventType

type EventType int
const (
	MouseLeftClickEventType EventType = iota
	MouseLeftDoubleClickEventType
	MouseRightClickEventType
	MouseRightDoubleClickEventType

	// MouseMiddleClickEventType Windows Only
	MouseMiddleClickEventType
	// MouseMiddleDoubleClickEventType Windows Only
	MouseMiddleDoubleClickEventType

	// MouseEnterWindowEventType Not Implemented
	MouseEnterWindowEventType
	// MouseLeaveWindowEventType Not Implemented
	MouseLeaveWindowEventType
	// MouseScrollWheelEventType Not Implemented
	MouseScrollWheelEventType

	WindowFocusEventType
	WindowBlurEventType
	WindowQuitEventType

	WindowHasMovedEventType
	WindowIsMovingEventType

	// WindowHasResizedEventType Windows Only
	WindowHasResizedEventType
	// WindowIsResizingEventType Windows Only
	WindowIsResizingEventType
)
type MenuBarElement interface {
	GetId() uuid.UUID
	GetType() MenuBarElementType
	HandleWith(window Window)
	SetText(text string)
	IsEnabled() bool
	Disable()
	Enable()
	IsChecked() bool
	Check()
	Uncheck()
	// contains filtered or unexported methods
}
type MenuBarElementItem struct {
	ID          uuid.UUID
	Disabled    bool
	Checked     bool
	Text        string
	Handler     func(element MenuBarElement, window Window)
	Elements    []MenuBarElement
	WindowsIcon interface{}
	DarwinIcon  interface{}
	// contains filtered or unexported fields
}
func (element *MenuBarElementItem) Check()
func (element *MenuBarElementItem) Disable()
func (element *MenuBarElementItem) Enable()
func (element *MenuBarElementItem) GetId() uuid.UUID
func (element *MenuBarElementItem) GetType() MenuBarElementType
func (element *MenuBarElementItem) HandleWith(window Window)
func (element *MenuBarElementItem) IsChecked() bool
func (element *MenuBarElementItem) IsEnabled() bool
func (element *MenuBarElementItem) SetText(text string)
func (element *MenuBarElementItem) Uncheck()
type MenuBarElementSeparator struct {
	ID uuid.UUID
}
func (element MenuBarElementSeparator) Check()
func (element MenuBarElementSeparator) Disable()
func (element MenuBarElementSeparator) Enable()
func (element MenuBarElementSeparator) GetId() uuid.UUID
func (element MenuBarElementSeparator) GetType() MenuBarElementType
func (element MenuBarElementSeparator) HandleWith(_ Window)
func (element MenuBarElementSeparator) IsChecked() bool
func (element MenuBarElementSeparator) IsEnabled() bool
func (element MenuBarElementSeparator) SetText(_ string)
func (element MenuBarElementSeparator) Uncheck()
type MenuBarElementType int
const (
	MenuBarElementTypeSeparator MenuBarElementType = iota
	MenuBarElementTypeItem
)

type Modifiers added in v0.2.0

type Modifiers struct {
	CTRL     bool
	SHIFT    bool
	MENU     bool
	ALTOPT   bool
	SUPER    bool
	CAPSLOCK bool
}

type MouseEvent

type MouseEvent struct {
	Position  Position
	Modifiers Modifiers
	// contains filtered or unexported fields
}

func (*MouseEvent) GetTimestamp added in v0.2.0

func (event *MouseEvent) GetTimestamp() time.Time

func (*MouseEvent) GetType added in v0.2.0

func (event *MouseEvent) GetType() EventType

type Position

type Position struct {
	X int
	Y int
}

type Size added in v0.2.0

type Size struct {
	Width  int
	Height int
}

type Window

type Window interface {
	Run()

	// WaitForWindowClose Does not return until the window has been destroyed
	WaitForWindowClose()

	// AppendEventHandler
	//
	// WARNING: Will run as a go func
	AppendEventHandler(func(window Window, event Event))

	GetMenuItem(id uuid.UUID) MenuBarElement

	GetPosition() (top, left int)
	// SetPosition Does not work on Mac
	SetPosition(top, left int)

	GetSize() (width, height int)
	// SetSize Does not work on Mac
	SetSize(width, height int)

	GetTitle() string
	// SetTitle Does not work on Mac
	SetTitle(string)
}

type WindowEvent

type WindowEvent struct {
	Position Position
	Size     Size
	// contains filtered or unexported fields
}

func (*WindowEvent) GetTimestamp added in v0.2.0

func (event *WindowEvent) GetTimestamp() time.Time

func (*WindowEvent) GetType added in v0.2.0

func (event *WindowEvent) GetType() EventType

type WindowOptions

type WindowOptions struct {
	NSApp   unsafe.Pointer
	AppName string
	Title   string
	Width   int
	Height  int
	Style   WindowStyle
	MenuBar []MenuBarElementItem
}

type WindowStyle

type WindowStyle struct {
	Minimizable    bool
	Maximizable    bool
	NotClosable    bool
	Resizable      bool
	DisplayMenuBar bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL