gofmt files
This commit is contained in:
parent
2dde2a79e7
commit
1ec8f6b01c
14
area.go
14
area.go
|
@ -18,7 +18,7 @@ var areas = make(map[*C.uiArea]*Area)
|
||||||
// and event handling are handled through an instance of a type
|
// and event handling are handled through an instance of a type
|
||||||
// that implements AreaHandler that every Area has; see AreaHandler
|
// that implements AreaHandler that every Area has; see AreaHandler
|
||||||
// for details.
|
// for details.
|
||||||
//
|
//
|
||||||
// There are two types of areas. Non-scrolling areas are rectangular
|
// There are two types of areas. Non-scrolling areas are rectangular
|
||||||
// and have no scrollbars. Programs can draw on and get mouse
|
// and have no scrollbars. Programs can draw on and get mouse
|
||||||
// events from any point in the Area, and the size of the Area is
|
// events from any point in the Area, and the size of the Area is
|
||||||
|
@ -28,7 +28,7 @@ var areas = make(map[*C.uiArea]*Area)
|
||||||
// size changes; instead, you are given the area size as part of the
|
// size changes; instead, you are given the area size as part of the
|
||||||
// draw and mouse event handlers, for use solely within those
|
// draw and mouse event handlers, for use solely within those
|
||||||
// handlers.
|
// handlers.
|
||||||
//
|
//
|
||||||
// Scrolling areas have horziontal and vertical scrollbars. The amount
|
// Scrolling areas have horziontal and vertical scrollbars. The amount
|
||||||
// that can be scrolled is determined by the area's size, which is
|
// that can be scrolled is determined by the area's size, which is
|
||||||
// decided by the programmer (both when creating the Area and by
|
// decided by the programmer (both when creating the Area and by
|
||||||
|
@ -36,7 +36,7 @@ var areas = make(map[*C.uiArea]*Area)
|
||||||
// drawing and mouse events are automatically adjusted to match
|
// drawing and mouse events are automatically adjusted to match
|
||||||
// what portion is visible, so you do not have to worry about scrolling
|
// what portion is visible, so you do not have to worry about scrolling
|
||||||
// in your event handlers. AreaHandler has more information.
|
// in your event handlers. AreaHandler has more information.
|
||||||
//
|
//
|
||||||
// The internal coordinate system of an Area is points, which are
|
// The internal coordinate system of an Area is points, which are
|
||||||
// floating-point and device-independent. For more details, see
|
// floating-point and device-independent. For more details, see
|
||||||
// AreaHandler. The size of a scrolling Area must be an exact integer
|
// AreaHandler. The size of a scrolling Area must be an exact integer
|
||||||
|
@ -45,12 +45,12 @@ var areas = make(map[*C.uiArea]*Area)
|
||||||
// SetSize are ints. All other instances of points in parameters and
|
// SetSize are ints. All other instances of points in parameters and
|
||||||
// structures (including sizes of drawn objects) are float64s.
|
// structures (including sizes of drawn objects) are float64s.
|
||||||
type Area struct {
|
type Area struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
a *C.uiArea
|
a *C.uiArea
|
||||||
|
|
||||||
ah *C.uiAreaHandler
|
ah *C.uiAreaHandler
|
||||||
|
|
||||||
scrolling bool
|
scrolling bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewArea creates a new non-scrolling Area.
|
// NewArea creates a new non-scrolling Area.
|
||||||
|
|
122
areahandler.go
122
areahandler.go
|
@ -12,7 +12,7 @@ package ui
|
||||||
// static inline uiAreaHandler *allocAreaHandler(void)
|
// static inline uiAreaHandler *allocAreaHandler(void)
|
||||||
// {
|
// {
|
||||||
// uiAreaHandler *ah;
|
// uiAreaHandler *ah;
|
||||||
//
|
//
|
||||||
// ah = (uiAreaHandler *) malloc(sizeof (uiAreaHandler));
|
// ah = (uiAreaHandler *) malloc(sizeof (uiAreaHandler));
|
||||||
// if (ah == NULL) // TODO
|
// if (ah == NULL) // TODO
|
||||||
// return NULL;
|
// return NULL;
|
||||||
|
@ -38,7 +38,7 @@ var areahandlers = make(map[*C.uiAreaHandler]AreaHandler)
|
||||||
// should be assumed to only be valid during the life of the method
|
// should be assumed to only be valid during the life of the method
|
||||||
// call (so for instance, do not save AreaDrawParams.AreaWidth, as
|
// call (so for instance, do not save AreaDrawParams.AreaWidth, as
|
||||||
// that might change without generating an event).
|
// that might change without generating an event).
|
||||||
//
|
//
|
||||||
// Coordinates to Draw and MouseEvent are given in points. Points
|
// Coordinates to Draw and MouseEvent are given in points. Points
|
||||||
// are generic, floating-point, device-independent coordinates with
|
// are generic, floating-point, device-independent coordinates with
|
||||||
// (0,0) at the top left corner. You never have to worry about the
|
// (0,0) at the top left corner. You never have to worry about the
|
||||||
|
@ -47,7 +47,7 @@ var areahandlers = make(map[*C.uiAreaHandler]AreaHandler)
|
||||||
// monitors for free. Proper documentation on the matter is being
|
// monitors for free. Proper documentation on the matter is being
|
||||||
// written. In the meantime, there are several referenes to this kind of
|
// written. In the meantime, there are several referenes to this kind of
|
||||||
// drawing, most notably on Apple's website: https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html#//apple_ref/doc/uid/TP40012302-CH4-SW1
|
// drawing, most notably on Apple's website: https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html#//apple_ref/doc/uid/TP40012302-CH4-SW1
|
||||||
//
|
//
|
||||||
// For a scrolling Area, points are automatically offset by the scroll
|
// For a scrolling Area, points are automatically offset by the scroll
|
||||||
// position. So if the mouse moves to position (5,5) while the
|
// position. So if the mouse moves to position (5,5) while the
|
||||||
// horizontal scrollbar is at position 10 and the horizontal scrollbar is
|
// horizontal scrollbar is at position 10 and the horizontal scrollbar is
|
||||||
|
@ -60,7 +60,7 @@ type AreaHandler interface {
|
||||||
// size of the area. The rectangle that needs to be drawn will
|
// size of the area. The rectangle that needs to be drawn will
|
||||||
// have been cleared by the system prior to drawing, so you are
|
// have been cleared by the system prior to drawing, so you are
|
||||||
// always working on a clean slate.
|
// always working on a clean slate.
|
||||||
//
|
//
|
||||||
// If you call Save on the drawing context, you must call Release
|
// If you call Save on the drawing context, you must call Release
|
||||||
// before returning from Draw, and the number of calls to Save
|
// before returning from Draw, and the number of calls to Save
|
||||||
// and Release must match. Failure to do so results in undefined
|
// and Release must match. Failure to do so results in undefined
|
||||||
|
@ -70,7 +70,7 @@ type AreaHandler interface {
|
||||||
// MouseEvent is called when the mouse moves over the Area
|
// MouseEvent is called when the mouse moves over the Area
|
||||||
// or when a mouse button is pressed or released. See
|
// or when a mouse button is pressed or released. See
|
||||||
// AreaMouseEvent for more details.
|
// AreaMouseEvent for more details.
|
||||||
//
|
//
|
||||||
// If a mouse button is being held, MouseEvents will continue to
|
// If a mouse button is being held, MouseEvents will continue to
|
||||||
// be generated, even if the mouse is not within the area. On
|
// be generated, even if the mouse is not within the area. On
|
||||||
// some systems, the system can interrupt this behavior;
|
// some systems, the system can interrupt this behavior;
|
||||||
|
@ -81,7 +81,7 @@ type AreaHandler interface {
|
||||||
// leaves the Area. It is called even if the mouse buttons are being
|
// leaves the Area. It is called even if the mouse buttons are being
|
||||||
// held (see MouseEvent above). If the mouse has entered the
|
// held (see MouseEvent above). If the mouse has entered the
|
||||||
// Area, left is false; if it has left the Area, left is true.
|
// Area, left is false; if it has left the Area, left is true.
|
||||||
//
|
//
|
||||||
// If, when the Area is first shown, the mouse is already inside
|
// If, when the Area is first shown, the mouse is already inside
|
||||||
// the Area, MouseCrossed will be called with left=false.
|
// the Area, MouseCrossed will be called with left=false.
|
||||||
// TODO what about future shows?
|
// TODO what about future shows?
|
||||||
|
@ -95,7 +95,7 @@ type AreaHandler interface {
|
||||||
// method is provided to allow your program to cope with the
|
// method is provided to allow your program to cope with the
|
||||||
// loss of the mouse in this case. You should cope by cancelling
|
// loss of the mouse in this case. You should cope by cancelling
|
||||||
// whatever drag-related operation you were doing.
|
// whatever drag-related operation you were doing.
|
||||||
//
|
//
|
||||||
// Note that this is only generated on some systems under
|
// Note that this is only generated on some systems under
|
||||||
// specific conditions. Do not implement behavior that only
|
// specific conditions. Do not implement behavior that only
|
||||||
// takes effect when DragBroken is called.
|
// takes effect when DragBroken is called.
|
||||||
|
@ -104,7 +104,7 @@ type AreaHandler interface {
|
||||||
// KeyEvent is called when a key is pressed while the Area has
|
// KeyEvent is called when a key is pressed while the Area has
|
||||||
// keyboard focus (if the Area has been tabbed into or if the
|
// keyboard focus (if the Area has been tabbed into or if the
|
||||||
// mouse has been clicked on it). See AreaKeyEvent for specifics.
|
// mouse has been clicked on it). See AreaKeyEvent for specifics.
|
||||||
//
|
//
|
||||||
// Because some keyboard events are handled by the system
|
// Because some keyboard events are handled by the system
|
||||||
// (for instance, menu accelerators and global hotkeys), you
|
// (for instance, menu accelerators and global hotkeys), you
|
||||||
// must return whether you handled the key event; return true
|
// must return whether you handled the key event; return true
|
||||||
|
@ -135,25 +135,25 @@ func unregisterAreaHandler(uah *C.uiAreaHandler) {
|
||||||
type AreaDrawParams struct {
|
type AreaDrawParams struct {
|
||||||
// Context is the drawing context to draw on. See DrawContext
|
// Context is the drawing context to draw on. See DrawContext
|
||||||
// for how to draw.
|
// for how to draw.
|
||||||
Context *DrawContext
|
Context *DrawContext
|
||||||
|
|
||||||
// AreaWidth and AreaHeight provide the size of the Area for
|
// AreaWidth and AreaHeight provide the size of the Area for
|
||||||
// non-scrolling Areas. For scrolling Areas both values are zero.
|
// non-scrolling Areas. For scrolling Areas both values are zero.
|
||||||
//
|
//
|
||||||
// To reiterate the AreaHandler documentation, do NOT save
|
// To reiterate the AreaHandler documentation, do NOT save
|
||||||
// these values for later; they can change without generating
|
// these values for later; they can change without generating
|
||||||
// an event.
|
// an event.
|
||||||
AreaWidth float64
|
AreaWidth float64
|
||||||
AreaHeight float64
|
AreaHeight float64
|
||||||
|
|
||||||
// These four fields define the rectangle that needs to be
|
// These four fields define the rectangle that needs to be
|
||||||
// redrawn. The system will not draw anything outside this
|
// redrawn. The system will not draw anything outside this
|
||||||
// rectangle, but you can make your drawing faster if you
|
// rectangle, but you can make your drawing faster if you
|
||||||
// also stay within the lines.
|
// also stay within the lines.
|
||||||
ClipX float64
|
ClipX float64
|
||||||
ClipY float64
|
ClipY float64
|
||||||
ClipWidth float64
|
ClipWidth float64
|
||||||
ClipHeight float64
|
ClipHeight float64
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doAreaHandlerDraw
|
//export doAreaHandlerDraw
|
||||||
|
@ -161,44 +161,44 @@ func doAreaHandlerDraw(uah *C.uiAreaHandler, ua *C.uiArea, udp *C.uiAreaDrawPara
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := areas[ua]
|
a := areas[ua]
|
||||||
dp := &AreaDrawParams{
|
dp := &AreaDrawParams{
|
||||||
Context: &DrawContext{udp.Context},
|
Context: &DrawContext{udp.Context},
|
||||||
AreaWidth: float64(udp.AreaWidth),
|
AreaWidth: float64(udp.AreaWidth),
|
||||||
AreaHeight: float64(udp.AreaHeight),
|
AreaHeight: float64(udp.AreaHeight),
|
||||||
ClipX: float64(udp.ClipX),
|
ClipX: float64(udp.ClipX),
|
||||||
ClipY: float64(udp.ClipY),
|
ClipY: float64(udp.ClipY),
|
||||||
ClipWidth: float64(udp.ClipWidth),
|
ClipWidth: float64(udp.ClipWidth),
|
||||||
ClipHeight: float64(udp.ClipHeight),
|
ClipHeight: float64(udp.ClipHeight),
|
||||||
}
|
}
|
||||||
ah.Draw(a, dp)
|
ah.Draw(a, dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO document all these
|
// TODO document all these
|
||||||
//
|
//
|
||||||
// TODO note that in the case of a drag, X and Y can be out of bounds, or in the event of a scrolling area, in places that are not visible
|
// TODO note that in the case of a drag, X and Y can be out of bounds, or in the event of a scrolling area, in places that are not visible
|
||||||
type AreaMouseEvent struct {
|
type AreaMouseEvent struct {
|
||||||
X float64
|
X float64
|
||||||
Y float64
|
Y float64
|
||||||
|
|
||||||
// AreaWidth and AreaHeight provide the size of the Area for
|
// AreaWidth and AreaHeight provide the size of the Area for
|
||||||
// non-scrolling Areas. For scrolling Areas both values are zero.
|
// non-scrolling Areas. For scrolling Areas both values are zero.
|
||||||
//
|
//
|
||||||
// To reiterate the AreaHandler documentation, do NOT save
|
// To reiterate the AreaHandler documentation, do NOT save
|
||||||
// these values for later; they can change without generating
|
// these values for later; they can change without generating
|
||||||
// an event.
|
// an event.
|
||||||
AreaWidth float64
|
AreaWidth float64
|
||||||
AreaHeight float64
|
AreaHeight float64
|
||||||
|
|
||||||
Down uint
|
Down uint
|
||||||
Up uint
|
Up uint
|
||||||
Count uint
|
Count uint
|
||||||
Modifiers Modifiers
|
Modifiers Modifiers
|
||||||
Held []uint
|
Held []uint
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendBits(out []uint, held C.uint64_t) []uint {
|
func appendBits(out []uint, held C.uint64_t) []uint {
|
||||||
n := uint(1)
|
n := uint(1)
|
||||||
for i := 0; i < 64; i++ {
|
for i := 0; i < 64; i++ {
|
||||||
if held & 1 != 0 {
|
if held&1 != 0 {
|
||||||
out = append(out, n)
|
out = append(out, n)
|
||||||
}
|
}
|
||||||
held >>= 1
|
held >>= 1
|
||||||
|
@ -212,15 +212,15 @@ func doAreaHandlerMouseEvent(uah *C.uiAreaHandler, ua *C.uiArea, ume *C.uiAreaMo
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := areas[ua]
|
a := areas[ua]
|
||||||
me := &AreaMouseEvent{
|
me := &AreaMouseEvent{
|
||||||
X: float64(ume.X),
|
X: float64(ume.X),
|
||||||
Y: float64(ume.Y),
|
Y: float64(ume.Y),
|
||||||
AreaWidth: float64(ume.AreaWidth),
|
AreaWidth: float64(ume.AreaWidth),
|
||||||
AreaHeight: float64(ume.AreaHeight),
|
AreaHeight: float64(ume.AreaHeight),
|
||||||
Down: uint(ume.Down),
|
Down: uint(ume.Down),
|
||||||
Up: uint(ume.Up),
|
Up: uint(ume.Up),
|
||||||
Count: uint(ume.Count),
|
Count: uint(ume.Count),
|
||||||
Modifiers: Modifiers(ume.Modifiers),
|
Modifiers: Modifiers(ume.Modifiers),
|
||||||
Held: make([]uint, 0, 64),
|
Held: make([]uint, 0, 64),
|
||||||
}
|
}
|
||||||
me.Held = appendBits(me.Held, ume.Held1To64)
|
me.Held = appendBits(me.Held, ume.Held1To64)
|
||||||
ah.MouseEvent(a, me)
|
ah.MouseEvent(a, me)
|
||||||
|
@ -242,11 +242,11 @@ func doAreaHandlerDragBroken(uah *C.uiAreaHandler, ua *C.uiArea) {
|
||||||
|
|
||||||
// TODO document all these
|
// TODO document all these
|
||||||
type AreaKeyEvent struct {
|
type AreaKeyEvent struct {
|
||||||
Key rune
|
Key rune
|
||||||
ExtKey ExtKey
|
ExtKey ExtKey
|
||||||
Modifier Modifiers
|
Modifier Modifiers
|
||||||
Modifiers Modifiers
|
Modifiers Modifiers
|
||||||
Up bool
|
Up bool
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doAreaHandlerKeyEvent
|
//export doAreaHandlerKeyEvent
|
||||||
|
@ -254,19 +254,20 @@ func doAreaHandlerKeyEvent(uah *C.uiAreaHandler, ua *C.uiArea, uke *C.uiAreaKeyE
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := areas[ua]
|
a := areas[ua]
|
||||||
ke := &AreaKeyEvent{
|
ke := &AreaKeyEvent{
|
||||||
Key: rune(uke.Key),
|
Key: rune(uke.Key),
|
||||||
ExtKey: ExtKey(uke.ExtKey),
|
ExtKey: ExtKey(uke.ExtKey),
|
||||||
Modifier: Modifiers(uke.Modifier),
|
Modifier: Modifiers(uke.Modifier),
|
||||||
Modifiers: Modifiers(uke.Modifiers),
|
Modifiers: Modifiers(uke.Modifiers),
|
||||||
Up: tobool(uke.Up),
|
Up: tobool(uke.Up),
|
||||||
}
|
}
|
||||||
return frombool(ah.KeyEvent(a, ke))
|
return frombool(ah.KeyEvent(a, ke))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO document
|
// TODO document
|
||||||
//
|
//
|
||||||
// Note: these must be numerically identical to their libui equivalents.
|
// Note: these must be numerically identical to their libui equivalents.
|
||||||
type Modifiers uint
|
type Modifiers uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Ctrl Modifiers = 1 << iota
|
Ctrl Modifiers = 1 << iota
|
||||||
Alt
|
Alt
|
||||||
|
@ -275,12 +276,13 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO document
|
// TODO document
|
||||||
//
|
//
|
||||||
// Note: these must be numerically identical to their libui equivalents.
|
// Note: these must be numerically identical to their libui equivalents.
|
||||||
type ExtKey int
|
type ExtKey int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Escape ExtKey = iota + 1
|
Escape ExtKey = iota + 1
|
||||||
Insert // equivalent to "Help" on Apple keyboards
|
Insert // equivalent to "Help" on Apple keyboards
|
||||||
Delete
|
Delete
|
||||||
Home
|
Home
|
||||||
End
|
End
|
||||||
|
@ -290,7 +292,7 @@ const (
|
||||||
Down
|
Down
|
||||||
Left
|
Left
|
||||||
Right
|
Right
|
||||||
F1 // F1..F12 are guaranteed to be consecutive
|
F1 // F1..F12 are guaranteed to be consecutive
|
||||||
F2
|
F2
|
||||||
F3
|
F3
|
||||||
F4
|
F4
|
||||||
|
@ -302,8 +304,8 @@ const (
|
||||||
F10
|
F10
|
||||||
F11
|
F11
|
||||||
F12
|
F12
|
||||||
N0 // numpad keys; independent of Num Lock state
|
N0 // numpad keys; independent of Num Lock state
|
||||||
N1 // N0..N9 are guaranteed to be consecutive
|
N1 // N0..N9 are guaranteed to be consecutive
|
||||||
N2
|
N2
|
||||||
N3
|
N3
|
||||||
N4
|
N4
|
||||||
|
|
8
box.go
8
box.go
|
@ -18,10 +18,10 @@ import "C"
|
||||||
// stretchy, they will be given equal shares of the leftover space.
|
// stretchy, they will be given equal shares of the leftover space.
|
||||||
// There can also be space between each control ("padding").
|
// There can also be space between each control ("padding").
|
||||||
type Box struct {
|
type Box struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
b *C.uiBox
|
b *C.uiBox
|
||||||
|
|
||||||
children []Control
|
children []Control
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHorizontalBox creates a new horizontal Box.
|
// NewHorizontalBox creates a new horizontal Box.
|
||||||
|
@ -102,7 +102,7 @@ func (b *Box) Append(child Control, stretchy bool) {
|
||||||
|
|
||||||
// Delete deletes the nth control of the Box.
|
// Delete deletes the nth control of the Box.
|
||||||
func (b *Box) Delete(n int) {
|
func (b *Box) Delete(n int) {
|
||||||
b.children = append(b.children[:n], b.children[n + 1:]...)
|
b.children = append(b.children[:n], b.children[n+1:]...)
|
||||||
// TODO why is this uintmax_t instead of intmax_t
|
// TODO why is this uintmax_t instead of intmax_t
|
||||||
C.uiBoxDelete(b.b, C.uintmax_t(n))
|
C.uiBoxDelete(b.b, C.uintmax_t(n))
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ var buttons = make(map[*C.uiButton]*Button)
|
||||||
// click to perform an action. A Button has a text label that should
|
// click to perform an action. A Button has a text label that should
|
||||||
// describe what the button does.
|
// describe what the button does.
|
||||||
type Button struct {
|
type Button struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
b *C.uiButton
|
b *C.uiButton
|
||||||
|
|
||||||
onClicked func(*Button)
|
onClicked func(*Button)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewButton creates a new Button with the given text as its label.
|
// NewButton creates a new Button with the given text as its label.
|
||||||
|
|
|
@ -21,10 +21,10 @@ var checkboxes = make(map[*C.uiCheckbox]*Checkbox)
|
||||||
// side. When the user clicks the checkbox, a check mark will appear
|
// side. When the user clicks the checkbox, a check mark will appear
|
||||||
// in the box; clicking it again removes the check.
|
// in the box; clicking it again removes the check.
|
||||||
type Checkbox struct {
|
type Checkbox struct {
|
||||||
co *C.uiControl
|
co *C.uiControl
|
||||||
c *C.uiCheckbox
|
c *C.uiCheckbox
|
||||||
|
|
||||||
onToggled func(*Checkbox)
|
onToggled func(*Checkbox)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCheckbox creates a new Checkbox with the given text as its label.
|
// NewCheckbox creates a new Checkbox with the given text as its label.
|
||||||
|
|
|
@ -22,10 +22,10 @@ var comboboxes = make(map[*C.uiCombobox]*Combobox)
|
||||||
// Combobox also has an entry field that the user can type an alternate
|
// Combobox also has an entry field that the user can type an alternate
|
||||||
// choice into.
|
// choice into.
|
||||||
type Combobox struct {
|
type Combobox struct {
|
||||||
co *C.uiControl
|
co *C.uiControl
|
||||||
c *C.uiCombobox
|
c *C.uiCombobox
|
||||||
|
|
||||||
onSelected func(*Combobox)
|
onSelected func(*Combobox)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCombobox creates a new Combobox.
|
// NewCombobox creates a new Combobox.
|
||||||
|
@ -41,6 +41,7 @@ func NewCombobox() *Combobox {
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
/*TODO
|
/*TODO
|
||||||
// NewEditableCombobox creates a new editable Combobox.
|
// NewEditableCombobox creates a new editable Combobox.
|
||||||
func NewEditableCombobox() *Combobox {
|
func NewEditableCombobox() *Combobox {
|
||||||
|
|
14
control.go
14
control.go
|
@ -11,14 +11,14 @@ import "C"
|
||||||
|
|
||||||
// Control represents a GUI control. It provdes methods
|
// Control represents a GUI control. It provdes methods
|
||||||
// common to all Controls.
|
// common to all Controls.
|
||||||
//
|
//
|
||||||
// To create a new Control, implement the control on
|
// To create a new Control, implement the control on
|
||||||
// the libui side, then provide access to that control on
|
// the libui side, then provide access to that control on
|
||||||
// the Go side via an implementation of Control as
|
// the Go side via an implementation of Control as
|
||||||
// described.
|
// described.
|
||||||
type Control interface {
|
type Control interface {
|
||||||
// Destroy destroys the Control.
|
// Destroy destroys the Control.
|
||||||
//
|
//
|
||||||
// Implementations should do any necessary cleanup,
|
// Implementations should do any necessary cleanup,
|
||||||
// then call LibuiControlDestroy.
|
// then call LibuiControlDestroy.
|
||||||
Destroy()
|
Destroy()
|
||||||
|
@ -32,30 +32,30 @@ type Control interface {
|
||||||
// Control. On OSs that use reference counting for
|
// Control. On OSs that use reference counting for
|
||||||
// controls, Handle does not increment the reference
|
// controls, Handle does not increment the reference
|
||||||
// count; you are sharing package ui's reference.
|
// count; you are sharing package ui's reference.
|
||||||
//
|
//
|
||||||
// Implementations should call LibuiControlHandle and
|
// Implementations should call LibuiControlHandle and
|
||||||
// document exactly what kind of handle is returned.
|
// document exactly what kind of handle is returned.
|
||||||
Handle() uintptr
|
Handle() uintptr
|
||||||
|
|
||||||
// Show shows the Control.
|
// Show shows the Control.
|
||||||
//
|
//
|
||||||
// Implementations should call LibuiControlShow.
|
// Implementations should call LibuiControlShow.
|
||||||
Show()
|
Show()
|
||||||
|
|
||||||
// Hide shows the Control. Hidden controls do not participate
|
// Hide shows the Control. Hidden controls do not participate
|
||||||
// in layout (that is, Box, Grid, etc. does not reserve space for
|
// in layout (that is, Box, Grid, etc. does not reserve space for
|
||||||
// hidden controls).
|
// hidden controls).
|
||||||
//
|
//
|
||||||
// Implementations should call LibuiControlHide.
|
// Implementations should call LibuiControlHide.
|
||||||
Hide()
|
Hide()
|
||||||
|
|
||||||
// Enable enables the Control.
|
// Enable enables the Control.
|
||||||
//
|
//
|
||||||
// Implementations should call LibuiControlEnable.
|
// Implementations should call LibuiControlEnable.
|
||||||
Enable()
|
Enable()
|
||||||
|
|
||||||
// Disable disables the Control.
|
// Disable disables the Control.
|
||||||
//
|
//
|
||||||
// Implementations should call LibuiControlDisable.
|
// Implementations should call LibuiControlDisable.
|
||||||
Disable()
|
Disable()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ import "C"
|
||||||
// DateTimePicker is a Control that represents a field where the user
|
// DateTimePicker is a Control that represents a field where the user
|
||||||
// can enter a date and/or a time.
|
// can enter a date and/or a time.
|
||||||
type DateTimePicker struct {
|
type DateTimePicker struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
d *C.uiDateTimePicker
|
d *C.uiDateTimePicker
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDateTimePicker creates a new DateTimePicker that shows
|
// NewDateTimePicker creates a new DateTimePicker that shows
|
||||||
|
|
173
draw.go
173
draw.go
|
@ -9,14 +9,14 @@ package ui
|
||||||
// static uiDrawBrush *newBrush(void)
|
// static uiDrawBrush *newBrush(void)
|
||||||
// {
|
// {
|
||||||
// uiDrawBrush *b;
|
// uiDrawBrush *b;
|
||||||
//
|
//
|
||||||
// b = (uiDrawBrush *) uimalloc(sizeof (uiDrawBrush));
|
// b = (uiDrawBrush *) uimalloc(sizeof (uiDrawBrush));
|
||||||
// return b;
|
// return b;
|
||||||
// }
|
// }
|
||||||
// static uiDrawBrushGradientStop *newStops(size_t n)
|
// static uiDrawBrushGradientStop *newStops(size_t n)
|
||||||
// {
|
// {
|
||||||
// uiDrawBrushGradientStop *stops;
|
// uiDrawBrushGradientStop *stops;
|
||||||
//
|
//
|
||||||
// stops = (uiDrawBrushGradientStop *) malloc(n * sizeof (uiDrawBrushGradientStop));
|
// stops = (uiDrawBrushGradientStop *) malloc(n * sizeof (uiDrawBrushGradientStop));
|
||||||
// // TODO
|
// // TODO
|
||||||
// return stops;
|
// return stops;
|
||||||
|
@ -38,7 +38,7 @@ package ui
|
||||||
// static uiDrawStrokeParams *newStrokeParams(void)
|
// static uiDrawStrokeParams *newStrokeParams(void)
|
||||||
// {
|
// {
|
||||||
// uiDrawStrokeParams *b;
|
// uiDrawStrokeParams *b;
|
||||||
//
|
//
|
||||||
// b = (uiDrawStrokeParams *) malloc(sizeof (uiDrawStrokeParams));
|
// b = (uiDrawStrokeParams *) malloc(sizeof (uiDrawStrokeParams));
|
||||||
// // TODO
|
// // TODO
|
||||||
// return b;
|
// return b;
|
||||||
|
@ -46,7 +46,7 @@ package ui
|
||||||
// static double *newDashes(size_t n)
|
// static double *newDashes(size_t n)
|
||||||
// {
|
// {
|
||||||
// double *dashes;
|
// double *dashes;
|
||||||
//
|
//
|
||||||
// dashes = (double *) malloc(n * sizeof (double));
|
// dashes = (double *) malloc(n * sizeof (double));
|
||||||
// // TODO
|
// // TODO
|
||||||
// return dashes;
|
// return dashes;
|
||||||
|
@ -64,7 +64,7 @@ package ui
|
||||||
// static uiDrawMatrix *newMatrix(void)
|
// static uiDrawMatrix *newMatrix(void)
|
||||||
// {
|
// {
|
||||||
// uiDrawMatrix *m;
|
// uiDrawMatrix *m;
|
||||||
//
|
//
|
||||||
// m = (uiDrawMatrix *) malloc(sizeof (uiDrawMatrix));
|
// m = (uiDrawMatrix *) malloc(sizeof (uiDrawMatrix));
|
||||||
// // TODO
|
// // TODO
|
||||||
// return m;
|
// return m;
|
||||||
|
@ -76,7 +76,7 @@ package ui
|
||||||
// static uiDrawTextFontDescriptor *newFontDescriptor(void)
|
// static uiDrawTextFontDescriptor *newFontDescriptor(void)
|
||||||
// {
|
// {
|
||||||
// uiDrawTextFontDescriptor *desc;
|
// uiDrawTextFontDescriptor *desc;
|
||||||
//
|
//
|
||||||
// desc = (uiDrawTextFontDescriptor *) malloc(sizeof (uiDrawTextFontDescriptor));
|
// desc = (uiDrawTextFontDescriptor *) malloc(sizeof (uiDrawTextFontDescriptor));
|
||||||
// // TODO
|
// // TODO
|
||||||
// return desc;
|
// return desc;
|
||||||
|
@ -84,7 +84,7 @@ package ui
|
||||||
// static uiDrawTextFont *newFont(uiDrawTextFontDescriptor *desc)
|
// static uiDrawTextFont *newFont(uiDrawTextFontDescriptor *desc)
|
||||||
// {
|
// {
|
||||||
// uiDrawTextFont *font;
|
// uiDrawTextFont *font;
|
||||||
//
|
//
|
||||||
// font = uiDrawLoadClosestFont(desc);
|
// font = uiDrawLoadClosestFont(desc);
|
||||||
// free((char *) (desc->Family));
|
// free((char *) (desc->Family));
|
||||||
// free(desc);
|
// free(desc);
|
||||||
|
@ -93,7 +93,7 @@ package ui
|
||||||
// static uiDrawTextLayout *newTextLayout(char *text, uiDrawTextFont *defaultFont, double width)
|
// static uiDrawTextLayout *newTextLayout(char *text, uiDrawTextFont *defaultFont, double width)
|
||||||
// {
|
// {
|
||||||
// uiDrawTextLayout *layout;
|
// uiDrawTextLayout *layout;
|
||||||
//
|
//
|
||||||
// layout = uiDrawNewTextLayout(text, defaultFont, width);
|
// layout = uiDrawNewTextLayout(text, defaultFont, width);
|
||||||
// free(text);
|
// free(text);
|
||||||
// return layout;
|
// return layout;
|
||||||
|
@ -101,7 +101,7 @@ package ui
|
||||||
// static uiDrawTextFontMetrics *newFontMetrics(void)
|
// static uiDrawTextFontMetrics *newFontMetrics(void)
|
||||||
// {
|
// {
|
||||||
// uiDrawTextFontMetrics *m;
|
// uiDrawTextFontMetrics *m;
|
||||||
//
|
//
|
||||||
// m = (uiDrawTextFontMetrics *) malloc(sizeof (uiDrawTextFontMetrics));
|
// m = (uiDrawTextFontMetrics *) malloc(sizeof (uiDrawTextFontMetrics));
|
||||||
// // TODO
|
// // TODO
|
||||||
// return m;
|
// return m;
|
||||||
|
@ -113,7 +113,7 @@ package ui
|
||||||
// static double *newDouble(void)
|
// static double *newDouble(void)
|
||||||
// {
|
// {
|
||||||
// double *d;
|
// double *d;
|
||||||
//
|
//
|
||||||
// d = (double *) malloc(sizeof (double));
|
// d = (double *) malloc(sizeof (double));
|
||||||
// // TODO
|
// // TODO
|
||||||
// return d;
|
// return d;
|
||||||
|
@ -135,7 +135,7 @@ import "C"
|
||||||
// figures to a path, you must "end" the path to make it ready to draw
|
// figures to a path, you must "end" the path to make it ready to draw
|
||||||
// with.
|
// with.
|
||||||
// TODO rewrite all that
|
// TODO rewrite all that
|
||||||
//
|
//
|
||||||
// Or more visually, the lifecycle of a Path is
|
// Or more visually, the lifecycle of a Path is
|
||||||
// p := NewPath()
|
// p := NewPath()
|
||||||
// for every figure {
|
// for every figure {
|
||||||
|
@ -154,18 +154,19 @@ import "C"
|
||||||
// dp.Context.Clip(p)
|
// dp.Context.Clip(p)
|
||||||
// // ...
|
// // ...
|
||||||
// p.Free() // when done with the path
|
// p.Free() // when done with the path
|
||||||
//
|
//
|
||||||
// A Path also defines its fill mode. (This should ideally be a fill
|
// A Path also defines its fill mode. (This should ideally be a fill
|
||||||
// parameter, but some implementations prevent it.)
|
// parameter, but some implementations prevent it.)
|
||||||
// TODO talk about fill modes
|
// TODO talk about fill modes
|
||||||
type Path struct {
|
type Path struct {
|
||||||
p *C.uiDrawPath
|
p *C.uiDrawPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
//
|
//
|
||||||
// TODO disclaimer
|
// TODO disclaimer
|
||||||
type FillMode uint
|
type FillMode uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Winding FillMode = iota
|
Winding FillMode = iota
|
||||||
Alternate
|
Alternate
|
||||||
|
@ -184,7 +185,7 @@ func NewPath(fillMode FillMode) *Path {
|
||||||
panic("invalid fill mode passed to ui.NewPath()")
|
panic("invalid fill mode passed to ui.NewPath()")
|
||||||
}
|
}
|
||||||
return &Path{
|
return &Path{
|
||||||
p: C.uiDrawNewPath(fm),
|
p: C.uiDrawNewPath(fm),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,25 +271,27 @@ func (p *Path) End() {
|
||||||
// At present the only DrawContexts are surfaces associated with
|
// At present the only DrawContexts are surfaces associated with
|
||||||
// Areas and are provided by package ui; see AreaDrawParams.
|
// Areas and are provided by package ui; see AreaDrawParams.
|
||||||
type DrawContext struct {
|
type DrawContext struct {
|
||||||
c *C.uiDrawContext
|
c *C.uiDrawContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// BrushType defines the various types of brushes.
|
// BrushType defines the various types of brushes.
|
||||||
//
|
//
|
||||||
// TODO disclaimer
|
// TODO disclaimer
|
||||||
type BrushType int
|
type BrushType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Solid BrushType = iota
|
Solid BrushType = iota
|
||||||
LinearGradient
|
LinearGradient
|
||||||
RadialGradient
|
RadialGradient
|
||||||
Image // presently unimplemented
|
Image // presently unimplemented
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
//
|
//
|
||||||
// TODO disclaimer
|
// TODO disclaimer
|
||||||
// TODO rename these to put LineCap at the beginning? or just Cap?
|
// TODO rename these to put LineCap at the beginning? or just Cap?
|
||||||
type LineCap int
|
type LineCap int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FlatCap LineCap = iota
|
FlatCap LineCap = iota
|
||||||
RoundCap
|
RoundCap
|
||||||
|
@ -296,9 +299,10 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
//
|
//
|
||||||
// TODO disclaimer
|
// TODO disclaimer
|
||||||
type LineJoin int
|
type LineJoin int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MiterJoin LineJoin = iota
|
MiterJoin LineJoin = iota
|
||||||
RoundJoin
|
RoundJoin
|
||||||
|
@ -310,32 +314,32 @@ const DefaultMiterLimit = 10.0
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
type Brush struct {
|
type Brush struct {
|
||||||
Type BrushType
|
Type BrushType
|
||||||
|
|
||||||
// If Type is Solid.
|
// If Type is Solid.
|
||||||
// TODO
|
// TODO
|
||||||
R float64
|
R float64
|
||||||
G float64
|
G float64
|
||||||
B float64
|
B float64
|
||||||
A float64
|
A float64
|
||||||
|
|
||||||
// If Type is LinearGradient or RadialGradient.
|
// If Type is LinearGradient or RadialGradient.
|
||||||
// TODO
|
// TODO
|
||||||
X0 float64 // start point for both
|
X0 float64 // start point for both
|
||||||
Y0 float64
|
Y0 float64
|
||||||
X1 float64 // linear: end point; radial: circle center
|
X1 float64 // linear: end point; radial: circle center
|
||||||
Y1 float64
|
Y1 float64
|
||||||
OuterRadius float64 // for radial gradients only
|
OuterRadius float64 // for radial gradients only
|
||||||
Stops []GradientStop
|
Stops []GradientStop
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
type GradientStop struct {
|
type GradientStop struct {
|
||||||
Pos float64 // between 0 and 1 inclusive
|
Pos float64 // between 0 and 1 inclusive
|
||||||
R float64
|
R float64
|
||||||
G float64
|
G float64
|
||||||
B float64
|
B float64
|
||||||
A float64
|
A float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Brush) toC() *C.uiDrawBrush {
|
func (b *Brush) toC() *C.uiDrawBrush {
|
||||||
|
@ -373,12 +377,12 @@ func (b *Brush) toC() *C.uiDrawBrush {
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
type StrokeParams struct {
|
type StrokeParams struct {
|
||||||
Cap LineCap
|
Cap LineCap
|
||||||
Join LineJoin
|
Join LineJoin
|
||||||
Thickness float64
|
Thickness float64
|
||||||
MiterLimit float64
|
MiterLimit float64
|
||||||
Dashes []float64
|
Dashes []float64
|
||||||
DashPhase float64
|
DashPhase float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sp *StrokeParams) toC() *C.uiDrawStrokeParams {
|
func (sp *StrokeParams) toC() *C.uiDrawStrokeParams {
|
||||||
|
@ -418,12 +422,12 @@ func (c *DrawContext) Fill(p *Path, b *Brush) {
|
||||||
// TODO
|
// TODO
|
||||||
// TODO should the methods of these return self for chaining?
|
// TODO should the methods of these return self for chaining?
|
||||||
type Matrix struct {
|
type Matrix struct {
|
||||||
M11 float64
|
M11 float64
|
||||||
M12 float64
|
M12 float64
|
||||||
M21 float64
|
M21 float64
|
||||||
M22 float64
|
M22 float64
|
||||||
M31 float64
|
M31 float64
|
||||||
M32 float64
|
M32 float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO identity matrix
|
// TODO identity matrix
|
||||||
|
@ -514,7 +518,7 @@ func (m *Matrix) Invertible() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
//
|
//
|
||||||
// If m is not invertible, false is returned and m is left unchanged.
|
// If m is not invertible, false is returned and m is left unchanged.
|
||||||
func (m *Matrix) Invert() bool {
|
func (m *Matrix) Invert() bool {
|
||||||
cm := m.toC()
|
cm := m.toC()
|
||||||
|
@ -564,10 +568,10 @@ func (c *DrawContext) Restore() {
|
||||||
// call (TODO verify). Use NumFamilies to get the number of families,
|
// call (TODO verify). Use NumFamilies to get the number of families,
|
||||||
// and Family to get the name of a given family by index. When
|
// and Family to get the name of a given family by index. When
|
||||||
// finished, call Free.
|
// finished, call Free.
|
||||||
//
|
//
|
||||||
// There is no guarantee that the list of families is sorted. You will
|
// There is no guarantee that the list of families is sorted. You will
|
||||||
// need to do sorting yourself if you need it.
|
// need to do sorting yourself if you need it.
|
||||||
//
|
//
|
||||||
// TODO thread affinity
|
// TODO thread affinity
|
||||||
type FontFamilies struct {
|
type FontFamilies struct {
|
||||||
ff *C.uiDrawFontFamilies
|
ff *C.uiDrawFontFamilies
|
||||||
|
@ -576,7 +580,7 @@ type FontFamilies struct {
|
||||||
// ListFontFamilies creates a new FontFamilies object ready for use.
|
// ListFontFamilies creates a new FontFamilies object ready for use.
|
||||||
func ListFontFamilies() *FontFamilies {
|
func ListFontFamilies() *FontFamilies {
|
||||||
return &FontFamilies{
|
return &FontFamilies{
|
||||||
ff: C.uiDrawListFontFamilies(),
|
ff: C.uiDrawListFontFamilies(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,14 +605,15 @@ func (f *FontFamilies) Family(n int) string {
|
||||||
|
|
||||||
// TextWeight defines the various text weights, in order of
|
// TextWeight defines the various text weights, in order of
|
||||||
// increasing weight.
|
// increasing weight.
|
||||||
//
|
//
|
||||||
// Note that if you leave this field unset, it will default to
|
// Note that if you leave this field unset, it will default to
|
||||||
// TextWeightThin. If you want the normal font weight, explicitly
|
// TextWeightThin. If you want the normal font weight, explicitly
|
||||||
// use the constant TextWeightNormal instead.
|
// use the constant TextWeightNormal instead.
|
||||||
// TODO realign these?
|
// TODO realign these?
|
||||||
//
|
//
|
||||||
// TODO disclaimer
|
// TODO disclaimer
|
||||||
type TextWeight int
|
type TextWeight int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TextWeightThin TextWeight = iota
|
TextWeightThin TextWeight = iota
|
||||||
TextWeightUltraLight
|
TextWeightUltraLight
|
||||||
|
@ -624,26 +629,28 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// TextItalic defines the various text italic modes.
|
// TextItalic defines the various text italic modes.
|
||||||
//
|
//
|
||||||
// TODO disclaimer
|
// TODO disclaimer
|
||||||
type TextItalic int
|
type TextItalic int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TextItalicNormal TextItalic = iota
|
TextItalicNormal TextItalic = iota
|
||||||
TextItalicOblique // merely slanted text
|
TextItalicOblique // merely slanted text
|
||||||
TextItalicItalic // true italics
|
TextItalicItalic // true italics
|
||||||
)
|
)
|
||||||
|
|
||||||
// TextStretch defines the various text stretches, in order of
|
// TextStretch defines the various text stretches, in order of
|
||||||
// increasing wideness.
|
// increasing wideness.
|
||||||
//
|
//
|
||||||
// Note that if you leave this field unset, it will default to
|
// Note that if you leave this field unset, it will default to
|
||||||
// TextStretchUltraCondensed. If you want the normal font
|
// TextStretchUltraCondensed. If you want the normal font
|
||||||
// stretch, explicitly use the constant TextStretchNormal
|
// stretch, explicitly use the constant TextStretchNormal
|
||||||
// instead.
|
// instead.
|
||||||
// TODO realign these?
|
// TODO realign these?
|
||||||
//
|
//
|
||||||
// TODO disclaimer
|
// TODO disclaimer
|
||||||
type TextStretch int
|
type TextStretch int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TextStretchUltraCondensed TextStretch = iota
|
TextStretchUltraCondensed TextStretch = iota
|
||||||
TextStretchExtraCondensed
|
TextStretchExtraCondensed
|
||||||
|
@ -658,20 +665,20 @@ const (
|
||||||
|
|
||||||
// FontDescriptor describes a Font.
|
// FontDescriptor describes a Font.
|
||||||
type FontDescriptor struct {
|
type FontDescriptor struct {
|
||||||
Family string
|
Family string
|
||||||
Size float64 // as a text size, for instance 12 for a 12-point font
|
Size float64 // as a text size, for instance 12 for a 12-point font
|
||||||
Weight TextWeight
|
Weight TextWeight
|
||||||
Italic TextItalic
|
Italic TextItalic
|
||||||
Stretch TextStretch
|
Stretch TextStretch
|
||||||
}
|
}
|
||||||
|
|
||||||
// Font represents an actual font that can be drawn with.
|
// Font represents an actual font that can be drawn with.
|
||||||
type Font struct {
|
type Font struct {
|
||||||
f *C.uiDrawTextFont
|
f *C.uiDrawTextFont
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadClosestFont loads a Font.
|
// LoadClosestFont loads a Font.
|
||||||
//
|
//
|
||||||
// You pass the properties of the ideal font you want to load in the
|
// You pass the properties of the ideal font you want to load in the
|
||||||
// FontDescriptor you pass to this function. If the requested font
|
// FontDescriptor you pass to this function. If the requested font
|
||||||
// is not available on the system, the closest matching font is used.
|
// is not available on the system, the closest matching font is used.
|
||||||
|
@ -682,17 +689,17 @@ type Font struct {
|
||||||
// description are implementation defined. This also means that
|
// description are implementation defined. This also means that
|
||||||
// getting a descriptor back out of a Font may return a different
|
// getting a descriptor back out of a Font may return a different
|
||||||
// desriptor.
|
// desriptor.
|
||||||
//
|
//
|
||||||
// TODO guarantee that passing *that* back into LoadClosestFont() returns the same font
|
// TODO guarantee that passing *that* back into LoadClosestFont() returns the same font
|
||||||
func LoadClosestFont(desc *FontDescriptor) *Font {
|
func LoadClosestFont(desc *FontDescriptor) *Font {
|
||||||
d := C.newFontDescriptor() // both of these are freed by C.newFont()
|
d := C.newFontDescriptor() // both of these are freed by C.newFont()
|
||||||
d.Family = C.CString(desc.Family)
|
d.Family = C.CString(desc.Family)
|
||||||
d.Size = C.double(desc.Size)
|
d.Size = C.double(desc.Size)
|
||||||
d.Weight = C.uiDrawTextWeight(desc.Weight)
|
d.Weight = C.uiDrawTextWeight(desc.Weight)
|
||||||
d.Italic = C.uiDrawTextItalic(desc.Italic)
|
d.Italic = C.uiDrawTextItalic(desc.Italic)
|
||||||
d.Stretch = C.uiDrawTextStretch(desc.Stretch)
|
d.Stretch = C.uiDrawTextStretch(desc.Stretch)
|
||||||
return &Font{
|
return &Font{
|
||||||
f: C.newFont(d),
|
f: C.newFont(d),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -705,11 +712,11 @@ func (f *Font) Free() {
|
||||||
// that use reference counting for font objects, Handle does not
|
// that use reference counting for font objects, Handle does not
|
||||||
// increment the reference count; you are sharing package ui's
|
// increment the reference count; you are sharing package ui's
|
||||||
// reference.
|
// reference.
|
||||||
//
|
//
|
||||||
// On Windows this is a pointer to an IDWriteFont.
|
// On Windows this is a pointer to an IDWriteFont.
|
||||||
//
|
//
|
||||||
// On Unix systems this is a pointer to a PangoFont.
|
// On Unix systems this is a pointer to a PangoFont.
|
||||||
//
|
//
|
||||||
// On OS X this is a CTFontRef.
|
// On OS X this is a CTFontRef.
|
||||||
func (f *Font) Handle() uintptr {
|
func (f *Font) Handle() uintptr {
|
||||||
return uintptr(C.uiDrawTextFontHandle(f.f))
|
return uintptr(C.uiDrawTextFontHandle(f.f))
|
||||||
|
@ -728,24 +735,24 @@ func (f *Font) Describe() *FontDescriptor {
|
||||||
type FontMetrics struct {
|
type FontMetrics struct {
|
||||||
// Ascent is the ascent of the font; that is, the distance from
|
// Ascent is the ascent of the font; that is, the distance from
|
||||||
// the top of the character cell to the baseline.
|
// the top of the character cell to the baseline.
|
||||||
Ascent float64
|
Ascent float64
|
||||||
|
|
||||||
// Descent is the descent of the font; that is, the distance from
|
// Descent is the descent of the font; that is, the distance from
|
||||||
// the baseline to the bottom of the character cell. The sum of
|
// the baseline to the bottom of the character cell. The sum of
|
||||||
// Ascent and Descent is the height of the character cell (and
|
// Ascent and Descent is the height of the character cell (and
|
||||||
// thus, the maximum height of a line of text).
|
// thus, the maximum height of a line of text).
|
||||||
Descent float64
|
Descent float64
|
||||||
|
|
||||||
// Leading is the amount of space the font designer suggests
|
// Leading is the amount of space the font designer suggests
|
||||||
// to have between lines (between the bottom of the first line's
|
// to have between lines (between the bottom of the first line's
|
||||||
// character cell and the top of the second line's character cell).
|
// character cell and the top of the second line's character cell).
|
||||||
// This is a suggestion; it is chosen by the font designer to
|
// This is a suggestion; it is chosen by the font designer to
|
||||||
// improve legibility.
|
// improve legibility.
|
||||||
Leading float64
|
Leading float64
|
||||||
|
|
||||||
// TODO figure out what these are
|
// TODO figure out what these are
|
||||||
UnderlinePos float64
|
UnderlinePos float64
|
||||||
UnderlineThickness float64
|
UnderlineThickness float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metrics returns metrics about the given Font.
|
// Metrics returns metrics about the given Font.
|
||||||
|
@ -764,7 +771,7 @@ func (f *Font) Metrics() *FontMetrics {
|
||||||
|
|
||||||
// TextLayout is the entry point for formatting a block of text to be
|
// TextLayout is the entry point for formatting a block of text to be
|
||||||
// drawn onto a DrawContext.
|
// drawn onto a DrawContext.
|
||||||
//
|
//
|
||||||
// The block of text to lay out and the default font that is used if no
|
// The block of text to lay out and the default font that is used if no
|
||||||
// font attributes are applied to a given character are provided
|
// font attributes are applied to a given character are provided
|
||||||
// at TextLayout creation time and cannot be changed later.
|
// at TextLayout creation time and cannot be changed later.
|
||||||
|
@ -772,18 +779,18 @@ func (f *Font) Metrics() *FontMetrics {
|
||||||
// at any time, even after drawing the text once (unlike a DrawPath).
|
// at any time, even after drawing the text once (unlike a DrawPath).
|
||||||
// Some of these attributes also have initial values; refer to each
|
// Some of these attributes also have initial values; refer to each
|
||||||
// method to see what they are.
|
// method to see what they are.
|
||||||
//
|
//
|
||||||
// The block of text can either be a single line or multiple
|
// The block of text can either be a single line or multiple
|
||||||
// word-wrapped lines, each with a given maximum width.
|
// word-wrapped lines, each with a given maximum width.
|
||||||
type TextLayout struct {
|
type TextLayout struct {
|
||||||
l *C.uiDrawTextLayout
|
l *C.uiDrawTextLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTextLayout creates a new TextLayout.
|
// NewTextLayout creates a new TextLayout.
|
||||||
// For details on the width parameter, see SetWidth.
|
// For details on the width parameter, see SetWidth.
|
||||||
func NewTextLayout(text string, defaultFont *Font, width float64) *TextLayout {
|
func NewTextLayout(text string, defaultFont *Font, width float64) *TextLayout {
|
||||||
l := new(TextLayout)
|
l := new(TextLayout)
|
||||||
ctext := C.CString(text) // freed by C.newTextLayout()
|
ctext := C.CString(text) // freed by C.newTextLayout()
|
||||||
l.l = C.newTextLayout(ctext, defaultFont.f, C.double(width))
|
l.l = C.newTextLayout(ctext, defaultFont.f, C.double(width))
|
||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
@ -806,7 +813,7 @@ func (l *TextLayout) SetWidth(width float64) {
|
||||||
// even if no glyph reaches to the top of its ascent or bottom of its
|
// even if no glyph reaches to the top of its ascent or bottom of its
|
||||||
// descent; it does not return a "best fit" rectnagle for the points that
|
// descent; it does not return a "best fit" rectnagle for the points that
|
||||||
// are actually drawn.
|
// are actually drawn.
|
||||||
//
|
//
|
||||||
// For a single-line TextLayout (where the width is negative), if there
|
// For a single-line TextLayout (where the width is negative), if there
|
||||||
// are no font changes throughout the TextLayout, then the height
|
// are no font changes throughout the TextLayout, then the height
|
||||||
// returned by TextLayout is equivalent to the sum of the ascent and
|
// returned by TextLayout is equivalent to the sum of the ascent and
|
||||||
|
|
6
entry.go
6
entry.go
|
@ -24,10 +24,10 @@ var entries = make(map[*C.uiEntry]*Entry)
|
||||||
// Entry is a Control that represents a space that the user can
|
// Entry is a Control that represents a space that the user can
|
||||||
// type a single line of text into.
|
// type a single line of text into.
|
||||||
type Entry struct {
|
type Entry struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
e *C.uiEntry
|
e *C.uiEntry
|
||||||
|
|
||||||
onChanged func(*Entry)
|
onChanged func(*Entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEntry creates a new Entry.
|
// NewEntry creates a new Entry.
|
||||||
|
|
6
group.go
6
group.go
|
@ -13,10 +13,10 @@ import "C"
|
||||||
// a labelled box (though some systems make this box invisible).
|
// a labelled box (though some systems make this box invisible).
|
||||||
// You can use this to group related controls together.
|
// You can use this to group related controls together.
|
||||||
type Group struct {
|
type Group struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
g *C.uiGroup
|
g *C.uiGroup
|
||||||
|
|
||||||
child Control
|
child Control
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGroup creates a new Group.
|
// NewGroup creates a new Group.
|
||||||
|
|
4
label.go
4
label.go
|
@ -12,8 +12,8 @@ import "C"
|
||||||
// Label is a Control that represents a line of text that cannot be
|
// Label is a Control that represents a line of text that cannot be
|
||||||
// interacted with. TODO rest of documentation.
|
// interacted with. TODO rest of documentation.
|
||||||
type Label struct {
|
type Label struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
l *C.uiLabel
|
l *C.uiLabel
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLabel creates a new Label with the given text.
|
// NewLabel creates a new Label with the given text.
|
||||||
|
|
6
main.go
6
main.go
|
@ -3,8 +3,8 @@
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -67,9 +67,9 @@ func Quit() {
|
||||||
// These prevent the passing of Go functions into C land.
|
// These prevent the passing of Go functions into C land.
|
||||||
// TODO make an actual sparse list instead of this monotonic map thingy
|
// TODO make an actual sparse list instead of this monotonic map thingy
|
||||||
var (
|
var (
|
||||||
qmmap = make(map[uintptr]func())
|
qmmap = make(map[uintptr]func())
|
||||||
qmcurrent = uintptr(0)
|
qmcurrent = uintptr(0)
|
||||||
qmlock sync.Mutex
|
qmlock sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
// QueueMain queues f to be executed on the GUI thread when
|
// QueueMain queues f to be executed on the GUI thread when
|
||||||
|
|
|
@ -12,8 +12,8 @@ import "C"
|
||||||
// ProgressBar is a Control that represents a horizontal bar that
|
// ProgressBar is a Control that represents a horizontal bar that
|
||||||
// is filled in progressively over time as a process completes.
|
// is filled in progressively over time as a process completes.
|
||||||
type ProgressBar struct {
|
type ProgressBar struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
p *C.uiProgressBar
|
p *C.uiProgressBar
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProgressBar creates a new ProgressBar.
|
// NewProgressBar creates a new ProgressBar.
|
||||||
|
|
|
@ -12,8 +12,8 @@ import "C"
|
||||||
// RadioButtons is a Control that represents a set of checkable
|
// RadioButtons is a Control that represents a set of checkable
|
||||||
// buttons from which exactly one may be chosen by the user.
|
// buttons from which exactly one may be chosen by the user.
|
||||||
type RadioButtons struct {
|
type RadioButtons struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
r *C.uiRadioButtons
|
r *C.uiRadioButtons
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRadioButtons creates a new RadioButtons.
|
// NewRadioButtons creates a new RadioButtons.
|
||||||
|
|
|
@ -21,10 +21,10 @@ var sliders = make(map[*C.uiSlider]*Slider)
|
||||||
// a range of integers. The user can drag a pointer on the bar to
|
// a range of integers. The user can drag a pointer on the bar to
|
||||||
// select an integer.
|
// select an integer.
|
||||||
type Slider struct {
|
type Slider struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
s *C.uiSlider
|
s *C.uiSlider
|
||||||
|
|
||||||
onChanged func(*Slider)
|
onChanged func(*Slider)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSlider creates a new Slider. If min >= max, they are swapped.
|
// NewSlider creates a new Slider. If min >= max, they are swapped.
|
||||||
|
|
|
@ -21,10 +21,10 @@ var spinboxes = make(map[*C.uiSpinbox]*Spinbox)
|
||||||
// enter integers. The space also comes with buttons to add or
|
// enter integers. The space also comes with buttons to add or
|
||||||
// subtract 1 from the integer.
|
// subtract 1 from the integer.
|
||||||
type Spinbox struct {
|
type Spinbox struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
s *C.uiSpinbox
|
s *C.uiSpinbox
|
||||||
|
|
||||||
onChanged func(*Spinbox)
|
onChanged func(*Spinbox)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSpinbox creates a new Spinbox. If min >= max, they are swapped.
|
// NewSpinbox creates a new Spinbox. If min >= max, they are swapped.
|
||||||
|
|
12
tab.go
12
tab.go
|
@ -13,10 +13,10 @@ import "C"
|
||||||
// has a label. The user can click on the tabs themselves to switch
|
// has a label. The user can click on the tabs themselves to switch
|
||||||
// pages. Individual pages can also have margins.
|
// pages. Individual pages can also have margins.
|
||||||
type Tab struct {
|
type Tab struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
t *C.uiTab
|
t *C.uiTab
|
||||||
|
|
||||||
children []Control
|
children []Control
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTab creates a new Tab.
|
// NewTab creates a new Tab.
|
||||||
|
@ -94,17 +94,17 @@ func (t *Tab) InsertAt(name string, n int, child Control) {
|
||||||
// TODO why is this uintmax_t and not intmax_t
|
// TODO why is this uintmax_t and not intmax_t
|
||||||
C.uiTabInsertAt(t.t, cname, C.uintmax_t(n), c)
|
C.uiTabInsertAt(t.t, cname, C.uintmax_t(n), c)
|
||||||
freestr(cname)
|
freestr(cname)
|
||||||
ch := make([]Control, len(t.children) + 1)
|
ch := make([]Control, len(t.children)+1)
|
||||||
// and insert into t.children at the right place
|
// and insert into t.children at the right place
|
||||||
copy(ch[:n], t.children[:n])
|
copy(ch[:n], t.children[:n])
|
||||||
ch[n] = child
|
ch[n] = child
|
||||||
copy(ch[n + 1:], t.children[n:])
|
copy(ch[n+1:], t.children[n:])
|
||||||
t.children = ch
|
t.children = ch
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes the nth page of the Tab.
|
// Delete deletes the nth page of the Tab.
|
||||||
func (t *Tab) Delete(n int) {
|
func (t *Tab) Delete(n int) {
|
||||||
t.children = append(t.children[:n], t.children[n + 1:]...)
|
t.children = append(t.children[:n], t.children[n+1:]...)
|
||||||
C.uiTabDelete(t.t, C.uintmax_t(n))
|
C.uiTabDelete(t.t, C.uintmax_t(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
util.go
2
util.go
|
@ -20,7 +20,7 @@ import "C"
|
||||||
// of the desired length, we get our C.CMalloc(). Using a slice
|
// of the desired length, we get our C.CMalloc(). Using a slice
|
||||||
// that's always initialized to zero gives us the ZeroMemory()
|
// that's always initialized to zero gives us the ZeroMemory()
|
||||||
// for free.
|
// for free.
|
||||||
var uimallocBytes = make([]byte, 1024) // 1024 bytes first
|
var uimallocBytes = make([]byte, 1024) // 1024 bytes first
|
||||||
|
|
||||||
//export uimalloc
|
//export uimalloc
|
||||||
func uimalloc(n C.size_t) unsafe.Pointer {
|
func uimalloc(n C.size_t) unsafe.Pointer {
|
||||||
|
|
|
@ -22,12 +22,12 @@ var windows = make(map[*C.uiWindow]*Window)
|
||||||
// entirety of the window. Though a Window is a Control,
|
// entirety of the window. Though a Window is a Control,
|
||||||
// a Window cannot be the child of another Control.
|
// a Window cannot be the child of another Control.
|
||||||
type Window struct {
|
type Window struct {
|
||||||
c *C.uiControl
|
c *C.uiControl
|
||||||
w *C.uiWindow
|
w *C.uiWindow
|
||||||
|
|
||||||
child Control
|
child Control
|
||||||
|
|
||||||
onClosing func(w *Window) bool
|
onClosing func(w *Window) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWindow creates a new Window.
|
// NewWindow creates a new Window.
|
||||||
|
|
|
@ -5,8 +5,8 @@ package ui
|
||||||
var page2group *Group
|
var page2group *Group
|
||||||
|
|
||||||
var (
|
var (
|
||||||
movingLabel *Label
|
movingLabel *Label
|
||||||
movingBoxes [2]*Box
|
movingBoxes [2]*Box
|
||||||
movingCurrent int
|
movingCurrent int
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,8 +22,9 @@ func moveLabel(*Button) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var moveBack bool
|
var moveBack bool
|
||||||
|
|
||||||
const (
|
const (
|
||||||
moveOutText = "Move Page 1 Out"
|
moveOutText = "Move Page 1 Out"
|
||||||
moveBackText = "Move Page 1 Back"
|
moveBackText = "Move Page 1 Back"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ func makePage2() *Box {
|
||||||
button = NewButton("Open Menuless Window")
|
button = NewButton("Open Menuless Window")
|
||||||
button.OnClicked(func(*Button) {
|
button.OnClicked(func(*Button) {
|
||||||
w := NewWindow("Another Window", 100, 100, true)
|
w := NewWindow("Another Window", 100, 100, true)
|
||||||
//TODO w.SetChild(makePage6())
|
//TODO w.SetChild(makePage6())
|
||||||
w.SetMargined(true)
|
w.SetMargined(true)
|
||||||
w.Show()
|
w.Show()
|
||||||
})
|
})
|
||||||
|
@ -154,8 +155,8 @@ func makePage2() *Box {
|
||||||
page2.Append(hbox, false)
|
page2.Append(hbox, false)
|
||||||
|
|
||||||
disabledTab := newTab()
|
disabledTab := newTab()
|
||||||
disabledTab.Append("Disabled", NewButton("Button"));
|
disabledTab.Append("Disabled", NewButton("Button"))
|
||||||
disabledTab.Append("Tab", NewLabel("Label"));
|
disabledTab.Append("Tab", NewLabel("Label"))
|
||||||
disabledTab.Disable()
|
disabledTab.Disable()
|
||||||
page2.Append(disabledTab, true)
|
page2.Append(disabledTab, true)
|
||||||
|
|
||||||
|
|
10
zz_test.go
10
zz_test.go
|
@ -8,9 +8,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
nomenus = flag.Bool("nomenus", false, "No menus")
|
nomenus = flag.Bool("nomenus", false, "No menus")
|
||||||
startspaced = flag.Bool("startspaced", false, "Start with spacing")
|
startspaced = flag.Bool("startspaced", false, "Start with spacing")
|
||||||
swaphv = flag.Bool("swaphv", false, "Swap horizontal and vertical boxes")
|
swaphv = flag.Bool("swaphv", false, "Swap horizontal and vertical boxes")
|
||||||
)
|
)
|
||||||
|
|
||||||
var mainbox *Box
|
var mainbox *Box
|
||||||
|
@ -64,9 +64,9 @@ func TestIt(t *testing.T) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
spwindows []*Window
|
spwindows []*Window
|
||||||
sptabs []*Tab
|
sptabs []*Tab
|
||||||
spgroups []*Group
|
spgroups []*Group
|
||||||
spboxes []*Box
|
spboxes []*Box
|
||||||
)
|
)
|
||||||
|
|
||||||
func newWindow(title string, width int, height int, hasMenubar bool) *Window {
|
func newWindow(title string, width int, height int, hasMenubar bool) *Window {
|
||||||
|
|
Loading…
Reference in New Issue