gofmt files
This commit is contained in:
parent
2dde2a79e7
commit
1ec8f6b01c
8
area.go
8
area.go
|
@ -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.
|
||||||
|
|
|
@ -135,7 +135,7 @@ 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.
|
||||||
|
@ -143,17 +143,17 @@ type AreaDrawParams struct {
|
||||||
// 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,13 +161,13 @@ 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)
|
||||||
}
|
}
|
||||||
|
@ -176,8 +176,8 @@ func doAreaHandlerDraw(uah *C.uiAreaHandler, ua *C.uiArea, udp *C.uiAreaDrawPara
|
||||||
//
|
//
|
||||||
// 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.
|
||||||
|
@ -185,20 +185,20 @@ type AreaMouseEvent struct {
|
||||||
// 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,11 +254,11 @@ 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))
|
||||||
}
|
}
|
||||||
|
@ -267,6 +267,7 @@ func doAreaHandlerKeyEvent(uah *C.uiAreaHandler, ua *C.uiArea, uke *C.uiAreaKeyE
|
||||||
//
|
//
|
||||||
// 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
|
||||||
|
@ -278,9 +279,10 @@ const (
|
||||||
//
|
//
|
||||||
// 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 {
|
||||||
|
|
|
@ -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
|
||||||
|
|
109
draw.go
109
draw.go
|
@ -159,13 +159,14 @@ import "C"
|
||||||
// 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,18 +271,19 @@ 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
|
||||||
|
@ -289,6 +291,7 @@ const (
|
||||||
// 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
|
||||||
|
@ -299,6 +302,7 @@ const (
|
||||||
//
|
//
|
||||||
// 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
|
||||||
|
@ -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(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,6 +613,7 @@ func (f *FontFamilies) Family(n int) string {
|
||||||
//
|
//
|
||||||
// TODO disclaimer
|
// TODO disclaimer
|
||||||
type TextWeight int
|
type TextWeight int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TextWeightThin TextWeight = iota
|
TextWeightThin TextWeight = iota
|
||||||
TextWeightUltraLight
|
TextWeightUltraLight
|
||||||
|
@ -627,10 +632,11 @@ const (
|
||||||
//
|
//
|
||||||
// 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
|
||||||
|
@ -644,6 +650,7 @@ const (
|
||||||
//
|
//
|
||||||
// TODO disclaimer
|
// TODO disclaimer
|
||||||
type TextStretch int
|
type TextStretch int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TextStretchUltraCondensed TextStretch = iota
|
TextStretchUltraCondensed TextStretch = iota
|
||||||
TextStretchExtraCondensed
|
TextStretchExtraCondensed
|
||||||
|
@ -658,16 +665,16 @@ 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.
|
||||||
|
@ -685,14 +692,14 @@ type Font struct {
|
||||||
//
|
//
|
||||||
// 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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
||||||
|
@ -776,14 +783,14 @@ func (f *Font) Metrics() *FontMetrics {
|
||||||
// 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
|
||||||
}
|
}
|
||||||
|
|
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