Documentation
¶
Overview ¶
Package gowt is an idiomatic Go facade over the generated swt package: no Java-shaped overloads, listeners are plain funcs, errors come back from Run. Unwrap on any widget returns the underlying swt object for the full API.
Index ¶
- func Run(setup func(*App)) (err error)
- func SetAppName(name string)
- type Align
- type Answer
- type App
- func (a *App) After(d time.Duration, f func())
- func (a *App) Async(f func())
- func (a *App) Clipboard() *Clipboard
- func (a *App) Dark() bool
- func (a *App) ImageFrom(r io.Reader) (img *Image, err error)
- func (a *App) ImageFromProvider(p swt.ImageDataProvider) *Image
- func (a *App) LoadImage(path string) (img *Image, err error)
- func (a *App) OnThemeChange(f func(dark bool))
- func (a *App) Quit()
- func (a *App) Sync(f func())
- func (a *App) Tray(tooltip string, onClick func()) *TrayIcon
- func (a *App) Unwrap() *swt.Display
- func (a *App) Window(title string, opts ...Option) *Window
- type Button
- type Buttons
- type CTabs
- type Canvas
- type Clipboard
- func (c *Clipboard) Clear()
- func (c *Clipboard) Files() []string
- func (c *Clipboard) HTML() (string, bool)
- func (c *Clipboard) Image() (img *Image, ok bool)
- func (c *Clipboard) SetFiles(paths []string) error
- func (c *Clipboard) SetHTML(html, plain string) (err error)
- func (c *Clipboard) SetImage(img *Image) error
- func (c *Clipboard) SetText(s string) error
- func (c *Clipboard) Text() (string, bool)
- func (c *Clipboard) Unwrap() *swt.Clipboard
- type Column
- type Combo
- func (c *Combo) Index() int
- func (c *Combo) Items() []string
- func (c *Combo) OnChange(f func(text string))
- func (c *Combo) OnSelect(f func(index int))
- func (c *Combo) Select(i int)
- func (c *Combo) SetItems(s []string)
- func (c *Combo) SetText(s string)
- func (c *Combo) Text() string
- func (c *Combo) Unwrap() *swt.Combo
- type CoolBar
- func (b *CoolBar) Add(w Widget)
- func (p CoolBar) AsComposite() *swt.Composite
- func (p CoolBar) Button(text string, onClick func(), opts ...Option) *Button
- func (p CoolBar) CTabs(opts ...Option) *CTabs
- func (p CoolBar) Canvas(onPaint func(g *GC), opts ...Option) *Canvas
- func (p CoolBar) Combo(items []string, opts ...Option) *Combo
- func (p CoolBar) CoolBar(opts ...Option) *CoolBar
- func (p CoolBar) DateTime(opts ...Option) *DateTime
- func (p CoolBar) Group(title string, opts ...Option) *Group
- func (p CoolBar) Label(text string, opts ...Option) *Label
- func (p CoolBar) Link(text string, onClick func(href string), opts ...Option) *Link
- func (p CoolBar) List(items []string, opts ...Option) *List
- func (p CoolBar) Panel(opts ...Option) *Panel
- func (p CoolBar) Progress(max int, opts ...Option) *Progress
- func (p CoolBar) Sash(opts ...Option) *Sash
- func (p CoolBar) Scale(min, max, value int, opts ...Option) *Scale
- func (p CoolBar) Scroll(opts ...Option) *Scroll
- func (p CoolBar) SetLayout(l Layout) *Panel
- func (p CoolBar) ShowTop(w Widget)
- func (p CoolBar) Slider(min, max, value int, opts ...Option) *Slider
- func (p CoolBar) Spinner(min, max, value int, opts ...Option) *Spinner
- func (p CoolBar) Split(opts ...Option) *Split
- func (p CoolBar) StyledText(opts ...Option) *StyledText
- func (p CoolBar) Table(opts ...Option) *Table
- func (p CoolBar) Tabs(opts ...Option) *Tabs
- func (p CoolBar) Text(opts ...Option) *Text
- func (p CoolBar) ToolBar(opts ...Option) *ToolBar
- func (p CoolBar) Tree(opts ...Option) *Tree
- func (b *CoolBar) Unwrap() *swt.CoolBar
- type DateTime
- type Drag
- type DragHandle
- type Drop
- type DropHandle
- type Edge
- type FileDialog
- type FileFilter
- type Fill
- type Font
- type Form
- type FormCell
- type GC
- func (g *GC) FillOval(x, y, w, h int)
- func (g *GC) FillRect(x, y, w, h int)
- func (g *GC) Image(img *Image, x, y int)
- func (g *GC) Line(x1, y1, x2, y2 int)
- func (g *GC) Oval(x, y, w, h int)
- func (g *GC) Rect(x, y, w, h int)
- func (g *GC) SetColor(c RGB)
- func (g *GC) SetFill(c RGB)
- func (g *GC) SetLineWidth(w int)
- func (g *GC) Text(s string, x, y int)
- func (g *GC) TextSize(s string) (w, h int)
- func (g *GC) Unwrap() *swt.GC
- type Grid
- type GridCell
- type Group
- func (p Group) AsComposite() *swt.Composite
- func (p Group) Button(text string, onClick func(), opts ...Option) *Button
- func (p Group) CTabs(opts ...Option) *CTabs
- func (p Group) Canvas(onPaint func(g *GC), opts ...Option) *Canvas
- func (p Group) Combo(items []string, opts ...Option) *Combo
- func (p Group) CoolBar(opts ...Option) *CoolBar
- func (p Group) DateTime(opts ...Option) *DateTime
- func (p Group) Group(title string, opts ...Option) *Group
- func (p Group) Label(text string, opts ...Option) *Label
- func (p Group) Link(text string, onClick func(href string), opts ...Option) *Link
- func (p Group) List(items []string, opts ...Option) *List
- func (p Group) Panel(opts ...Option) *Panel
- func (p Group) Progress(max int, opts ...Option) *Progress
- func (p Group) Sash(opts ...Option) *Sash
- func (p Group) Scale(min, max, value int, opts ...Option) *Scale
- func (p Group) Scroll(opts ...Option) *Scroll
- func (p Group) SetLayout(l Layout) *Panel
- func (g *Group) SetTitle(s string)
- func (p Group) ShowTop(w Widget)
- func (p Group) Slider(min, max, value int, opts ...Option) *Slider
- func (p Group) Spinner(min, max, value int, opts ...Option) *Spinner
- func (p Group) Split(opts ...Option) *Split
- func (p Group) StyledText(opts ...Option) *StyledText
- func (p Group) Table(opts ...Option) *Table
- func (p Group) Tabs(opts ...Option) *Tabs
- func (p Group) Text(opts ...Option) *Text
- func (p Group) ToolBar(opts ...Option) *ToolBar
- func (p Group) Tree(opts ...Option) *Tree
- func (g *Group) Unwrap() *swt.Group
- type Icon
- type Image
- type Label
- type Layout
- type Link
- type List
- func (l *List) Add(s string)
- func (l *List) Clear()
- func (l *List) Index() int
- func (l *List) Items() []string
- func (l *List) Len() int
- func (l *List) OnActivate(f func(index int))
- func (l *List) OnSelect(f func(index int))
- func (l *List) Remove(i int)
- func (l *List) Selected() []int
- func (l *List) SetItem(i int, s string)
- func (l *List) SetItems(s []string)
- func (l *List) SetSelection(i ...int)
- func (l *List) Unwrap() *swt.List
- type Menu
- type MenuItem
- type Message
- type Node
- func (n *Node) Checked() bool
- func (n *Node) Children() []*Node
- func (n *Node) Data() any
- func (n *Node) Expanded() bool
- func (n *Node) Node(text string) *Node
- func (n *Node) Remove()
- func (n *Node) SetChecked(v bool)
- func (n *Node) SetData(v any)
- func (n *Node) SetExpanded(v bool)
- func (n *Node) SetImage(img *Image)
- func (n *Node) SetText(s string)
- func (n *Node) Text() string
- func (n *Node) Unwrap() *swt.TreeItem
- type Op
- type Option
- func Anchor(c FormCell) Option
- func AsCalendar() Option
- func AsTime() Option
- func Background(c RGB) Option
- func Border() Option
- func Bottom() Option
- func Cell(c GridCell) Option
- func Center() Option
- func Check() Option
- func Closable() Option
- func Custom(f func(*swt.Control)) Option
- func Disabled() Option
- func DropDown() Option
- func Flat() Option
- func InRow(c RowCell) Option
- func Indeterminate() Option
- func MultiSelect() Option
- func Multiline() Option
- func Password() Option
- func Radio() Option
- func ReadOnly() Option
- func Right() Option
- func Scrollbars() Option
- func Simple() Option
- func Smooth() Option
- func Tooltip(s string) Option
- func Vertical() Option
- func Wrap() Option
- type Panel
- func (p Panel) AsComposite() *swt.Composite
- func (p Panel) Button(text string, onClick func(), opts ...Option) *Button
- func (p Panel) CTabs(opts ...Option) *CTabs
- func (p Panel) Canvas(onPaint func(g *GC), opts ...Option) *Canvas
- func (p Panel) Combo(items []string, opts ...Option) *Combo
- func (p Panel) CoolBar(opts ...Option) *CoolBar
- func (p Panel) DateTime(opts ...Option) *DateTime
- func (p Panel) Group(title string, opts ...Option) *Group
- func (p Panel) Label(text string, opts ...Option) *Label
- func (p Panel) Link(text string, onClick func(href string), opts ...Option) *Link
- func (p Panel) List(items []string, opts ...Option) *List
- func (p Panel) Panel(opts ...Option) *Panel
- func (p Panel) Progress(max int, opts ...Option) *Progress
- func (p Panel) Sash(opts ...Option) *Sash
- func (p Panel) Scale(min, max, value int, opts ...Option) *Scale
- func (p Panel) Scroll(opts ...Option) *Scroll
- func (p Panel) SetLayout(l Layout) *Panel
- func (p Panel) ShowTop(w Widget)
- func (p Panel) Slider(min, max, value int, opts ...Option) *Slider
- func (p Panel) Spinner(min, max, value int, opts ...Option) *Spinner
- func (p Panel) Split(opts ...Option) *Split
- func (p Panel) StyledText(opts ...Option) *StyledText
- func (p Panel) Table(opts ...Option) *Table
- func (p Panel) Tabs(opts ...Option) *Tabs
- func (p Panel) Text(opts ...Option) *Text
- func (p Panel) ToolBar(opts ...Option) *ToolBar
- func (p Panel) Tree(opts ...Option) *Tree
- func (p Panel) Unwrap() *swt.Composite
- type Progress
- type RGB
- type Row
- type RowCell
- type Sash
- type Scale
- type Scroll
- type Slider
- type Spinner
- type Split
- func (p Split) AsComposite() *swt.Composite
- func (p Split) Button(text string, onClick func(), opts ...Option) *Button
- func (p Split) CTabs(opts ...Option) *CTabs
- func (p Split) Canvas(onPaint func(g *GC), opts ...Option) *Canvas
- func (p Split) Combo(items []string, opts ...Option) *Combo
- func (p Split) CoolBar(opts ...Option) *CoolBar
- func (p Split) DateTime(opts ...Option) *DateTime
- func (p Split) Group(title string, opts ...Option) *Group
- func (p Split) Label(text string, opts ...Option) *Label
- func (p Split) Link(text string, onClick func(href string), opts ...Option) *Link
- func (p Split) List(items []string, opts ...Option) *List
- func (p Split) Panel(opts ...Option) *Panel
- func (p Split) Progress(max int, opts ...Option) *Progress
- func (p Split) Sash(opts ...Option) *Sash
- func (p Split) Scale(min, max, value int, opts ...Option) *Scale
- func (p Split) Scroll(opts ...Option) *Scroll
- func (p Split) SetLayout(l Layout) *Panel
- func (s *Split) SetWeights(w ...int)
- func (p Split) ShowTop(w Widget)
- func (p Split) Slider(min, max, value int, opts ...Option) *Slider
- func (p Split) Spinner(min, max, value int, opts ...Option) *Spinner
- func (p Split) Split(opts ...Option) *Split
- func (p Split) StyledText(opts ...Option) *StyledText
- func (p Split) Table(opts ...Option) *Table
- func (p Split) Tabs(opts ...Option) *Tabs
- func (p Split) Text(opts ...Option) *Text
- func (p Split) ToolBar(opts ...Option) *ToolBar
- func (p Split) Tree(opts ...Option) *Tree
- func (s *Split) Unwrap() *swt.SashForm
- type Stack
- type StyleSpan
- type StyledText
- func (t *StyledText) Append(s string)
- func (t *StyledText) Caret() int
- func (t *StyledText) ClearStyles()
- func (t *StyledText) Copy()
- func (t *StyledText) Cut()
- func (t *StyledText) Insert(s string)
- func (t *StyledText) LineAt(offset int) int
- func (t *StyledText) LineStart(line int) int
- func (t *StyledText) Lines() int
- func (t *StyledText) OnCaret(f func(offset int))
- func (t *StyledText) OnChange(f func(text string))
- func (t *StyledText) OnSelect(f func(start, length int))
- func (t *StyledText) OnStyle(f func(line string) []StyleSpan)
- func (t *StyledText) Paste()
- func (t *StyledText) Replace(start, length int, s string)
- func (t *StyledText) Reveal()
- func (t *StyledText) SelectedText() string
- func (t *StyledText) Selection() (start, length int)
- func (t *StyledText) SetCaret(offset int)
- func (t *StyledText) SetEditable(on bool)
- func (t *StyledText) SetLineBackground(line, count int, c RGB)
- func (t *StyledText) SetSelection(start, length int)
- func (t *StyledText) SetStyle(start, length int, s TextStyle)
- func (t *StyledText) SetTabs(n int)
- func (t *StyledText) SetText(s string)
- func (t *StyledText) SetTopLine(line int)
- func (t *StyledText) SetWrap(on bool)
- func (t *StyledText) Styles() []StyleSpan
- func (t *StyledText) Text() string
- func (t *StyledText) Unwrap() *swt.StyledText
- type Table
- func (t *Table) Clear()
- func (t *Table) Column(title string, width int, opts ...Option) *Column
- func (t *Table) Index() int
- func (t *Table) Len() int
- func (t *Table) OnActivate(f func(index int))
- func (t *Table) OnSelect(f func(index int))
- func (t *Table) Remove(i int)
- func (t *Table) Row(cells ...string) *TableRow
- func (t *Table) RowAt(i int) *TableRow
- func (t *Table) Selected() []int
- func (t *Table) SetSelection(i ...int)
- func (t *Table) ShowHeader(v bool)
- func (t *Table) ShowLines(v bool)
- func (t *Table) Unwrap() *swt.Table
- type TableRow
- func (r *TableRow) Checked() bool
- func (r *TableRow) Data() any
- func (r *TableRow) SetChecked(v bool)
- func (r *TableRow) SetData(v any)
- func (r *TableRow) SetImage(col int, img *Image)
- func (r *TableRow) SetText(col int, s string)
- func (r *TableRow) Text(col int) string
- func (r *TableRow) Unwrap() *swt.TableItem
- type Tabs
- type Text
- type TextStyle
- type ToolBar
- type ToolItem
- func (i *ToolItem) Checked() bool
- func (i *ToolItem) OnClick(f func())
- func (i *ToolItem) SetChecked(v bool)
- func (i *ToolItem) SetEnabled(v bool)
- func (i *ToolItem) SetImage(img *Image)
- func (i *ToolItem) SetText(s string)
- func (i *ToolItem) SetTooltip(s string)
- func (i *ToolItem) Unwrap() *swt.ToolItem
- type TrayIcon
- type Tree
- func (t *Tree) Clear()
- func (t *Tree) Node(text string) *Node
- func (t *Tree) OnActivate(f func(n *Node))
- func (t *Tree) OnCollapse(f func(n *Node))
- func (t *Tree) OnExpand(f func(n *Node))
- func (t *Tree) OnSelect(f func(n *Node))
- func (t *Tree) Roots() []*Node
- func (t *Tree) Select(n *Node)
- func (t *Tree) Selected() []*Node
- func (t *Tree) Unwrap() *swt.Tree
- type Widget
- type Window
- func (p Window) AsComposite() *swt.Composite
- func (p Window) Button(text string, onClick func(), opts ...Option) *Button
- func (p Window) CTabs(opts ...Option) *CTabs
- func (p Window) Canvas(onPaint func(g *GC), opts ...Option) *Canvas
- func (w *Window) Close()
- func (w *Window) ColorDialog(initial RGB) (c RGB, ok bool)
- func (p Window) Combo(items []string, opts ...Option) *Combo
- func (w *Window) Confirm(title, text string) bool
- func (p Window) CoolBar(opts ...Option) *CoolBar
- func (p Window) DateTime(opts ...Option) *DateTime
- func (w *Window) DirDialog(title, dir string) (path string, ok bool)
- func (w *Window) FileDialog(d FileDialog) []string
- func (w *Window) FontDialog(initial Font) (f Font, ok bool)
- func (p Window) Group(title string, opts ...Option) *Group
- func (p Window) Label(text string, opts ...Option) *Label
- func (p Window) Link(text string, onClick func(href string), opts ...Option) *Link
- func (p Window) List(items []string, opts ...Option) *List
- func (w *Window) MenuBar() *Menu
- func (w *Window) MessageBox(m Message) Answer
- func (w *Window) OnClose(f func() bool)
- func (p Window) Panel(opts ...Option) *Panel
- func (p Window) Progress(max int, opts ...Option) *Progress
- func (p Window) Sash(opts ...Option) *Sash
- func (p Window) Scale(min, max, value int, opts ...Option) *Scale
- func (p Window) Scroll(opts ...Option) *Scroll
- func (w *Window) SetLayout(l Layout) *Panel
- func (w *Window) SetSize(width, height int)
- func (w *Window) SetTitle(s string)
- func (w *Window) SetTopInset(points int)
- func (w *Window) Show()
- func (p Window) ShowTop(w Widget)
- func (p Window) Slider(min, max, value int, opts ...Option) *Slider
- func (p Window) Spinner(min, max, value int, opts ...Option) *Spinner
- func (p Window) Split(opts ...Option) *Split
- func (p Window) StyledText(opts ...Option) *StyledText
- func (p Window) Table(opts ...Option) *Table
- func (p Window) Tabs(opts ...Option) *Tabs
- func (p Window) Text(opts ...Option) *Text
- func (p Window) ToolBar(opts ...Option) *ToolBar
- func (p Window) Tree(opts ...Option) *Tree
- func (w *Window) Unwrap() *swt.Shell
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run creates the display, calls setup on the UI thread, then runs the event loop until the last window is closed or App.Quit is called. SWT exceptions raised on the UI thread (panics carrying an error, e.g. *swt.SWTException) are returned; runtime errors and other panics propagate.
With GOWT_SNAP=<file.png> in the environment Run writes the first window as a PNG after the loop has run for GOWT_SNAP_DELAY milliseconds (default 800), then returns; see docs/screenshots.md.
Example ¶
A window with a field, a button and a label; Run returns when the window is closed.
package main
import (
"log"
"github.com/haiodo/gowt"
)
func main() {
err := gowt.Run(func(app *gowt.App) {
w := app.Window("Hello gowt")
w.SetLayout(gowt.Grid{Columns: 2, Margin: 10, Spacing: 8})
name := w.Text(gowt.Cell(gowt.GridCell{Align: gowt.AlignFill, GrowX: true, Width: 200}))
greet := w.Label("", gowt.Cell(gowt.GridCell{SpanX: 2, Align: gowt.AlignFill, GrowX: true}))
w.Button("Greet", func() { greet.SetText("Hello, " + name.Text() + "!") })
w.Show()
})
if err != nil {
log.Fatal(err)
}
}
Output:
func SetAppName ¶
func SetAppName(name string)
SetAppName sets the name the system shows for the process (macOS menu bar and Dock, Linux WM class). Call it before Run.
Types ¶
type Answer ¶
type Answer int
Answer is the button that closed a message box. Closing the box with the window button gives AnswerCancel (or AnswerNo, AnswerOK if there is no Cancel).
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the handle to the UI thread, valid inside Run.
func (*App) After ¶
After runs f on the UI thread once, after d.
Example ¶
After runs a function on the UI thread once the delay has passed.
package main
import (
"time"
"github.com/haiodo/gowt"
)
func main() {
_ = gowt.Run(func(app *gowt.App) {
w := app.Window("Timer")
w.Show()
app.After(5*time.Second, app.Quit)
})
}
Output:
func (*App) Async ¶
func (a *App) Async(f func())
Async queues f on the UI thread; safe from any goroutine.
Example ¶
Work off the UI thread reports back through Async; widgets are touched only on the UI thread.
package main
import (
"time"
"github.com/haiodo/gowt"
)
func main() {
_ = gowt.Run(func(app *gowt.App) {
w := app.Window("Download")
status := w.Label("working...")
w.Show()
go func() {
time.Sleep(time.Second) // stands for slow work
app.Async(func() { status.SetText("done") })
}()
})
}
Output:
func (*App) Clipboard ¶
Clipboard returns the system clipboard of the App, creating it on first use.
Example ¶
The clipboard belongs to the App; a setter fails with an error when the system clipboard is busy.
package main
import (
"fmt"
"log"
"github.com/haiodo/gowt"
)
func main() {
_ = gowt.Run(func(app *gowt.App) {
if err := app.Clipboard().SetText("hello"); err != nil {
log.Print(err)
return
}
text, ok := app.Clipboard().Text()
fmt.Println(text, ok)
})
}
Output:
func (*App) Dark ¶
Dark reports whether the system is in dark mode (macOS appearance, Windows apps theme, Linux xdg-desktop-portal color-scheme). Run keeps the app following it; call from the UI thread.
func (*App) ImageFromProvider ¶
func (a *App) ImageFromProvider(p swt.ImageDataProvider) *Image
ImageFromProvider creates an image from p, drawn at every zoom the provider answers for (for example svg.NewImageDataProvider). The App owns it and disposes it when Run returns, like the other images it created.
func (*App) OnThemeChange ¶
OnThemeChange runs f on the UI thread when the system switches between light and dark. Cached widget colors are already refreshed when f runs.
func (*App) Quit ¶
func (a *App) Quit()
Quit ends the event loop after the current event; safe from any goroutine.
func (*App) Sync ¶
func (a *App) Sync(f func())
Sync runs f on the UI thread and waits; safe from any goroutine except while the UI thread is blocked on you.
type Button ¶
type Button struct {
// contains filtered or unexported fields
}
Button is a push, check or radio button.
func (*Button) OnClick ¶
func (b *Button) OnClick(f func())
OnClick runs f when the button is pressed (or toggled).
func (*Button) SetChecked ¶
SetChecked sets the state of a Check or Radio button.
type CTabs ¶
type CTabs struct {
// contains filtered or unexported fields
}
CTabs is the custom-drawn tab folder: closable tabs (Closable on the folder's Tab) and a flatter look.
func (*CTabs) OnClose ¶
OnClose runs f with the index of the tab whose close button was pressed; false keeps the tab.
func (*CTabs) Tab ¶
Tab appends a tab and returns its page; Closable() adds a close button to the tab.
func (*CTabs) Unwrap ¶
func (t *CTabs) Unwrap() *swt.CTabFolder
Unwrap returns the underlying swt.CTabFolder for the full API.
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas is a blank area drawn by the paint callback.
func (*Canvas) Redraw ¶
func (c *Canvas) Redraw()
Redraw schedules a repaint, which calls the paint callback.
type Clipboard ¶
type Clipboard struct {
// contains filtered or unexported fields
}
Clipboard is the system clipboard. App.Clipboard creates it; the App disposes it when Run returns, so there is nothing to dispose. UI thread only (from another goroutine use App.Sync).
Getters return ok=false when the clipboard holds no such format. Setters return an error when the system clipboard cannot be written, which is routine on Windows while another process has it open. Setting one format clears the others; use SetHTML for HTML with a plain-text fallback. Other formats (RTF, URL, custom) and the X11 selection clipboard are reachable through Unwrap.
func (*Clipboard) Files ¶
Files returns the paths of the files copied in a file manager, nil if there are none.
func (*Clipboard) Image ¶
Image returns a copy of the image on the clipboard. The App owns it and disposes it when Run returns; Dispose may be called earlier.
func (*Clipboard) SetHTML ¶
SetHTML replaces the clipboard content with html and, for applications that do not read HTML, plain.
type Column ¶
type Column struct {
// contains filtered or unexported fields
}
Column is a table column.
func (*Column) OnClick ¶
func (c *Column) OnClick(f func())
OnClick runs f when the header is clicked, e.g. to sort.
func (*Column) Unwrap ¶
func (c *Column) Unwrap() *swt.TableColumn
Unwrap returns the underlying swt.TableColumn for the full API.
type Combo ¶
type Combo struct {
// contains filtered or unexported fields
}
Combo is a drop-down (or Simple) list with an edit field; ReadOnly() makes it a pure chooser.
type CoolBar ¶
type CoolBar struct {
// contains filtered or unexported fields
}
CoolBar is a tool bar area whose bands the user can rearrange.
func (CoolBar) AsComposite ¶
AsComposite returns the underlying composite; unlike Unwrap it has the same type on Panel, Window, Group, Split and CoolBar, so one function can take any of them.
func (CoolBar) Button ¶
Button adds a push button (Check or Radio for other kinds). onClick may be nil.
func (CoolBar) Canvas ¶
Canvas adds a drawing area. onPaint draws the whole area (clipped to the damaged part) and must not keep g; it may be nil. Call Redraw after the model changes.
func (CoolBar) CoolBar ¶
CoolBar adds a cool bar; create the band contents as its children, then Add them.
func (CoolBar) DateTime ¶
DateTime adds a date picker; DropDown() makes the date field a drop-down calendar.
func (CoolBar) Link ¶
Link adds a link label; onClick gets the href of the clicked anchor (its text if there is no href). onClick may be nil.
func (CoolBar) ShowTop ¶
func (p CoolBar) ShowTop(w Widget)
ShowTop makes w, a child of p, the visible one. p must have a Stack layout.
func (CoolBar) StyledText ¶
func (p CoolBar) StyledText(opts ...Option) *StyledText
StyledText adds a multi-line styled editor; options: Scrollbars, Wrap, ReadOnly, Border.
type DateTime ¶
type DateTime struct {
// contains filtered or unexported fields
}
DateTime is a date field, a time field (AsTime) or a month calendar (AsCalendar).
type Drag ¶
type Drag struct {
Ops Op // allowed operations, zero means OpCopy
Text func() string // plain text
Files func() []string // file paths
Image func() *Image // not disposed by the facade
OnStart func() bool // false cancels this drag; may be nil
OnDone func(op Op) // after the drop; OpNone if nobody took it; may be nil
}
Drag describes what a widget offers when the user drags from it. Every non-nil getter adds its format; getters run when a target asks for the data. Custom formats need swt.DragSource through Unwrap.
type DragHandle ¶
type DragHandle struct {
// contains filtered or unexported fields
}
DragHandle is the drag source created by DragFrom.
func DragFrom ¶
func DragFrom(w Widget, d Drag) *DragHandle
DragFrom makes w a drag source. A control has at most one; a second call panics with an SWT error that Run returns. The source is disposed with the widget.
func (*DragHandle) Unwrap ¶
func (h *DragHandle) Unwrap() *swt.DragSource
Unwrap returns the underlying swt.DragSource for the full API.
type Drop ¶
type Drop struct {
Ops Op // accepted operations, zero means OpCopy
Text func(text string, op Op) // plain text dropped
Files func(paths []string, op Op) // files dropped
Image func(img *Image, op Op) // image dropped; the App owns img (Dispose may be called earlier)
Over func(x, y int) bool // x, y in widget coordinates; false rejects the drop at that point; may be nil
}
Drop describes what a widget accepts. Every non-nil callback adds its format. Custom formats need swt.DropTarget through Unwrap.
type DropHandle ¶
type DropHandle struct {
// contains filtered or unexported fields
}
DropHandle is the drop target created by DropOn.
func DropOn ¶
func DropOn(w Widget, d Drop) *DropHandle
DropOn makes w a drop target. A control has at most one; a second call panics with an SWT error that Run returns. The target is disposed with the widget.
Example ¶
Any widget can be a drag source and a drop target; callbacks run on the UI thread.
package main
import (
"github.com/haiodo/gowt"
)
func main() {
_ = gowt.Run(func(app *gowt.App) {
w := app.Window("Drop")
zone := w.Label("drop files here")
gowt.DropOn(zone, gowt.Drop{Files: func(paths []string, _ gowt.Op) { zone.SetText(paths[0]) }})
w.Show()
})
}
Output:
func (*DropHandle) Unwrap ¶
func (h *DropHandle) Unwrap() *swt.DropTarget
Unwrap returns the underlying swt.DropTarget for the full API.
type Edge ¶
type Edge struct {
// contains filtered or unexported fields
}
Edge says where one side of a Form child sits. The zero Edge leaves the side free.
func Beside ¶
Beside attaches the side to the opposite side of w, gap points away: a left edge sits right of w.
type FileDialog ¶
type FileDialog struct {
Title, Dir, Name string
Save, Multi bool
Filters []FileFilter
}
FileDialog describes an open or save dialog.
type FileFilter ¶
type FileFilter struct{ Name, Pattern string }
FileFilter is one entry of the file type chooser; Pattern is "*.png;*.jpg", "*" matches all.
type Fill ¶
type Fill struct{ Vertical bool }
Fill lays children out in one row or column of equal size.
type Form ¶
type Form struct{ Margin, Spacing int }
Form positions each child by attaching its edges (see Anchor), which lets children stretch or follow siblings.
type FormCell ¶
FormCell places one child of a Form. Width and Height are hints in points, zero is natural size. A child with no edge set sticks to the top left.
type GC ¶
type GC struct {
// contains filtered or unexported fields
}
GC draws on a Canvas. It is valid only inside the paint callback it was passed to. Colors are set per call and need no disposal.
func (*GC) SetLineWidth ¶
SetLineWidth sets the outline width in pixels.
func (*GC) Text ¶
Text draws s with its top left at (x, y) over the fill color; tabs and newlines are honored.
type Grid ¶
Grid lays children out in Columns columns, left to right, top to bottom. Margin and Spacing are in points; zero means none (SWT's own defaults are 5 and 5).
Example ¶
Grid places children in columns; GridCell tunes one child.
package main
import (
"github.com/haiodo/gowt"
)
func main() {
_ = gowt.Run(func(app *gowt.App) {
w := app.Window("Form")
w.SetLayout(gowt.Grid{Columns: 2, Margin: 10, Spacing: 6})
w.Label("Name")
w.Text(gowt.Cell(gowt.GridCell{Align: gowt.AlignFill, GrowX: true}))
w.Label("Notes")
w.Text(gowt.Multiline(), gowt.Cell(gowt.GridCell{Align: gowt.AlignFill, GrowX: true, GrowY: true, Height: 80}))
w.Show()
})
}
Output:
type GridCell ¶
GridCell places one child inside a Grid. Zero value: natural size, top left, one cell. Align zero is AlignStart.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a container with a titled frame.
func (Group) AsComposite ¶
AsComposite returns the underlying composite; unlike Unwrap it has the same type on Panel, Window, Group, Split and CoolBar, so one function can take any of them.
func (Group) Button ¶
Button adds a push button (Check or Radio for other kinds). onClick may be nil.
func (Group) Canvas ¶
Canvas adds a drawing area. onPaint draws the whole area (clipped to the damaged part) and must not keep g; it may be nil. Call Redraw after the model changes.
func (Group) CoolBar ¶
CoolBar adds a cool bar; create the band contents as its children, then Add them.
func (Group) DateTime ¶
DateTime adds a date picker; DropDown() makes the date field a drop-down calendar.
func (Group) Link ¶
Link adds a link label; onClick gets the href of the clicked anchor (its text if there is no href). onClick may be nil.
func (Group) ShowTop ¶
func (p Group) ShowTop(w Widget)
ShowTop makes w, a child of p, the visible one. p must have a Stack layout.
func (Group) StyledText ¶
func (p Group) StyledText(opts ...Option) *StyledText
StyledText adds a multi-line styled editor; options: Scrollbars, Wrap, ReadOnly, Border.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image is a bitmap. The caller owns it: Dispose when done. Widgets that show an image (SetImage) do not take ownership and do not copy it, so keep it alive while shown. Images still alive when Run returns are disposed with the App.
type Label ¶
type Label struct {
// contains filtered or unexported fields
}
Label is a static text.
type Layout ¶
type Layout interface {
// contains filtered or unexported methods
}
Layout arranges the children of a Panel or Window.
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link is a label with clickable parts: text uses <a href="...">anchor</a>.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a single or multi (MultiSelect) selection list of strings.
func (*List) OnActivate ¶
OnActivate runs f on double click or Enter.
func (*List) SetSelection ¶
SetSelection replaces the selection.
type Menu ¶
type Menu struct {
// contains filtered or unexported fields
}
Menu is a menu bar, a popup menu or a submenu.
func PopupMenu ¶
PopupMenu creates the context menu of w. It is a function, not a method, because every wrapper would need its own copy; Show opens it by hand, right click opens it by itself.
func (*Menu) Item ¶
Item appends a push item (Check or Radio for other kinds). onClick may be nil. A "&" in text marks a mnemonic; text after "\t" is shown as the shortcut hint (it does not bind a key).
func (*Menu) OnShow ¶
func (m *Menu) OnShow(f func())
OnShow runs f just before the menu opens, to refresh enabled states.
type MenuItem ¶
type MenuItem struct {
// contains filtered or unexported fields
}
MenuItem is a menu entry.
func (*MenuItem) OnClick ¶
func (i *MenuItem) OnClick(f func())
OnClick runs f when the item is chosen (or toggled).
func (*MenuItem) SetChecked ¶
SetChecked sets the state of a check or radio item.
func (*MenuItem) SetEnabled ¶
SetEnabled enables or greys out the item.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a tree item. Nodes are re-wrapped on every lookup: keep per-node state in SetData.
func (*Node) SetChecked ¶
SetChecked sets the check box of a Check tree.
func (*Node) SetExpanded ¶
SetExpanded shows or hides the children.
type Op ¶
type Op int
Op is a drag and drop operation. In Drag.Ops and Drop.Ops the zero value means OpCopy.
const ( OpNone Op = Op(swt.DNDDROP_NONE) OpCopy Op = Op(swt.DNDDROP_COPY) OpMove Op = Op(swt.DNDDROP_MOVE) OpLink Op = Op(swt.DNDDROP_LINK) )
The operations a drag may offer and a drop may accept; OpNone reports a drag nobody accepted.
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option adjusts a widget at construction: style bits are OR-ed before creation, apply runs after.
func Anchor ¶
Anchor sets the position of a child laid out by Form. Edges that refer to a sibling need that sibling to exist already.
func AsTime ¶
func AsTime() Option
AsTime and AsCalendar turn a DateTime from a date field into a time field or a month calendar.
func Check ¶
func Check() Option
Check makes a Button a check box, and Table and Tree rows and ToolBar items checkable. Radio, Multiline, Password, ReadOnly and Border follow below.
func Custom ¶
Custom runs f on the widget right after it is created and sets no style bits. It lets a package outside gowt adjust the swt control.
func DropDown ¶
func DropDown() Option
DropDown makes a DateTime date field a drop-down calendar, or a ToolBar item a drop-down.
func MultiSelect ¶
func MultiSelect() Option
MultiSelect allows several selected items in a List, Table or Tree.
func Multiline ¶
func Multiline() Option
Multiline makes a Text multi-line, wrapped, with a vertical scroll bar.
func Scrollbars ¶
func Scrollbars() Option
Scrollbars gives a StyledText vertical and horizontal scroll bars (they appear when needed).
type Panel ¶
type Panel struct {
// contains filtered or unexported fields
}
Panel is a plain container; Window, Group, Split and CoolBar embed its methods.
func (Panel) AsComposite ¶
AsComposite returns the underlying composite; unlike Unwrap it has the same type on Panel, Window, Group, Split and CoolBar, so one function can take any of them.
func (Panel) Button ¶
Button adds a push button (Check or Radio for other kinds). onClick may be nil.
func (Panel) Canvas ¶
Canvas adds a drawing area. onPaint draws the whole area (clipped to the damaged part) and must not keep g; it may be nil. Call Redraw after the model changes.
Example ¶
The paint callback draws the whole area; call Redraw after the model changes.
package main
import (
"github.com/haiodo/gowt"
)
func main() {
_ = gowt.Run(func(app *gowt.App) {
w := app.Window("Canvas")
w.Canvas(func(g *gowt.GC) {
g.SetFill(gowt.RGB{R: 30, G: 120, B: 220})
g.FillOval(10, 10, 100, 60)
}, gowt.Cell(gowt.GridCell{Width: 200, Height: 100}))
w.Show()
})
}
Output:
func (Panel) CoolBar ¶
CoolBar adds a cool bar; create the band contents as its children, then Add them.
func (Panel) DateTime ¶
DateTime adds a date picker; DropDown() makes the date field a drop-down calendar.
func (Panel) Link ¶
Link adds a link label; onClick gets the href of the clicked anchor (its text if there is no href). onClick may be nil.
func (Panel) ShowTop ¶
func (p Panel) ShowTop(w Widget)
ShowTop makes w, a child of p, the visible one. p must have a Stack layout.
func (Panel) StyledText ¶
func (p Panel) StyledText(opts ...Option) *StyledText
StyledText adds a multi-line styled editor; options: Scrollbars, Wrap, ReadOnly, Border.
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress is a progress bar; Vertical() rotates it, Indeterminate() animates it without a value.
func (*Progress) Unwrap ¶
func (p *Progress) Unwrap() *swt.ProgressBar
Unwrap returns the underlying swt.ProgressBar for the full API.
type Row ¶
Row lays children out in a row (or column with Vertical) at their natural size, wrapping if Wrap is set. Fill stretches every child to the row's full height (width for Vertical), Center centers them.
type RowCell ¶
type RowCell struct{ Width, Height int }
RowCell sets the size of one child of a Row; zero means natural size.
type Sash ¶
type Sash struct {
// contains filtered or unexported fields
}
Sash is a bare draggable divider; most code wants Split instead. The sash does not move itself: OnMove must lay it out (Unwrap gives the layout data).
type Scale ¶
type Scale struct {
// contains filtered or unexported fields
}
Scale is a slider with tick marks; Vertical() rotates it.
type Scroll ¶
type Scroll struct {
// contains filtered or unexported fields
}
Scroll shows content larger than itself with scroll bars. Build the content in Content, then call Fit.
func (*Scroll) Fit ¶
func (s *Scroll) Fit()
Fit sets the scrollable size to the content's natural size; call it after the content is built.
func (*Scroll) Unwrap ¶
func (s *Scroll) Unwrap() *swt.ScrolledComposite
Unwrap returns the underlying swt.ScrolledComposite for the full API.
type Slider ¶
type Slider struct {
// contains filtered or unexported fields
}
Slider is a scroll-bar style control; Vertical() rotates it.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner is an integer edit field with arrows.
func (*Spinner) OnChange ¶
OnChange runs f with the new value after the arrows or typing changed it.
type Split ¶
type Split struct {
// contains filtered or unexported fields
}
Split divides its children with draggable sashes; the children are ordinary Panel children.
func (Split) AsComposite ¶
AsComposite returns the underlying composite; unlike Unwrap it has the same type on Panel, Window, Group, Split and CoolBar, so one function can take any of them.
func (Split) Button ¶
Button adds a push button (Check or Radio for other kinds). onClick may be nil.
func (Split) Canvas ¶
Canvas adds a drawing area. onPaint draws the whole area (clipped to the damaged part) and must not keep g; it may be nil. Call Redraw after the model changes.
func (Split) CoolBar ¶
CoolBar adds a cool bar; create the band contents as its children, then Add them.
func (Split) DateTime ¶
DateTime adds a date picker; DropDown() makes the date field a drop-down calendar.
func (Split) Link ¶
Link adds a link label; onClick gets the href of the clicked anchor (its text if there is no href). onClick may be nil.
func (*Split) SetWeights ¶
SetWeights sets the relative size of each child, one weight per child.
func (Split) ShowTop ¶
func (p Split) ShowTop(w Widget)
ShowTop makes w, a child of p, the visible one. p must have a Stack layout.
func (Split) StyledText ¶
func (p Split) StyledText(opts ...Option) *StyledText
StyledText adds a multi-line styled editor; options: Scrollbars, Wrap, ReadOnly, Border.
type Stack ¶
type Stack struct{ Margin int }
Stack shows one child at a time, all at the full size of the container; choose it with Panel.ShowTop.
type StyledText ¶
type StyledText struct {
// contains filtered or unexported fields
}
StyledText is a multi-line editor with per-range styles. All offsets and lengths are in runes, i.e. indexes into []rune(Text()); the facade converts to the UTF-16 units SWT uses. Each conversion scans the text, O(n) per call: fine for documents up to some hundred kilobytes; for larger ones keep a line index and use Unwrap with SWT offsets.
Not wrapped (use Unwrap): bullets, line alignment and indent, glyph metrics, underline styles and colors, block selection, verify and extended-modify listeners (undo), bidi segments, custom content.
Example ¶
StyledText offsets are runes; spans style ranges of the text.
package main
import (
"github.com/haiodo/gowt"
)
func main() {
_ = gowt.Run(func(app *gowt.App) {
w := app.Window("Editor")
ed := w.StyledText(gowt.Scrollbars())
ed.SetText("bold word")
ed.SetStyle(0, 4, gowt.TextStyle{Bold: true})
w.Show()
})
}
Output:
func (*StyledText) ClearStyles ¶
func (t *StyledText) ClearStyles()
ClearStyles removes every style.
func (*StyledText) Copy ¶
func (t *StyledText) Copy()
Copy copies the selection to the system clipboard.
func (*StyledText) Cut ¶
func (t *StyledText) Cut()
Cut moves the selection to the system clipboard.
func (*StyledText) LineAt ¶
func (t *StyledText) LineAt(offset int) int
LineAt returns the line index that holds the rune offset.
func (*StyledText) LineStart ¶
func (t *StyledText) LineStart(line int) int
LineStart returns the rune offset of the first character of line.
func (*StyledText) OnCaret ¶
func (t *StyledText) OnCaret(f func(offset int))
OnCaret runs f with the caret position after it moved.
func (*StyledText) OnChange ¶
func (t *StyledText) OnChange(f func(text string))
OnChange runs f with the new content after every edit.
func (*StyledText) OnSelect ¶
func (t *StyledText) OnSelect(f func(start, length int))
OnSelect runs f with the selection after it changed.
func (*StyledText) OnStyle ¶
func (t *StyledText) OnStyle(f func(line string) []StyleSpan)
OnStyle runs f each time a line is drawn; the spans it returns style that line only. Start is counted in runes from the beginning of the line, so no whole-text conversion happens per repaint. f must not change the text.
func (*StyledText) Paste ¶
func (t *StyledText) Paste()
Paste inserts the system clipboard text at the caret.
func (*StyledText) Replace ¶
func (t *StyledText) Replace(start, length int, s string)
Replace replaces length runes from start with s.
func (*StyledText) Reveal ¶
func (t *StyledText) Reveal()
Reveal scrolls so that the selection is visible.
func (*StyledText) SelectedText ¶
func (t *StyledText) SelectedText() string
SelectedText returns the selected text.
func (*StyledText) Selection ¶
func (t *StyledText) Selection() (start, length int)
Selection returns the selected range; length is 0 when only the caret is set.
func (*StyledText) SetEditable ¶
func (t *StyledText) SetEditable(on bool)
SetEditable allows or forbids typing.
func (*StyledText) SetLineBackground ¶
func (t *StyledText) SetLineBackground(line, count int, c RGB)
SetLineBackground colors count lines from line.
func (*StyledText) SetSelection ¶
func (t *StyledText) SetSelection(start, length int)
SetSelection selects length runes from start.
func (*StyledText) SetStyle ¶
func (t *StyledText) SetStyle(start, length int, s TextStyle)
SetStyle applies s to length runes from start, replacing the styles there.
func (*StyledText) SetTabs ¶
func (t *StyledText) SetTabs(n int)
SetTabs sets the tab width in spaces.
func (*StyledText) SetText ¶
func (t *StyledText) SetText(s string)
SetText replaces the whole content.
func (*StyledText) SetTopLine ¶
func (t *StyledText) SetTopLine(line int)
SetTopLine scrolls so that line is the first visible one.
func (*StyledText) SetWrap ¶
func (t *StyledText) SetWrap(on bool)
SetWrap turns word wrapping on or off.
func (*StyledText) Styles ¶
func (t *StyledText) Styles() []StyleSpan
Styles returns the styled ranges in order. Font is not reported.
func (*StyledText) Unwrap ¶
func (t *StyledText) Unwrap() *swt.StyledText
Unwrap returns the underlying swt.StyledText for the full API (offsets there are UTF-16 units).
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a multi-column grid with a header; rows are added with Row. Check makes rows checkable.
Example ¶
Table rows hold one text per column; SetData keeps an application value with a row.
package main
import (
"fmt"
"github.com/haiodo/gowt"
)
func main() {
_ = gowt.Run(func(app *gowt.App) {
w := app.Window("Files")
t := w.Table()
t.Column("Name", 200)
t.Column("Size", 80, gowt.Right())
t.Row("a.txt", "12").SetData("id-1")
t.OnSelect(func(i int) { fmt.Println(t.RowAt(i).Data()) })
w.Show()
})
}
Output:
func (*Table) OnActivate ¶
OnActivate runs f on double click or Enter.
func (*Table) SetSelection ¶
SetSelection replaces the selection.
func (*Table) ShowHeader ¶
ShowHeader shows or hides the column headers.
type TableRow ¶
type TableRow struct {
// contains filtered or unexported fields
}
TableRow is a table row. Rows are re-wrapped on every lookup: keep per-row state in SetData.
func (*TableRow) SetChecked ¶
SetChecked sets the check box of a Check table.
type Tabs ¶
type Tabs struct {
// contains filtered or unexported fields
}
Tabs is a native tab folder; each Tab returns the page container.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text is an edit field.
func (*Text) OnActivate ¶
func (t *Text) OnActivate(f func())
OnActivate runs f when the user presses Enter in a single-line field.
type TextStyle ¶
type TextStyle struct {
Foreground, Background *RGB
Bold, Italic bool
Underline, Strikeout bool
Font *Font // a typeface other than the widget's; the widget owns the native font
}
TextStyle is the look of a range of a StyledText. Nil colors inherit the widget's.
type ToolBar ¶
type ToolBar struct {
// contains filtered or unexported fields
}
ToolBar is a row of tool buttons.
type ToolItem ¶
type ToolItem struct {
// contains filtered or unexported fields
}
ToolItem is a tool bar button.
func (*ToolItem) OnClick ¶
func (i *ToolItem) OnClick(f func())
OnClick runs f when the item is pressed (or toggled).
func (*ToolItem) SetChecked ¶
SetChecked sets the state of a Check or Radio item.
func (*ToolItem) SetEnabled ¶
SetEnabled enables or greys out the item.
func (*ToolItem) SetTooltip ¶
SetTooltip sets the text shown on hover.
type TrayIcon ¶
type TrayIcon struct {
// contains filtered or unexported fields
}
TrayIcon is an icon in the system tray / status area.
func (*TrayIcon) OnClick ¶
func (t *TrayIcon) OnClick(f func())
OnClick runs f when the icon is clicked.
func (*TrayIcon) SetTooltip ¶
SetTooltip sets the text shown on hover.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is a hierarchy of Nodes. Check makes nodes checkable, MultiSelect allows several selected.
func (*Tree) OnActivate ¶
OnActivate runs f on double click or Enter.
func (*Tree) OnCollapse ¶
OnCollapse runs f with the node that was collapsed; see OnExpand.
func (*Tree) OnExpand ¶
OnExpand and OnCollapse run f with the node that changed. The event carries the item as a bare *swt.Widget that cannot be downcast, so the node is found by walking the tree.
type Widget ¶
type Widget interface {
// contains filtered or unexported methods
}
Widget is any gowt control. Layouts and containers take it where they refer to a sibling or a child.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window is a top-level window.
func (Window) AsComposite ¶
AsComposite returns the underlying composite; unlike Unwrap it has the same type on Panel, Window, Group, Split and CoolBar, so one function can take any of them.
func (Window) Button ¶
Button adds a push button (Check or Radio for other kinds). onClick may be nil.
func (Window) Canvas ¶
Canvas adds a drawing area. onPaint draws the whole area (clipped to the damaged part) and must not keep g; it may be nil. Call Redraw after the model changes.
func (*Window) Close ¶
func (w *Window) Close()
Close closes the window as the user would, running OnClose.
func (*Window) ColorDialog ¶
ColorDialog shows a color chooser starting at initial; ok is false if cancelled.
func (*Window) Confirm ¶
Confirm asks a Yes/No question and reports whether Yes was pressed.
Example ¶
A modal question over a window.
package main
import (
"github.com/haiodo/gowt"
)
func main() {
_ = gowt.Run(func(app *gowt.App) {
w := app.Window("Editor")
w.Button("Quit", func() {
if w.Confirm("Quit", "Discard unsaved changes?") {
w.Close()
}
})
w.Show()
})
}
Output:
func (Window) CoolBar ¶
CoolBar adds a cool bar; create the band contents as its children, then Add them.
func (Window) DateTime ¶
DateTime adds a date picker; DropDown() makes the date field a drop-down calendar.
func (*Window) FileDialog ¶
func (w *Window) FileDialog(d FileDialog) []string
FileDialog shows d modal over w and returns the chosen paths, nil if cancelled. Multi only applies to open dialogs.
func (*Window) FontDialog ¶
FontDialog shows a font chooser starting at initial; ok is false if cancelled.
func (Window) Link ¶
Link adds a link label; onClick gets the href of the clicked anchor (its text if there is no href). onClick may be nil.
func (*Window) MenuBar ¶
MenuBar creates the window's menu bar. On macOS it becomes the application menu bar.
func (*Window) MessageBox ¶
MessageBox shows m modal over w and returns the pressed button.
func (*Window) SetLayout ¶
SetLayout installs l and returns the window as a Panel; a top inset set earlier is kept.
func (*Window) SetTopInset ¶
SetTopInset adds points to the top margin of the window layout (Grid, Row and Form; other layouts ignore it), on top of the layout's own Margin. look.SetFullSizeContent uses it to keep the content below the title bar and the toolbar.
func (*Window) Show ¶
func (w *Window) Show()
Show packs the window to its content size (unless SetSize was called) and opens it.
func (Window) ShowTop ¶
func (p Window) ShowTop(w Widget)
ShowTop makes w, a child of p, the visible one. p must have a Stack layout.
func (Window) StyledText ¶
func (p Window) StyledText(opts ...Option) *StyledText
StyledText adds a multi-line styled editor; options: Scrollbars, Wrap, ReadOnly, Border.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
The WebBrowser behind SWT's Browser: package webview is the engine, standing in for SWT's own WebKit/Edge/WebKitGTK classes (manual.txt, port.sh).
|
The WebBrowser behind SWT's Browser: package webview is the engine, standing in for SWT's own WebKit/Edge/WebKitGTK classes (manual.txt, port.sh). |
|
cmd
|
|
|
backdropdemo
command
Command backdropdemo switches the window material (none / translucent = Acrylic / glass = Mica) and the rounded corners.
|
Command backdropdemo switches the window material (none / translucent = Acrylic / glass = Mica) and the rounded corners. |
|
controlexample
command
Command controlexample runs SWT's ControlExample (examples/controlexample, translated by j2go) with the tabs translated so far.
|
Command controlexample runs SWT's ControlExample (examples/controlexample, translated by j2go) with the tabs translated so far. |
|
form
command
Command form: a two-column Grid form (Name/Email + OK) with a File > Quit menu bar.
|
Command form: a two-column Grid form (Name/Email + OK) with a File > Quit menu bar. |
|
glassdemo
command
Command glassdemo shows the macOS 26 look options: window backdrop, glass panel, glass buttons, full-size content.
|
Command glassdemo shows the macOS 26 look options: window backdrop, glass panel, glass buttons, full-size content. |
|
gowtdemo
command
Command gowtdemo shows the gowt facade widgets, one tab per widget family.
|
Command gowtdemo shows the gowt facade widgets, one tab per widget family. |
|
hello
command
Command hello opens a Shell with one push button: the Display+Shell+Button path end to end.
|
Command hello opens a Shell with one push button: the Display+Shell+Button path end to end. |
|
hellogowt
command
Command hellogowt is the smallest gowt program: a window with a field, a button and a label.
|
Command hellogowt is the smallest gowt program: a window with a field, a button and a label. |
|
icondemo
command
Command icondemo shows every dictionary icon as a button and rebuilds them when the system theme changes.
|
Command icondemo shows every dictionary icon as a button and rebuilds them when the system theme changes. |
|
images
command
Command images loads 3 of the ControlExample test images through getResourceAsStream -> ImageData(InputStream) -> Image(Display, ImageData), and draws them on a Canvas with gc.DrawImage.
|
Command images loads 3 of the ControlExample test images through getResourceAsStream -> ImageData(InputStream) -> Image(Display, ImageData), and draws them on a Canvas with gc.DrawImage. |
|
jfacedemo
command
Command jfacedemo builds a form from JFace's fluent widget factories and layout factories only: labels, texts and a group, a table under a TableColumnLayout, and a row of buttons.
|
Command jfacedemo builds a form from JFace's fluent widget factories and layout factories only: labels, texts and a group, a table under a TableColumnLayout, and a row of buttons. |
|
minibrowser
command
Command minibrowser is a small tabbed browser: a SashForm with the list of open pages on the left and one WebView per page, stacked, on the right.
|
Command minibrowser is a small tabbed browser: a SashForm with the list of open pages on the left and one WebView per page, stacked, on the right. |
|
paint
command
Command paint draws on a Canvas from a paint callback: the drawRect: -> paint event -> GC path.
|
Command paint draws on a Canvas from a paint callback: the drawRect: -> paint event -> GC path. |
|
snapcheck
command
Command snapcheck compares the PNGs written by `controlexample -snap` with the committed references (tests/snapshots).
|
Command snapcheck compares the PNGs written by `controlexample -snap` with the committed references (tests/snapshots). |
|
stack
command
Command stack: a Split divides left (buttons) from right (a Stack of Groups); clicking a button switches the visible panel.
|
Command stack: a Split divides left (buttons) from right (a Stack of Groups); clicking a button switches the visible panel. |
|
swttest
command
Command swttest runs the translated SWT JUnit tests (tests/swttests) on the main thread with one Display, the way SWT's tests expect: a panic fails its test, not the run; a hung test ends the run with its name.
|
Command swttest runs the translated SWT JUnit tests (tests/swttests) on the main thread with one Display, the way SWT's tests expect: a panic fails its test, not the run; a hung test ends the run with its name. |
|
themecheck
command
Command themecheck shows the system theme and logs every change: switch light/dark in system settings while it runs and the label and stdout must follow (Linux: GOWT_THEMECHECK_SECS=n exits after n seconds).
|
Command themecheck shows the system theme and logs every change: switch light/dark in system settings while it runs and the label and stdout must follow (Linux: GOWT_THEMECHECK_SECS=n exits after n seconds). |
|
tree
command
Command tree shows a Tree (NSOutlineView) with three root items and their children.
|
Command tree shows a Tree (NSOutlineView) with three root items and their children. |
|
webviewdemo
command
Command webviewdemo shows a Tree beside a system web view: the pages come from an embed.FS over the app:// scheme, a button evaluates JS in the page, and page messages land in a Label.
|
Command webviewdemo shows a Tree beside a system web view: the pages come from an embed.FS over the app:// scheme, a button evaluates JS in the page, and page messages land in a Label. |
|
widgets2
command
Command widgets2 shows a Tabs holding a Combo pair, a Table, and a Scroll.
|
Command widgets2 shows a Tabs holding a Combo pair, a Table, and a Scroll. |
|
winprobe
command
|
|
|
examples
|
|
|
browser
command
Command browser uses SWT's Browser widget (package browser) inside a gowt window.
|
Command browser uses SWT's Browser widget (package browser) inside a gowt window. |
|
catalog
command
Command catalog shows one sample of every facade widget.
|
Command catalog shows one sample of every facade widget. |
|
clipboard
command
Command clipboard copies a field's text to the system clipboard and pastes it back.
|
Command clipboard copies a field's text to the system clipboard and pastes it back. |
|
controlexample
Hand-written glue for the translated ControlExample (tooling/j2go/manual.txt, README "Round 10 controlexample").
|
Hand-written glue for the translated ControlExample (tooling/j2go/manual.txt, README "Round 10 controlexample"). |
|
controlexample/res
Package res embeds the ControlExample resources.
|
Package res embeds the ControlExample resources. |
|
dialogs
command
Command dialogs shows a menu bar, a context menu, a tool bar and the modal dialogs.
|
Command dialogs shows a menu bar, a context menu, a tool bar and the modal dialogs. |
|
dnd
command
Command dnd drags a label's text onto a drop zone and accepts files dropped from a file manager.
|
Command dnd drags a label's text onto a drop zone and accepts files dropped from a file manager. |
|
events
command
Command events shows callbacks, the UI thread rule and background work reporting back.
|
Command events shows callbacks, the UI thread rule and background work reporting back. |
|
graphics
command
Command graphics draws on a Canvas and shows an Image built in memory.
|
Command graphics draws on a Canvas and shows an Image built in memory. |
|
hello
command
Command hello is the smallest gowt program: one window, a label and a button.
|
Command hello is the smallest gowt program: one window, a label and a button. |
|
icons
command
Command icons puts named system icons on buttons and tints them again when the theme changes.
|
Command icons puts named system icons on buttons and tints them again when the theme changes. |
|
jface
command
Command jface builds one window from gowt containers and JFace factories: the grid layout and the label, text field and button come from package jface, the status line is a gowt widget.
|
Command jface builds one window from gowt containers and JFace factories: the grid layout and the label, text field and button come from package jface, the status line is a gowt widget. |
|
layouts
command
Command layouts shows the five layouts: Grid, Row, Fill, Form and Stack.
|
Command layouts shows the five layouts: Grid, Row, Fill, Form and Stack. |
|
styledtext
command
Command styledtext highlights words in an editor.
|
Command styledtext highlights words in an editor. |
|
swtdirect
command
Command swtdirect drops from the facade to package swt for what the facade does not wrap: Unwrap gives the swt object of a widget, AsComposite the parent for a raw swt widget.
|
Command swtdirect drops from the facade to package swt for what the facade does not wrap: Unwrap gives the swt object of a widget, AsComposite the parent for a raw swt widget. |
|
theme
command
Command theme follows the system light/dark setting and tries the platform look options of package look.
|
Command theme follows the system light/dark setting and tries the platform look options of package look. |
|
webview
command
Command webview puts the system web view beside native widgets: a page served from Go over a custom scheme, a script run from a button, and messages from the page into a Label.
|
Command webview puts the system web view beside native widgets: a page served from Go over a custom scheme, a script run from a button, and messages from the page into a Label. |
|
widgets
command
Command widgets shows the common widgets: text fields, buttons, lists, a table, a tree and ranges.
|
Command widgets shows the common widgets: text fields, buttons, lists, a table, a tree and ranges. |
|
internal
|
|
|
cocoa
ObjC blocks over purego: a block literal is {isa, flags, reserved, invoke, descriptor}.
|
ObjC blocks over purego: a block literal is {isa, flags, reserved, invoke, descriptor}. |
|
gtk
Package gtk binds GTK 3, GLib, Pango and cairo through purego (no cgo): gen_*.go come from GIR via tooling/girgen, glue_*.go are hand-written from the public GTK/GLib documentation.
|
Package gtk binds GTK 3, GLib, Pango and cairo through purego (no cgo): gen_*.go come from GIR via tooling/girgen, glue_*.go are hand-written from the public GTK/GLib documentation. |
|
jrt
Package jrt hand-writes small Go stand-ins for the java.lang/java.util base types that some translated SWT classes extend (SWTException/SWTError extend RuntimeException/Error, TypedEvent extends EventObject) but that have no Java source for j2go to translate - see tooling/j2go/README.md "Manual superclass embedding".
|
Package jrt hand-writes small Go stand-ins for the java.lang/java.util base types that some translated SWT classes extend (SWTException/SWTError extend RuntimeException/Error, TypedEvent extends EventObject) but that have no Java source for j2go to translate - see tooling/j2go/README.md "Manual superclass embedding". |
|
junit
Package junit is the JUnit 5 surface the translated SWT tests (tests/swttests) use: the generated test registry and org.junit.jupiter.api.Assertions/Assumptions.
|
Package junit is the JUnit 5 surface the translated SWT tests (tests/swttests) use: the generated test registry and org.junit.jupiter.api.Assertions/Assumptions. |
|
shot
Package shot captures a Shell's window on linux for the snapshot commands (cmd/controlexample -snap, cmd/images).
|
Package shot captures a Shell's window on linux for the snapshot commands (cmd/controlexample -snap, cmd/images). |
|
snapcmp
Package snapcmp compares two screenshots with a per-pixel tolerance (stdlib only, no GUI).
|
Package snapcmp compares two screenshots with a per-pixel tolerance (stdlib only, no GUI). |
|
webkit
Package webkit binds WebKitGTK 4.1 (GTK 3) through purego, without cgo.
|
Package webkit binds WebKitGTK 4.1 (GTK 3) through purego, without cgo. |
|
win32
toC/fromC of the C bitfield structs Uniscribe and GetMenuBarInfo use: a Java boolean per bit, packed as the C compiler does (LSB first in the declared storage unit).
|
toC/fromC of the C bitfield structs Uniscribe and GetMenuBarInfo use: a Java boolean per bit, packed as the C compiler does (LSB first in the declared storage unit). |
|
Package look sets the platform look of a gowt app: the window material, macOS 26 Liquid Glass, Windows 11 corners and dark content.
|
Package look sets the platform look of a gowt app: the window material, macOS 26 Liquid Glass, Windows 11 corners and dark content. |
|
Package svg is gowt's optional SVG rasterizer (the counterpart of SWT's org.eclipse.swt.svg fragment): importing it for its side effect makes swt.Image load SVG at every zoom.
|
Package svg is gowt's optional SVG rasterizer (the counterpart of SWT's org.eclipse.swt.svg fragment): importing it for its side effect makes swt.Image load SVG at every zoom. |
|
The PNG/GIF/BMP/JPEG codec backend is not translated from SWT's org.eclipse.swt.internal.image (FileFormat + PNGFileFormat/GIFFileFormat/WinBMPFileFormat/OS2BMPFileFormat/LZW*/Png*/LEData*): it is a hand-written wrapper over Go's stdlib image codecs plus golang.org/x/image/bmp instead.
|
The PNG/GIF/BMP/JPEG codec backend is not translated from SWT's org.eclipse.swt.internal.image (FileFormat + PNGFileFormat/GIFFileFormat/WinBMPFileFormat/OS2BMPFileFormat/LZW*/Png*/LEData*): it is a hand-written wrapper over Go's stdlib image codecs plus golang.org/x/image/bmp instead. |
|
swtreflect
Package swtreflect registers the public methods of package swt's widgets for java.lang.reflect-style lookup (internal/jrt/reflect.go).
|
Package swtreflect registers the public methods of package swt's widgets for java.lang.reflect-style lookup (internal/jrt/reflect.go). |
|
tests
|
|
|
swttests
Package swttests is SWT's JUnit tests (org.eclipse.swt.tests.junit) translated by j2go; each test class registers itself with internal/junit, cmd/swttest runs them on the main thread.
|
Package swttests is SWT's JUnit tests (org.eclipse.swt.tests.junit) translated by j2go; each test class registers itself with internal/junit, cmd/swttest runs them on the main thread. |
|
tooling
|
|
|
apidump
command
Command apidump prints the exported API of package swt for one GOOS, one symbol per line, sorted: package-level funcs/vars/consts/types and the full method set (promoted included) of every exported type.
|
Command apidump prints the exported API of package swt for one GOOS, one symbol per line, sorted: package-level funcs/vars/consts/types and the full method set (promoted included) of every exported type. |
|
girgen
command
girgen emits internal/gtk (purego bindings) from GIR files for exactly the names the SWT widget code uses; the call-site names are the interface spec (see README, "GIR-driven gtk binding").
|
girgen emits internal/gtk (purego bindings) from GIR files for exactly the names the SWT widget code uses; the call-site names are the interface spec (see README, "GIR-driven gtk binding"). |
|
mksyso
command
Command mksyso writes a COFF object with one RT_MANIFEST resource (ID 1), for go build to link into a Windows executable: mksyso -arch amd64|arm64 -manifest app.manifest -o out.syso.
|
Command mksyso writes a COFF object with one RT_MANIFEST resource (ID 1), for go build to link into a Windows executable: mksyso -arch amd64|arm64 -manifest app.manifest -o out.syso. |
|
webkitgen
command
webkitgen emits internal/webkit/gen_funcs.go: purego prototypes for the C functions named in names.txt, with parameter and return types taken from the GIR files of WebKitGTK 4.1 and the libraries it sits on.
|
webkitgen emits internal/webkit/gen_funcs.go: purego prototypes for the C functions named in names.txt, with parameter and return types taken from the GIR files of WebKitGTK 4.1 and the libraries it sits on. |
|
Package webview embeds the system web view (WKWebView on macOS, WebKitGTK 4.1 on Linux) in an SWT Composite and bridges it to Go: custom URL schemes served from Go, page-to-Go messages, async script evaluation.
|
Package webview embeds the system web view (WKWebView on macOS, WebKitGTK 4.1 on Linux) in an SWT Composite and bridges it to Go: custom URL schemes served from Go, page-to-Go messages, async script evaluation. |
|
Package winmanifest embeds an application manifest into a Windows executable: comctl32 v6 (visual styles, SysLink) and per-monitor DPI awareness (v2, falling back to per-monitor and system-aware on older Windows).
|
Package winmanifest embeds an application manifest into a Windows executable: comctl32 v6 (visual styles, SysLink) and per-monitor DPI awareness (v2, falling back to per-monitor and system-aware on older Windows). |


