gofmt files

This commit is contained in:
polypmer 2016-09-07 07:52:52 -04:00
parent 2dde2a79e7
commit 1ec8f6b01c
22 changed files with 226 additions and 215 deletions

14
area.go
View File

@ -18,7 +18,7 @@ var areas = make(map[*C.uiArea]*Area)
// and event handling are handled through an instance of a type
// that implements AreaHandler that every Area has; see AreaHandler
// for details.
//
//
// There are two types of areas. Non-scrolling areas are rectangular
// 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
@ -28,7 +28,7 @@ var areas = make(map[*C.uiArea]*Area)
// size changes; instead, you are given the area size as part of the
// draw and mouse event handlers, for use solely within those
// handlers.
//
//
// Scrolling areas have horziontal and vertical scrollbars. The amount
// that can be scrolled is determined by the area's size, which is
// 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
// what portion is visible, so you do not have to worry about scrolling
// in your event handlers. AreaHandler has more information.
//
//
// The internal coordinate system of an Area is points, which are
// floating-point and device-independent. For more details, see
// 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
// structures (including sizes of drawn objects) are float64s.
type Area struct {
c *C.uiControl
a *C.uiArea
c *C.uiControl
a *C.uiArea
ah *C.uiAreaHandler
ah *C.uiAreaHandler
scrolling bool
scrolling bool
}
// NewArea creates a new non-scrolling Area.

View File

