README
¶
gocoa
Go bindings for the Cocoa framework to build macOS applications.

How to use
The following is a basic Hello World application.
package main
import (
"fmt"
"github.com/mojbro/gocoa"
)
func main() {
gocoa.InitApplication()
gocoa.OnApplicationDidFinishLaunching(func() {
fmt.Println("App running!")
})
wnd := gocoa.NewWindow("Hello World!", 150, 150, 300, 200)
// Change me button
currentTitle, nextTitle := "Change me!", "Change me again!"
changeButton := gocoa.NewButton(75, 125, 150, 25)
changeButton.SetTitle(currentTitle)
changeButton.OnClick(func() {
changeButton.SetTitle(nextTitle)
currentTitle, nextTitle = nextTitle, currentTitle
})
wnd.AddButton(changeButton)
// Quit button
quitButton := gocoa.NewButton(75, 50, 150, 25)
quitButton.SetTitle("Quit")
quitButton.OnClick(func() { gocoa.TerminateApplication() })
wnd.AddButton(quitButton)
wnd.MakeKeyAndOrderFront()
gocoa.RunApplication()
}
Status of this project
This package is very, very early and incomplete! It is mostly just an experiment and is not really useful yet.
Contributors
Big thanks to Philipp Haussleiter who has contributed a great deal to this project.
Documentation
¶
Overview ¶
Package gocoa - Go bindings for the Cocoa framework. It is currently in early stage development and not very usable yet.
Index ¶
- Constants
- func InitApplication()
- func OnApplicationDidFinishLaunching(fn func())
- func RunApplication()
- func TerminateApplication()
- type Button
- func (btn *Button) OnClick(fn func())
- func (btn *Button) SetBackgroundColor(hexRGBA string)
- func (btn *Button) SetBezelStyle(bezelStyle ButtonBezelStyle)
- func (btn *Button) SetBorderColor(hexRGBA string)
- func (btn *Button) SetBorderWidth(borderWidth int)
- func (btn *Button) SetButtonType(buttonType ButtonType)
- func (btn *Button) SetColor(hexRGBA string)
- func (btn *Button) SetFontFamily(fontFamily string)
- func (btn *Button) SetFontSize(fontSize int)
- func (btn *Button) SetState(state ButtonState)
- func (btn *Button) SetTitle(title string)
- func (btn *Button) State() ButtonState
- func (btn *Button) Title() string
- type ButtonBezelStyle
- type ButtonState
- type ButtonType
- type ComboBox
- func (comboBox *ComboBox) AddItem(item string)
- func (comboBox *ComboBox) OnSelectionDidChange(fn func())
- func (comboBox *ComboBox) SelectedIndex() int
- func (comboBox *ComboBox) SelectedText() string
- func (comboBox *ComboBox) SetEditable(editable bool)
- func (comboBox *ComboBox) SetSelectedIndex(selectedIndex int)
- func (comboBox *ComboBox) SetSelectedText(selectedText string)
- func (comboBox *ComboBox) SetStringValue(stringValue string)
- func (comboBox *ComboBox) StringValue() string
- type DatePicker
- func (datePicker *DatePicker) Date() string
- func (datePicker *DatePicker) SetDate(date string)
- func (datePicker *DatePicker) SetDateFormat(dateFormat string)
- func (datePicker *DatePicker) SetMaximumDate(date string)
- func (datePicker *DatePicker) SetMinimumDate(date string)
- func (datePicker *DatePicker) SetMode(mode DatePickerMode)
- func (datePicker *DatePicker) SetStyle(style DatePickerStyle)
- type DatePickerMode
- type DatePickerStyle
- type EventHandler
- type FrameStyle
- type ImageAlignment
- type ImageScaling
- type ImageView
- func (imageView *ImageView) SetAnimates(animates bool)
- func (imageView *ImageView) SetContentTintColor(hexRGBA string)
- func (imageView *ImageView) SetEditable(editable bool)
- func (imageView *ImageView) SetImageAlignment(imageAlignment ImageAlignment)
- func (imageView *ImageView) SetImageFrameStyle(frameStyle FrameStyle)
- func (imageView *ImageView) SetImageScaling(imageScaling ImageScaling)
- type ProgressIndicator
- func (indicator *ProgressIndicator) GetIsIndeterminate() bool
- func (indicator *ProgressIndicator) GetValue() float64
- func (indicator *ProgressIndicator) Hide()
- func (indicator *ProgressIndicator) IncrementBy(inc float64)
- func (indicator *ProgressIndicator) Remove()
- func (indicator *ProgressIndicator) SetAutohide(value bool)
- func (indicator *ProgressIndicator) SetDisplayedWhenStopped(value bool)
- func (indicator *ProgressIndicator) SetIsIndeterminate(value bool)
- func (indicator *ProgressIndicator) SetLimits(minValue float64, maxValue float64)
- func (indicator *ProgressIndicator) SetValue(value float64)
- func (indicator *ProgressIndicator) Show()
- func (indicator *ProgressIndicator) StartAnimation()
- func (indicator *ProgressIndicator) StopAnimation()
- type Screen
- type Slider
- type SliderType
- type TextField
- func (textField *TextField) Editable() bool
- func (textField *TextField) Enabled() bool
- func (textField *TextField) SetBackgroundColor(hexRGBA string)
- func (textField *TextField) SetBezeled(bezeled bool)
- func (textField *TextField) SetBorderColor(hexRGBA string)
- func (textField *TextField) SetBorderWidth(borderWidth int)
- func (textField *TextField) SetColor(hexRGBA string)
- func (textField *TextField) SetDrawsBackground(drawsBackground bool)
- func (textField *TextField) SetEditable(editable bool)
- func (textField *TextField) SetEnabled(enabled bool)
- func (textField *TextField) SetFontFamily(fontFamily string)
- func (textField *TextField) SetFontSize(fontSize int)
- func (textField *TextField) SetSelectable(selectable bool)
- func (textField *TextField) SetStringValue(text string)
- func (textField *TextField) StringValue() string
- type TextView
- type Window
- func (wnd *Window) AddButton(btn *Button)
- func (wnd *Window) AddComboBox(comboBox *ComboBox)
- func (wnd *Window) AddDatePicker(datePicker *DatePicker)
- func (wnd *Window) AddDefaultQuitMenu()
- func (wnd *Window) AddImageView(imageView *ImageView)
- func (wnd *Window) AddLabel(tv *TextField)
- func (wnd *Window) AddProgressIndicator(indicator *ProgressIndicator)
- func (wnd *Window) AddSlider(slider *Slider)
- func (wnd *Window) AddTextField(tv *TextField)
- func (wnd *Window) AddTextView(tv *TextView)
- func (wnd *Window) GetScreen() *Screen
- func (wnd *Window) MakeKeyAndOrderFront()
- func (wnd *Window) OnDidDeminiaturize(fn EventHandler)
- func (wnd *Window) OnDidMiniaturize(fn EventHandler)
- func (wnd *Window) OnDidMove(fn EventHandler)
- func (wnd *Window) OnDidResize(fn EventHandler)
- func (wnd *Window) SetAllowsResizing(allowsResizing bool)
- func (wnd *Window) SetCloseButtonEnabled(enabled bool)
- func (wnd *Window) SetMiniaturizeButtonEnabled(enabled bool)
- func (wnd *Window) SetTitle(title string)
- func (wnd *Window) SetZoomButtonEnabled(enabled bool)
- func (wnd *Window) Update()
- type WindowEvent
Constants ¶
const ( DatePickerStyleClockAndCalendar DatePickerStyle = 1 DatePickerStyleTextField DatePickerStyle = 2 DatePickerStyleTextFieldAndStepper DatePickerStyle = 0 DatePickerModeRange DatePickerMode = 1 DatePickerModeSingle DatePickerMode = 0 )
Variables ¶
This section is empty.
Functions ¶
func InitApplication ¶
func InitApplication()
InitApplication initializes the global application instance. Call this before using the rest of the gocoa package.
func OnApplicationDidFinishLaunching ¶
func OnApplicationDidFinishLaunching(fn func())
OnApplicationDidFinishLaunching - will be triggered after Application Launch is finished
func TerminateApplication ¶
func TerminateApplication()
TerminateApplication - will be triggered, when the Application terminates
Types ¶
type Button ¶
type Button struct {
// contains filtered or unexported fields
}
Button represents a button control that can trigger actions.
func NewButton ¶
NewButton constructs a new button at position (x, y) and with size (width x height). Gotcha! It is currently hard-coded to quit the app when the button is being pressed, until callbacks have been implemented. This func is not thread safe.
func (*Button) OnClick ¶
func (btn *Button) OnClick(fn func())
OnClick - function, that will be triggered, if the button is clicked.
func (*Button) SetBackgroundColor ¶
func (*Button) SetBezelStyle ¶
func (btn *Button) SetBezelStyle(bezelStyle ButtonBezelStyle)
func (*Button) SetBorderColor ¶
func (*Button) SetBorderWidth ¶
func (*Button) SetButtonType ¶
func (btn *Button) SetButtonType(buttonType ButtonType)
func (*Button) SetFontFamily ¶
func (*Button) SetFontSize ¶
func (*Button) SetState ¶
func (btn *Button) SetState(state ButtonState)
func (*Button) SetTitle ¶
SetTitle sets the title of the button, which is the text displayed on the button.
func (*Button) State ¶
func (btn *Button) State() ButtonState
type ButtonBezelStyle ¶
type ButtonBezelStyle int32
const ( ButtonBezelStyleRounded ButtonBezelStyle = 1 ButtonBezelStyleRegularSquare ButtonBezelStyle = 2 ButtonBezelStyleShadowlessSquare ButtonBezelStyle = 6 ButtonBezelStyleSmallSquare ButtonBezelStyle = 10 ButtonBezelStyleRoundRect ButtonBezelStyle = 12 ButtonBezelStyleInline ButtonBezelStyle = 15 ButtonBezelStyleRecessed ButtonBezelStyle = 13 ButtonBezelStyleDisclosure ButtonBezelStyle = 5 ButtonBezelStyleRoundedDisclosure ButtonBezelStyle = 14 ButtonBezelStyleCircular ButtonBezelStyle = 7 ButtonBezelStyleHelpButton ButtonBezelStyle = 9 ButtonBezelStyleTexturedRounded ButtonBezelStyle = 11 ButtonBezelStyleTexturedSquare ButtonBezelStyle = 8 )
type ButtonState ¶
type ButtonState int32
const ( ButtonStateValueOff ButtonState = 0 ButtonStateValueOn ButtonState = 1 ButtonStateValueMixed ButtonState = 2 )
type ButtonType ¶
type ButtonType int32
const ( ButtonTypeMomentaryPushIn ButtonType = 7 ButtonTypeMomentaryLight ButtonType = 0 ButtonTypeMomentaryChange ButtonType = 5 ButtonTypePushOnPushOff ButtonType = 1 ButtonTypeOnOff ButtonType = 6 ButtonTypeToggle ButtonType = 2 ButtonTypeSwitch ButtonType = 3 ButtonTypeRadio ButtonType = 4 ButtonTypeAccelerator ButtonType = 8 ButtonTypeMultiLevelAccelerator ButtonType = 9 )
type ComboBox ¶
type ComboBox struct {
// contains filtered or unexported fields
}
func (*ComboBox) OnSelectionDidChange ¶
func (comboBox *ComboBox) OnSelectionDidChange(fn func())
func (*ComboBox) SelectedIndex ¶
func (*ComboBox) SelectedText ¶
func (*ComboBox) SetEditable ¶
func (*ComboBox) SetSelectedIndex ¶
func (*ComboBox) SetSelectedText ¶
func (*ComboBox) SetStringValue ¶
func (*ComboBox) StringValue ¶
type DatePicker ¶
type DatePicker struct {
// contains filtered or unexported fields
}
DatePicker represents a date picker control that can trigger actions.
func NewDatePicker ¶
func NewDatePicker(x int, y int, width int, height int) *DatePicker
func (*DatePicker) Date ¶
func (datePicker *DatePicker) Date() string
func (*DatePicker) SetDate ¶
func (datePicker *DatePicker) SetDate(date string)
func (*DatePicker) SetDateFormat ¶
func (datePicker *DatePicker) SetDateFormat(dateFormat string)
func (*DatePicker) SetMaximumDate ¶
func (datePicker *DatePicker) SetMaximumDate(date string)
func (*DatePicker) SetMinimumDate ¶
func (datePicker *DatePicker) SetMinimumDate(date string)
func (*DatePicker) SetMode ¶
func (datePicker *DatePicker) SetMode(mode DatePickerMode)
func (*DatePicker) SetStyle ¶
func (datePicker *DatePicker) SetStyle(style DatePickerStyle)
type DatePickerMode ¶
type DatePickerMode int32
type DatePickerStyle ¶
type DatePickerStyle int32
type EventHandler ¶
type EventHandler func(wnd *Window)
EventHandler - handler functions that accepts the updated window as parameter
type FrameStyle ¶
type FrameStyle int32
const ( FrameStyleNone FrameStyle = 0 FrameStylePhoto FrameStyle = 1 FrameStyleGrayBezel FrameStyle = 2 FrameStyleGroove FrameStyle = 3 FrameStyleButton FrameStyle = 4 )
type ImageAlignment ¶
type ImageAlignment int32
const ( ImageAlignCenter ImageAlignment = 0 ImageAlignTop ImageAlignment = 1 ImageAlignTopLeft ImageAlignment = 2 ImageAlignTopRight ImageAlignment = 3 ImageAlignLeft ImageAlignment = 4 ImageAlignBottom ImageAlignment = 5 ImageAlignBottomLeft ImageAlignment = 6 ImageAlignBottomRight ImageAlignment = 7 ImageAlignRight ImageAlignment = 8 )
type ImageScaling ¶
type ImageScaling int32
const ( ImageScalingScaleProportionallyDown ImageScaling = 0 ImageScalingScaleAxesIndependently ImageScaling = 1 ImageScalingScaleNone ImageScaling = 2 ImageScalingScaleProportionallyUpOrDown ImageScaling = 3 )
type ImageView ¶
type ImageView struct {
// contains filtered or unexported fields
}
Represents an ImageView control that can display images.
func (*ImageView) SetAnimates ¶
func (*ImageView) SetContentTintColor ¶
func (*ImageView) SetEditable ¶
func (*ImageView) SetImageAlignment ¶
func (imageView *ImageView) SetImageAlignment(imageAlignment ImageAlignment)
func (*ImageView) SetImageFrameStyle ¶
func (imageView *ImageView) SetImageFrameStyle(frameStyle FrameStyle)
func (*ImageView) SetImageScaling ¶
func (imageView *ImageView) SetImageScaling(imageScaling ImageScaling)
type ProgressIndicator ¶
type ProgressIndicator struct {
// contains filtered or unexported fields
}
ProgressIndicator represents a indicator control that can trigger actions.
func NewProgressIndicator ¶
func NewProgressIndicator(x int, y int, w int, h int) *ProgressIndicator
NewProgressIndicator constructs a new ProgressIndicator
func (*ProgressIndicator) GetIsIndeterminate ¶
func (indicator *ProgressIndicator) GetIsIndeterminate() bool
GetIsIndeterminate - return if the progressbar is indeterminate
func (*ProgressIndicator) GetValue ¶
func (indicator *ProgressIndicator) GetValue() float64
GetValue - returns the current value of the indicator
func (*ProgressIndicator) Hide ¶
func (indicator *ProgressIndicator) Hide()
Hide - hides the Progressbar
func (*ProgressIndicator) IncrementBy ¶
func (indicator *ProgressIndicator) IncrementBy(inc float64)
IncrementBy - increments by `inc`
func (*ProgressIndicator) Remove ¶
func (indicator *ProgressIndicator) Remove()
Remove - removes the indicator from the superview
func (*ProgressIndicator) SetAutohide ¶
func (indicator *ProgressIndicator) SetAutohide(value bool)
SetAutohide - if set to true, the indicator will disapear after 100%, default false
func (*ProgressIndicator) SetDisplayedWhenStopped ¶
func (indicator *ProgressIndicator) SetDisplayedWhenStopped(value bool)
SetDisplayedWhenStopped - A Boolean that indicates whether the progress indicator hides itself when it isn’t animating.
func (*ProgressIndicator) SetIsIndeterminate ¶
func (indicator *ProgressIndicator) SetIsIndeterminate(value bool)
SetIsIndeterminate - sets if the progressbar is indeterminate
func (*ProgressIndicator) SetLimits ¶
func (indicator *ProgressIndicator) SetLimits(minValue float64, maxValue float64)
SetLimits - sets min and max values
func (*ProgressIndicator) SetValue ¶
func (indicator *ProgressIndicator) SetValue(value float64)
SetValue - sets the value to `value`
func (*ProgressIndicator) Show ¶
func (indicator *ProgressIndicator) Show()
Show - shows the Progressbar
func (*ProgressIndicator) StartAnimation ¶
func (indicator *ProgressIndicator) StartAnimation()
StartAnimation - Starts the animation of an indeterminate progress indicator.
func (*ProgressIndicator) StopAnimation ¶
func (indicator *ProgressIndicator) StopAnimation()
StopAnimation - Stops the animation of an indeterminate progress indicator.
type Slider ¶
type Slider struct {
// contains filtered or unexported fields
}
func (*Slider) OnSliderValueChanged ¶
func (slider *Slider) OnSliderValueChanged(fn func())
func (*Slider) SetMaximumValue ¶
func (*Slider) SetMinimumValue ¶
func (*Slider) SetSliderType ¶
func (slider *Slider) SetSliderType(sliderType SliderType)
type SliderType ¶
type SliderType int32
const ( SliderTypeCircular SliderType = 1 SliderTypeLinear SliderType = 0 )
type TextField ¶
type TextField struct {
// contains filtered or unexported fields
}
TextField -Button represents a button control that can trigger actions.
func NewLabel ¶
NewLabel - This func is not thread safe. Label is only for convenience. Under the hood it's still a textfield with some preconfiguration in place
func NewTextField ¶
NewTextField - This func is not thread safe.
func (*TextField) SetBackgroundColor ¶
func (*TextField) SetBezeled ¶
func (*TextField) SetBorderColor ¶
func (*TextField) SetBorderWidth ¶
func (*TextField) SetDrawsBackground ¶
func (*TextField) SetEditable ¶
func (*TextField) SetEnabled ¶
SetEnabled sets the enabled value of the text field. CANNOT BE CHANGED AT RUNTIME
func (*TextField) SetFontFamily ¶
func (*TextField) SetFontSize ¶
func (*TextField) SetSelectable ¶
func (*TextField) SetStringValue ¶
SetStringValue sets the string value of the text field
func (*TextField) StringValue ¶
StringValue - returns the string value of the text field
type TextView ¶
type TextView struct {
// contains filtered or unexported fields
}
TextView - represents a textView control that can trigger actions.
func NewTextView ¶
NewTextView - This func is not thread safe.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window is just that.
func NewCenteredWindow ¶
NewCenteredWindow constructs and returns a new window.
func (*Window) AddComboBox ¶
func (*Window) AddDatePicker ¶
func (wnd *Window) AddDatePicker(datePicker *DatePicker)
AddDatePicker adds a DatePicker to the window.
func (*Window) AddDefaultQuitMenu ¶
func (wnd *Window) AddDefaultQuitMenu()
func (*Window) AddImageView ¶
AddImageView adds an ImageView to the window.
func (*Window) AddProgressIndicator ¶
func (wnd *Window) AddProgressIndicator(indicator *ProgressIndicator)
AddProgressIndicator adds a ProgressIndicator to the window.
func (*Window) AddTextField ¶
AddTextField - adds a Button to the window.
func (*Window) AddTextView ¶
AddTextView - adds a Button to the window.
func (*Window) MakeKeyAndOrderFront ¶
func (wnd *Window) MakeKeyAndOrderFront()
MakeKeyAndOrderFront moves the window to the front of the screen list, within its level and it shows the window.
func (*Window) OnDidDeminiaturize ¶
func (wnd *Window) OnDidDeminiaturize(fn EventHandler)
func (*Window) OnDidMiniaturize ¶
func (wnd *Window) OnDidMiniaturize(fn EventHandler)
func (*Window) OnDidMove ¶
func (wnd *Window) OnDidMove(fn EventHandler)
func (*Window) OnDidResize ¶
func (wnd *Window) OnDidResize(fn EventHandler)