alexflint / gallium

Build desktop applications in Go and HTML.
MIT License
3.67k stars 135 forks source link

New window creation API #18

Closed alexflint closed 7 years ago

alexflint commented 7 years ago

This pr introduces a new API for creating windows that lets you set many more window properties than was previously possible. For example, to create a borderless window:

app.OpenWindow(func(win *gallium.WindowOptions) {
        win.X = 0
        win.Y = 0
        win.Width = 800
        win.Height = 600
        win.URL = "http://example.com/"
        win.Frame = false
        win.TitleBar = false
})
screenshot 2016-10-02 14 07 55

The callback style for passing options is based on Dave Cheney's presentation here: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis. I'm not yet sold on the idea and may go back to just passing in an options struct to OpenWindow()

The full set of options:

type WindowOptions struct {
    URL              string // Initial URL to load; leave empty to load nothing
    Title            string // String to display in title bar
    Width            int    // Width in pixels. Set to zero to use OS default.
    Height           int    // Height in pixels. Set to zero to use OS default.
    X                int    // X offset from left in pixels. Set to zero to use OS default.
    Y                int    // Y offset from top in pixels. Set to zero to use OS default.
    TitleBar         bool   // Whether the window title bar
    Frame            bool   // Whether the window has a frame
    Resizable        bool   // Whether the window border can be dragged to change its shape
    CloseButton      bool   // Whether the window has a close button
    MinButton        bool   // Whether the window has a miniaturize button
    FullScreenButton bool   // Whether the window has a full screen button
    Menu             []MenuEntry
}

(My plan is to leave PRs like this up for 24 hours before merging to gather feedback. If anybody has time to do a full code review I would appreciate it.)

alexflint commented 7 years ago

Okay have moved away from functional options. It's nicer now because there is a more natural place for the default sizes and titles. All of these APIs are still very provisional and open to complete redesign so I'm going to merge this soon @ernesto-jimenez .

emead commented 7 years ago

The README needs updating to remove the use of NewWindow.