@ -12,7 +12,7 @@ package ui
// static inline uiAreaHandler *allocAreaHandler(void)
// {
// uiAreaHandler *ah;
//
//
// ah = (uiAreaHandler *) malloc(sizeof (uiAreaHandler));
// if (ah == NULL) // TODO
// 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
// call (so for instance, do not save AreaDrawParams.AreaWidth, as
// that might change without generating an event).
//
//
// Coordinates to Draw and MouseEvent are given in points. Points
// are generic, floating-point, device-independent coordinates with
// (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
// 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
//
//
// For a scrolling Area, points are automatically offset by the scroll
// position. So if the mouse moves to position (5,5) while the
// 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
// have been cleared by the system prior to drawing, so you are
// always working on a clean slate.
//
//
// If you call Save on the drawing context, you must call Release
// before returning from Draw, and the number of calls to Save
// 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
// or when a mouse button is pressed or released. See
// AreaMouseEvent for more details.
//
//
// If a mouse button is being held, MouseEvents will continue to
// be generated, even if the mouse is not within the area. On
// 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
// held (see MouseEvent above). If the mouse has entered the
// 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
// the Area, MouseCrossed will be called with left=false.
// TODO what about future shows?
@ -95,7 +95,7 @@ type AreaHandler interface {
// method is provided to allow your program to cope with the
// loss of the mouse in this case. You should cope by cancelling
// whatever drag-related operation you were doing.
//
//
// Note that this is only generated on some systems under
// specific conditions. Do not implement behavior that only
// 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
// keyboard focus (if the Area has been tabbed into or if the
// mouse has been clicked on it). See AreaKeyEvent for specifics.
//
//
// Because some keyboard events are handled by the system
// (for instance, menu accelerators and global hotkeys), you
// must return whether you handled the key event; return true
@ -135,25 +135,25 @@ func unregisterAreaHandler(uah *C.uiAreaHandler) {
type AreaDrawParams struct {
// Context is the drawing context to draw on. See DrawContext
// for how to draw.
Context *DrawContext
Context *DrawContext
// AreaWidth and AreaHeight provide the size of the Area for
// non-scrolling Areas. For scrolling Areas both values are zero.
//
//
// To reiterate the AreaHandler documentation, do NOT save
// these values for later; they can change without generating
// an event.
AreaWidth float64
AreaHeight float64
AreaWidth float64
AreaHeight float64
// These four fields define the rectangle that needs to be
// redrawn. The system will not draw anything outside this
// rectangle, but you can make your drawing faster if you
// also stay within the lines.
ClipX float64
ClipY float64
ClipWidth float64
ClipHeight float64
ClipX float64
ClipY float64
ClipWidth float64
ClipHeight float64
}
//export doAreaHandlerDraw
@ -161,44 +161,44 @@ func doAreaHandlerDraw(uah *C.uiAreaHandler, ua *C.uiArea, udp *C.uiAreaDrawPara
ah := areahandlers[uah]
a := areas[ua]
dp := &AreaDrawParams{
Context: &DrawContext{udp.Context},
AreaWidth: float64(udp.AreaWidth),
AreaHeight: float64(udp.AreaHeight),
ClipX: float64(udp.ClipX),
ClipY: float64(udp.ClipY),
ClipWidth: float64(udp.ClipWidth),
ClipHeight: float64(udp.ClipHeight),
Context: &DrawContext{udp.Context},
AreaWidth: float64(udp.AreaWidth),
AreaHeight: float64(udp.AreaHeight),
ClipX: float64(udp.ClipX),
ClipY: float64(udp.ClipY),
ClipWidth: float64(udp.ClipWidth),
ClipHeight: float64(udp.ClipHeight),
}
ah.Draw(a, dp)
}
// 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
type AreaMouseEvent struct {
X float64
Y float64
X float64
Y float64
// AreaWidth and AreaHeight provide the size of the Area for
// non-scrolling Areas. For scrolling Areas both values are zero.
//
//
// To reiterate the AreaHandler documentation, do NOT save
// these values for later; they can change without generating
// an event.
AreaWidth float64
AreaHeight float64
AreaWidth float64
AreaHeight float64
Down uint
Up uint
Count uint
Modifiers Modifiers
Held []uint
Down uint
Up uint
Count uint
Modifiers Modifiers
Held []uint
}
func appendBits(out []uint, held C.uint64_t) []uint {
n := uint(1)
for i := 0; i < 64; i++ {
if held & 1 != 0 {
if held&1 != 0 {
out = append(out, n)
}
held >>= 1
@ -212,15 +212,15 @@ func doAreaHandlerMouseEvent(uah *C.uiAreaHandler, ua *C.uiArea, ume *C.uiAreaMo
ah := areahandlers[uah]
a := areas[ua]
me := &AreaMouseEvent{
X: float64(ume.X),
Y: float64(ume.Y),
AreaWidth: float64(ume.AreaWidth),
AreaHeight: float64(ume.AreaHeight),
Down: uint(ume.Down),
Up: uint(ume.Up),
Count: uint(ume.Count),
Modifiers: Modifiers(ume.Modifiers),
Held: make([]uint, 0, 64),
X: float64(ume.X),
Y: float64(ume.Y),
AreaWidth: float64(ume.AreaWidth),
AreaHeight: float64(ume.AreaHeight),
Down: uint(ume.Down),
Up: uint(ume.Up),
Count: uint(ume.Count),
Modifiers: Modifiers(ume.Modifiers),
Held: make([]uint, 0, 64),
}
me.Held = appendBits(me.Held, ume.Held1To64)
ah.MouseEvent(a, me)
@ -242,11 +242,11 @@ func doAreaHandlerDragBroken(uah *C.uiAreaHandler, ua *C.uiArea) {
// TODO document all these
type AreaKeyEvent struct {
Key rune
ExtKey ExtKey
Modifier Modifiers
Modifiers Modifiers
Up bool
Key rune
ExtKey ExtKey
Modifier Modifiers
Modifiers Modifiers
Up bool
}
//export doAreaHandlerKeyEvent
@ -254,19 +254,20 @@ func doAreaHandlerKeyEvent(uah *C.uiAreaHandler, ua *C.uiArea, uke *C.uiAreaKeyE
ah := areahandlers[uah]
a := areas[ua]
ke := &AreaKeyEvent{
Key: rune(uke.Key),
ExtKey: ExtKey(uke.ExtKey),
Modifier: Modifiers(uke.Modifier),
Modifiers: Modifiers(uke.Modifiers),
Up: tobool(uke.Up),
Key: rune(uke.Key),
ExtKey: ExtKey(uke.ExtKey),
Modifier: Modifiers(uke.Modifier),
Modifiers: Modifiers(uke.Modifiers),
Up: tobool(uke.Up),
}
return frombool(ah.KeyEvent(a, ke))
}
// TODO document
//
//
// Note: these must be numerically identical to their libui equivalents.
type Modifiers uint
const (
Ctrl Modifiers = 1 << iota
Alt
@ -275,12 +276,13 @@ const (
)
// TODO document
//
//
// Note: these must be numerically identical to their libui equivalents.
type ExtKey int
const (
Escape ExtKey = iota + 1
Insert // equivalent to "Help" on Apple keyboards
Insert // equivalent to "Help" on Apple keyboards
Delete
Home
End
@ -290,7 +292,7 @@ const (
Down
Left
Right
F1 // F1..F12 are guaranteed to be consecutive
F1 // F1..F12 are guaranteed to be consecutive
F2
F3
F4
@ -302,8 +304,8 @@ const (
F10
F11
F12
N0 // numpad keys; independent of Num Lock state
N1 // N0..N9 are guaranteed to be consecutive
N0 // numpad keys; independent of Num Lock state
N1 // N0..N9 are guaranteed to be consecutive
N2
N3
N4

8
box.go
View File

@ -18,10 +18,10 @@ import "C"
// stretchy, they will be given equal shares of the leftover space.
// There can also be space between each control ("padding").
type Box struct {
c *C.uiControl
b *C.uiBox
c *C.uiControl
b *C.uiBox
children []Control
children []Control
}
// 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.
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
C.uiBoxDelete(b.b, C.uintmax_t(n))
}

View File

@ -21,10 +21,10 @@ var buttons = make(map[*C.uiButton]*Button)
// click to perform an action. A Button has a text label that should
// describe what the button does.
type Button struct {
c *C.uiControl
b *C.uiButton
c *C.uiControl
b *C.uiButton
onClicked func(*Button)
onClicked func(*Button)
}
// NewButton creates a new Button with the given text as its label.

View File

@ -21,10 +21,10 @@ var checkboxes = make(map[*C.uiCheckbox]*Checkbox)
// side. When the user clicks the checkbox, a check mark will appear
// in the box; clicking it again removes the check.
type Checkbox struct {
co *C.uiControl
c *C.uiCheckbox
co *C.uiControl
c *C.uiCheckbox
onToggled func(*Checkbox)
onToggled func(*Checkbox)
}
// NewCheckbox creates a new Checkbox with the given text as its label.

View File

@ -22,10 +22,10 @@ var comboboxes = make(map[*C.uiCombobox]*Combobox)
// Combobox also has an entry field that the user can type an alternate
// choice into.
type Combobox struct {
co *C.uiControl
c *C.uiCombobox
co *C.uiControl
c *C.uiCombobox
onSelected func(*Combobox)
onSelected func(*Combobox)
}
// NewCombobox creates a new Combobox.
@ -41,6 +41,7 @@ func NewCombobox() *Combobox {
return c
}
/*TODO
// NewEditableCombobox creates a new editable Combobox.
func NewEditableCombobox() *Combobox {

View File

@ -11,14 +11,14 @@ import "C"
// Control represents a GUI control. It provdes methods
// common to all Controls.
//
//
// To create a new Control, implement the control on
// the libui side, then provide access to that control on
// the Go side via an implementation of Control as
// described.
type Control interface {
// Destroy destroys the Control.
//
//
// Implementations should do any necessary cleanup,
// then call LibuiControlDestroy.
Destroy()
@ -32,30 +32,30 @@ type Control interface {
// Control. On OSs that use reference counting for
// controls, Handle does not increment the reference
// count; you are sharing package ui's reference.
//
//
// Implementations should call LibuiControlHandle and
// document exactly what kind of handle is returned.
Handle() uintptr
// Show shows the Control.
//
//
// Implementations should call LibuiControlShow.
Show()
// Hide shows the Control. Hidden controls do not participate
// in layout (that is, Box, Grid, etc. does not reserve space for
// hidden controls).
//
//
// Implementations should call LibuiControlHide.
Hide()
// Enable enables the Control.
//
//
// Implementations should call LibuiControlEnable.
Enable()
// Disable disables the Control.
//
//
// Implementations should call LibuiControlDisable.
Disable()
}

View File

@ -12,8 +12,8 @@ import "C"
// DateTimePicker is a Control that represents a field where the user
// can enter a date and/or a time.
type DateTimePicker struct {
c *C.uiControl
d *C.uiDateTimePicker
c *C.uiControl
d *C.uiDateTimePicker
}
// NewDateTimePicker creates a new DateTimePicker that shows

173
draw.go
View File

@ -9,14 +9,14 @@ package ui
// static uiDrawBrush *newBrush(void)
// {
// uiDrawBrush *b;
//
//
// b = (uiDrawBrush *) uimalloc(sizeof (uiDrawBrush));
// return b;
// }
// static uiDrawBrushGradientStop *newStops(size_t n)
// {
// uiDrawBrushGradientStop *stops;
//
//
// stops = (uiDrawBrushGradientStop *) malloc(n * sizeof (uiDrawBrushGradientStop));
// // TODO
// return stops;
@ -38,7 +38,7 @@ package ui
// static uiDrawStrokeParams *newStrokeParams(void)
// {
// uiDrawStrokeParams *b;
//
//
// b = (uiDrawStrokeParams *) malloc(sizeof (uiDrawStrokeParams));
// // TODO
// return b;
@ -46,7 +46,7 @@ package ui
// static double *newDashes(size_t n)
// {
// double *dashes;
//
//
// dashes = (double *) malloc(n * sizeof (double));
// // TODO
// return dashes;
@ -64,7 +64,7 @@ package ui
// static uiDrawMatrix *newMatrix(void)
// {
// uiDrawMatrix *m;
//
//
// m = (uiDrawMatrix *) malloc(sizeof (uiDrawMatrix));
// // TODO
// return m;
@ -76,7 +76,7 @@ package ui
// static uiDrawTextFontDescriptor *newFontDescriptor(void)
// {
// uiDrawTextFontDescriptor *desc;
//
//
// desc = (uiDrawTextFontDescriptor *) malloc(sizeof (uiDrawTextFontDescriptor));
// // TODO
// return desc;
@ -84,7 +84,7 @@ package ui
// static uiDrawTextFont *newFont(uiDrawTextFontDescriptor *desc)
// {
// uiDrawTextFont *font;
//
//
// font = uiDrawLoadClosestFont(desc);
// free((char *) (desc->Family));
// free(desc);
@ -93,7 +93,7 @@ package ui
// static uiDrawTextLayout *newTextLayout(char *text, uiDrawTextFont *defaultFont, double width)
// {
// uiDrawTextLayout *layout;
//
//
// layout = uiDrawNewTextLayout(text, defaultFont, width);
// free(text);
// return layout;
@ -101,7 +101,7 @@ package ui
// static uiDrawTextFontMetrics *newFontMetrics(void)
// {
// uiDrawTextFontMetrics *m;
//
//
// m = (uiDrawTextFontMetrics *) malloc(sizeof (uiDrawTextFontMetrics));
// // TODO
// return m;
@ -113,7 +113,7 @@ package ui
// static double *newDouble(void)
// {
// double *d;
//
//
// d = (double *) malloc(sizeof (double));
// // TODO
// return d;
@ -135,7 +135,7 @@ import "C"
// figures to a path, you must "end" the path to make it ready to draw
// with.
// TODO rewrite all that
//
//
// Or more visually, the lifecycle of a Path is
// p := NewPath()
// for every figure {
@ -154,18 +154,19 @@ import "C"
// dp.Context.Clip(p)
// // ...
// p.Free() // when done with the path
//
//
// A Path also defines its fill mode. (This should ideally be a fill
// parameter, but some implementations prevent it.)
// TODO talk about fill modes
type Path struct {
p *C.uiDrawPath
p *C.uiDrawPath
}
// TODO
//
//
// TODO disclaimer
type FillMode uint
const (
Winding FillMode = iota
Alternate
@ -184,7 +185,7 @@ func NewPath(fillMode FillMode) *Path {
panic("invalid fill mode passed to ui.NewPath()")
}
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
// Areas and are provided by package ui; see AreaDrawParams.
type DrawContext struct {
c *C.uiDrawContext
c *C.uiDrawContext
}
// BrushType defines the various types of brushes.
//
//
// TODO disclaimer
type BrushType int
const (
Solid BrushType = iota
LinearGradient
RadialGradient
Image // presently unimplemented
Image // presently unimplemented
)
// TODO
//
//
// TODO disclaimer
// TODO rename these to put LineCap at the beginning? or just Cap?
type LineCap int
const (
FlatCap LineCap = iota
RoundCap
@ -296,9 +299,10 @@ const (
)
// TODO
//
//
// TODO disclaimer
type LineJoin int
const (
MiterJoin LineJoin = iota
RoundJoin
@ -310,32 +314,32 @@ const DefaultMiterLimit = 10.0
// TODO
type Brush struct {
Type BrushType
Type BrushType
// If Type is Solid.
// TODO
R float64
G float64
B float64
A float64
R float64
G float64
B float64
A float64
// If Type is LinearGradient or RadialGradient.
// TODO
X0 float64 // start point for both
Y0 float64
X1 float64 // linear: end point; radial: circle center
Y1 float64
OuterRadius float64 // for radial gradients only
Stops []GradientStop
X0 float64 // start point for both
Y0 float64
X1 float64 // linear: end point; radial: circle center
Y1 float64
OuterRadius float64 // for radial gradients only
Stops []GradientStop
}
// TODO
type GradientStop struct {
Pos float64 // between 0 and 1 inclusive
R float64
G float64
B float64
A float64
Pos float64 // between 0 and 1 inclusive
R float64
G float64
B float64
A float64
}
func (b *Brush) toC() *C.uiDrawBrush {
@ -373,12 +377,12 @@ func (b *Brush) toC() *C.uiDrawBrush {
// TODO
type StrokeParams struct {
Cap LineCap
Join LineJoin
Thickness float64
MiterLimit float64
Dashes []float64
DashPhase float64
Cap LineCap
Join LineJoin
Thickness float64
MiterLimit float64
Dashes []float64
DashPhase float64
}
func (sp *StrokeParams) toC() *C.uiDrawStrokeParams {
@ -418,12 +422,12 @@ func (c *DrawContext) Fill(p *Path, b *Brush) {
// TODO
// TODO should the methods of these return self for chaining?
type Matrix struct {
M11 float64
M12 float64
M21 float64
M22 float64
M31 float64
M32 float64
M11 float64
M12 float64
M21 float64
M22 float64
M31 float64
M32 float64
}
// TODO identity matrix
@ -514,7 +518,7 @@ func (m *Matrix) Invertible() bool {
}
// TODO
//
//
// If m is not invertible, false is returned and m is left unchanged.
func (m *Matrix) Invert() bool {
cm := m.toC()
@ -564,10 +568,10 @@ func (c *DrawContext) Restore() {
// call (TODO verify). Use NumFamilies to get the number of families,
// and Family to get the name of a given family by index. When
// finished, call Free.
//
//
// There is no guarantee that the list of families is sorted. You will
// need to do sorting yourself if you need it.
//
//
// TODO thread affinity
type FontFamilies struct {
ff *C.uiDrawFontFamilies
@ -576,7 +580,7 @@ type FontFamilies struct {
// ListFontFamilies creates a new FontFamilies object ready for use.
func ListFontFamilies() *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
// increasing weight.
//
//
// Note that if you leave this field unset, it will default to
// TextWeightThin. If you want the normal font weight, explicitly
// use the constant TextWeightNormal instead.
// TODO realign these?
//
//
// TODO disclaimer
type TextWeight int
const (
TextWeightThin TextWeight = iota
TextWeightUltraLight
@ -624,26 +629,28 @@ const (
)
// TextItalic defines the various text italic modes.
//
//
// TODO disclaimer
type TextItalic int
const (
TextItalicNormal TextItalic = iota
TextItalicOblique // merely slanted text
TextItalicItalic // true italics
TextItalicNormal TextItalic = iota
TextItalicOblique // merely slanted text
TextItalicItalic // true italics
)
// TextStretch defines the various text stretches, in order of
// increasing wideness.
//
//
// Note that if you leave this field unset, it will default to
// TextStretchUltraCondensed. If you want the normal font
// stretch, explicitly use the constant TextStretchNormal
// instead.
// TODO realign these?
//
//
// TODO disclaimer
type TextStretch int
const (
TextStretchUltraCondensed TextStretch = iota
TextStretchExtraCondensed
@ -658,20 +665,20 @@ const (
// FontDescriptor describes a Font.
type FontDescriptor struct {
Family string
Size float64 // as a text size, for instance 12 for a 12-point font
Weight TextWeight
Italic TextItalic
Stretch TextStretch
Family string
Size float64 // as a text size, for instance 12 for a 12-point font
Weight TextWeight
Italic TextItalic
Stretch TextStretch
}
// Font represents an actual font that can be drawn with.
type Font struct {
f *C.uiDrawTextFont
f *C.uiDrawTextFont
}
// LoadClosestFont loads a Font.
//
//
// You pass the properties of the ideal font you want to load in the
// FontDescriptor you pass to this function. If the requested font
// 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
// getting a descriptor back out of a Font may return a different
// desriptor.
//
//
// TODO guarantee that passing *that* back into LoadClosestFont() returns the same 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.Size = C.double(desc.Size)
d.Weight = C.uiDrawTextWeight(desc.Weight)
d.Italic = C.uiDrawTextItalic(desc.Italic)
d.Stretch = C.uiDrawTextStretch(desc.Stretch)
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
// increment the reference count; you are sharing package ui's
// reference.
//
//
// On Windows this is a pointer to an IDWriteFont.
//
//
// On Unix systems this is a pointer to a PangoFont.
//
//
// On OS X this is a CTFontRef.
func (f *Font) Handle() uintptr {
return uintptr(C.uiDrawTextFontHandle(f.f))
@ -728,24 +735,24 @@ func (f *Font) Describe() *FontDescriptor {
type FontMetrics struct {
// Ascent is the ascent of the font; that is, the distance from
// 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
// the baseline to the bottom of the character cell. The sum of
// Ascent and Descent is the height of the character cell (and
// thus, the maximum height of a line of text).
Descent float64
Descent float64
// Leading is the amount of space the font designer suggests
// to have between lines (between the bottom of the first line's
// character cell and the top of the second line's character cell).
// This is a suggestion; it is chosen by the font designer to
// improve legibility.
Leading float64
Leading float64
// TODO figure out what these are
UnderlinePos float64
UnderlineThickness float64
UnderlinePos float64
UnderlineThickness float64
}
// 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
// drawn onto a DrawContext.
//
//
// 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
// 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).
// Some of these attributes also have initial values; refer to each
// method to see what they are.
//
//
// The block of text can either be a single line or multiple
// word-wrapped lines, each with a given maximum width.
type TextLayout struct {
l *C.uiDrawTextLayout
l *C.uiDrawTextLayout
}
// NewTextLayout creates a new TextLayout.
// For details on the width parameter, see SetWidth.
func NewTextLayout(text string, defaultFont *Font, width float64) *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))
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
// descent; it does not return a "best fit" rectnagle for the points that
// are actually drawn.
//
//
// For a single-line TextLayout (where the width is negative), if there
// are no font changes throughout the TextLayout, then the height
// returned by TextLayout is equivalent to the sum of the ascent and

View File

@ -24,10 +24,10 @@ var entries = make(map[*C.uiEntry]*Entry)
// Entry is a Control that represents a space that the user can
// type a single line of text into.
type Entry struct {
c *C.uiControl
e *C.uiEntry
c *C.uiControl
e *C.uiEntry
onChanged func(*Entry)
onChanged func(*Entry)
}
// NewEntry creates a new Entry.

View File

@ -13,10 +13,10 @@ import "C"
// a labelled box (though some systems make this box invisible).
// You can use this to group related controls together.
type Group struct {
c *C.uiControl
g *C.uiGroup
c *C.uiControl
g *C.uiGroup
child Control
child Control
}
// NewGroup creates a new Group.

View File

@ -12,8 +12,8 @@ import "C"
// Label is a Control that represents a line of text that cannot be
// interacted with. TODO rest of documentation.
type Label struct {
c *C.uiControl
l *C.uiLabel
c *C.uiControl
l *C.uiLabel
}
// NewLabel creates a new Label with the given text.

View File

@ -3,8 +3,8 @@
package ui
import (
"runtime"
"errors"
"runtime"
"sync"
"unsafe"
)
@ -67,9 +67,9 @@ func Quit() {
// These prevent the passing of Go functions into C land.
// TODO make an actual sparse list instead of this monotonic map thingy
var (
qmmap = make(map[uintptr]func())
qmmap = make(map[uintptr]func())
qmcurrent = uintptr(0)
qmlock sync.Mutex
qmlock sync.Mutex
)
// QueueMain queues f to be executed on the GUI thread when

View File

@ -12,8 +12,8 @@ import "C"
// ProgressBar is a Control that represents a horizontal bar that
// is filled in progressively over time as a process completes.
type ProgressBar struct {
c *C.uiControl
p *C.uiProgressBar
c *C.uiControl
p *C.uiProgressBar
}
// NewProgressBar creates a new ProgressBar.

View File

@ -12,8 +12,8 @@ import "C"
// RadioButtons is a Control that represents a set of checkable
// buttons from which exactly one may be chosen by the user.
type RadioButtons struct {
c *C.uiControl
r *C.uiRadioButtons
c *C.uiControl
r *C.uiRadioButtons
}
// NewRadioButtons creates a new RadioButtons.

View File

@ -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
// select an integer.
type Slider struct {
c *C.uiControl
s *C.uiSlider
c *C.uiControl
s *C.uiSlider
onChanged func(*Slider)
onChanged func(*Slider)
}
// NewSlider creates a new Slider. If min >= max, they are swapped.

View File

@ -21,10 +21,10 @@ var spinboxes = make(map[*C.uiSpinbox]*Spinbox)
// enter integers. The space also comes with buttons to add or
// subtract 1 from the integer.
type Spinbox struct {
c *C.uiControl
s *C.uiSpinbox
c *C.uiControl
s *C.uiSpinbox
onChanged func(*Spinbox)
onChanged func(*Spinbox)
}
// NewSpinbox creates a new Spinbox. If min >= max, they are swapped.

12
tab.go
View File

@ -13,10 +13,10 @@ import "C"
// has a label. The user can click on the tabs themselves to switch
// pages. Individual pages can also have margins.
type Tab struct {
c *C.uiControl
t *C.uiTab
c *C.uiControl
t *C.uiTab
children []Control
children []Control
}
// 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
C.uiTabInsertAt(t.t, cname, C.uintmax_t(n), c)
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
copy(ch[:n], t.children[:n])
ch[n] = child
copy(ch[n + 1:], t.children[n:])
copy(ch[n+1:], t.children[n:])
t.children = ch
}
// Delete deletes the nth page of the Tab.
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))
}

View File

@ -20,7 +20,7 @@ import "C"
// of the desired length, we get our C.CMalloc(). Using a slice
// that's always initialized to zero gives us the ZeroMemory()
// for free.
var uimallocBytes = make([]byte, 1024) // 1024 bytes first
var uimallocBytes = make([]byte, 1024) // 1024 bytes first
//export uimalloc
func uimalloc(n C.size_t) unsafe.Pointer {

View File

@ -22,12 +22,12 @@ var windows = make(map[*C.uiWindow]*Window)
// entirety of the window. Though a Window is a Control,
// a Window cannot be the child of another Control.
type Window struct {
c *C.uiControl
w *C.uiWindow
c *C.uiControl
w *C.uiWindow
child Control
child Control
onClosing func(w *Window) bool
onClosing func(w *Window) bool
}
// NewWindow creates a new Window.

View File

@ -5,8 +5,8 @@ package ui
var page2group *Group
var (
movingLabel *Label
movingBoxes [2]*Box
movingLabel *Label
movingBoxes [2]*Box
movingCurrent int
)
@ -22,8 +22,9 @@ func moveLabel(*Button) {
}
var moveBack bool
const (
moveOutText = "Move Page 1 Out"
moveOutText = "Move Page 1 Out"
moveBackText = "Move Page 1 Back"
)
@ -92,7 +93,7 @@ func makePage2() *Box {
button = NewButton("Open Menuless Window")
button.OnClicked(func(*Button) {
w := NewWindow("Another Window", 100, 100, true)
//TODO w.SetChild(makePage6())
//TODO w.SetChild(makePage6())
w.SetMargined(true)
w.Show()
})
@ -154,8 +155,8 @@ func makePage2() *Box {
page2.Append(hbox, false)
disabledTab := newTab()
disabledTab.Append("Disabled", NewButton("Button"));
disabledTab.Append("Tab", NewLabel("Label"));
disabledTab.Append("Disabled", NewButton("Button"))
disabledTab.Append("Tab", NewLabel("Label"))
disabledTab.Disable()
page2.Append(disabledTab, true)

View File

@ -8,9 +8,9 @@ import (
)
var (
nomenus = flag.Bool("nomenus", false, "No menus")
nomenus = flag.Bool("nomenus", false, "No menus")
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
@ -64,9 +64,9 @@ func TestIt(t *testing.T) {
var (
spwindows []*Window
sptabs []*Tab
spgroups []*Group
spboxes []*Box
sptabs []*Tab
spgroups []*Group
spboxes []*Box
)
func newWindow(title string, width int, height int, hasMenubar bool) *Window {