From 37dba6a1ef0acf65466cd6a5ea067f4d9404614a Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 14 Jun 2016 08:11:07 +0200 Subject: [PATCH] Adds compatibility for latest libui, adds New{Password,Search}Entry --- area.go | 10 ++++---- box.go | 3 +-- combobox.go | 2 +- draw.go | 66 ++++++++++++++++++++++++++--------------------------- entry.go | 26 +++++++++++++++++++++ slider.go | 4 ++-- spinbox.go | 4 ++-- tab.go | 10 ++++---- 8 files changed, 75 insertions(+), 50 deletions(-) diff --git a/area.go b/area.go index 358a391..1689ce8 100644 --- a/area.go +++ b/area.go @@ -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 @@ -74,7 +74,7 @@ func NewScrollingArea(handler AreaHandler, width int, height int) *Area { a.scrolling = true a.ah = registerAreaHandler(handler) - a.a = C.uiNewScrollingArea(a.ah, C.intmax_t(width), C.intmax_t(height)) + a.a = C.uiNewScrollingArea(a.ah, C.int(width), C.int(height)) a.c = (*C.uiControl)(unsafe.Pointer(a.a)) areas[a.a] = a @@ -133,7 +133,7 @@ func (a *Area) SetSize(width int, height int) { if !a.scrolling { panic("attempt to call SetSize on non-scrolling Area") } - C.uiAreaSetSize(a.a, C.intmax_t(width), C.intmax_t(height)) + C.uiAreaSetSize(a.a, C.int(width), C.int(height)) } // QueueRedrawAll queues the entire Area for redraw. diff --git a/box.go b/box.go index caf49e3..cc72cf6 100644 --- a/box.go +++ b/box.go @@ -103,8 +103,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:]...) - // TODO why is this uintmax_t instead of intmax_t - C.uiBoxDelete(b.b, C.uintmax_t(n)) + C.uiBoxDelete(b.b, C.int(n)) } // Padded returns whether there is space between each control diff --git a/combobox.go b/combobox.go index 2afa294..9aa0a04 100644 --- a/combobox.go +++ b/combobox.go @@ -114,7 +114,7 @@ func (c *Combobox) Selected() int { // SetChecked sets the currently select item in the Combobox // to index. If index is -1 no item will be selected. func (c *Combobox) SetSelected(index int) { - C.uiComboboxSetSelected(c.c, C.intmax_t(index)) + C.uiComboboxSetSelected(c.c, C.int(index)) } // OnSelected registers f to be run when the user selects an item in diff --git a/draw.go b/draw.go index eb4158d..236410c 100644 --- a/draw.go +++ b/draw.go @@ -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,7 +154,7 @@ 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 @@ -163,7 +163,7 @@ type Path struct { } // TODO -// +// // TODO disclaimer type FillMode uint const ( @@ -274,7 +274,7 @@ type DrawContext struct { } // BrushType defines the various types of brushes. -// +// // TODO disclaimer type BrushType int const ( @@ -285,7 +285,7 @@ const ( ) // TODO -// +// // TODO disclaimer // TODO rename these to put LineCap at the beginning? or just Cap? type LineCap int @@ -296,7 +296,7 @@ const ( ) // TODO -// +// // TODO disclaimer type LineJoin int const ( @@ -514,7 +514,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 +564,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 @@ -593,7 +593,7 @@ func (f *FontFamilies) NumFamilies() int { // Family returns the name of the nth family in the list. func (f *FontFamilies) Family(n int) string { - cname := C.uiDrawFontFamiliesFamily(f.ff, C.uintmax_t(n)) + cname := C.uiDrawFontFamiliesFamily(f.ff, C.int(n)) name := C.GoString(cname) C.uiFreeText(cname) return name @@ -601,12 +601,12 @@ 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 ( @@ -624,7 +624,7 @@ const ( ) // TextItalic defines the various text italic modes. -// +// // TODO disclaimer type TextItalic int const ( @@ -635,13 +635,13 @@ const ( // 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 ( @@ -671,7 +671,7 @@ type Font struct { } // 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,7 +682,7 @@ 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() @@ -705,11 +705,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)) @@ -764,7 +764,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,7 +772,7 @@ 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 { @@ -806,7 +806,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 diff --git a/entry.go b/entry.go index ee14fc8..42a2993 100644 --- a/entry.go +++ b/entry.go @@ -43,6 +43,32 @@ func NewEntry() *Entry { return e } +// NewPasswordEntry creates a new Entry suitable for entering passwords. +func NewPasswordEntry() *Entry { + e := new(Entry) + + e.e = C.uiNewPasswordEntry() + e.c = (*C.uiControl)(unsafe.Pointer(e.e)) + + C.realuiEntryOnChanged(e.e) + entries[e.e] = e + + return e +} + +// NewSearchEntry creates a new Entry suitable for searching. +func NewSearchEntry() *Entry { + e := new(Entry) + + e.e = C.uiNewSearchEntry() + e.c = (*C.uiControl)(unsafe.Pointer(e.e)) + + C.realuiEntryOnChanged(e.e) + entries[e.e] = e + + return e +} + // Destroy destroys the Entry. func (e *Entry) Destroy() { delete(entries, e.e) diff --git a/slider.go b/slider.go index 99b8d2c..eb1031b 100644 --- a/slider.go +++ b/slider.go @@ -31,7 +31,7 @@ type Slider struct { func NewSlider(min int, max int) *Slider { s := new(Slider) - s.s = C.uiNewSlider(C.intmax_t(min), C.intmax_t(max)) + s.s = C.uiNewSlider(C.int(min), C.int(max)) s.c = (*C.uiControl)(unsafe.Pointer(s.s)) C.realuiSliderOnChanged(s.s) @@ -90,7 +90,7 @@ func (s *Slider) Value() int { // SetText sets the Slider's current value to value. func (s *Slider) SetValue(value int) { - C.uiSliderSetValue(s.s, C.intmax_t(value)) + C.uiSliderSetValue(s.s, C.int(value)) } // OnChanged registers f to be run when the user changes the value diff --git a/spinbox.go b/spinbox.go index 5e5e43f..26ca133 100644 --- a/spinbox.go +++ b/spinbox.go @@ -31,7 +31,7 @@ type Spinbox struct { func NewSpinbox(min int, max int) *Spinbox { s := new(Spinbox) - s.s = C.uiNewSpinbox(C.intmax_t(min), C.intmax_t(max)) + s.s = C.uiNewSpinbox(C.int(min), C.int(max)) s.c = (*C.uiControl)(unsafe.Pointer(s.s)) C.realuiSpinboxOnChanged(s.s) @@ -93,7 +93,7 @@ func (s *Spinbox) Value() int { // SetText sets the Spinbox's current value to value. func (s *Spinbox) SetValue(value int) { - C.uiSpinboxSetValue(s.s, C.intmax_t(value)) + C.uiSpinboxSetValue(s.s, C.int(value)) } // OnChanged registers f to be run when the user changes the value diff --git a/tab.go b/tab.go index d18cecd..676c9b4 100644 --- a/tab.go +++ b/tab.go @@ -91,8 +91,8 @@ func (t *Tab) InsertAt(name string, n int, child Control) { c = touiControl(child.LibuiControl()) } cname := C.CString(name) - // 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.int(n), c) freestr(cname) ch := make([]Control, len(t.children) + 1) // and insert into t.children at the right place @@ -105,7 +105,7 @@ func (t *Tab) InsertAt(name string, n int, child Control) { // Delete deletes the nth page of the Tab. func (t *Tab) Delete(n int) { t.children = append(t.children[:n], t.children[n + 1:]...) - C.uiTabDelete(t.t, C.uintmax_t(n)) + C.uiTabDelete(t.t, C.int(n)) } // NumPages returns the number of pages in the Tab. @@ -116,12 +116,12 @@ func (t *Tab) NumPages() int { // Margined returns whether page n (starting at 0) of the Tab // has margins around its child. func (t *Tab) Margined(n int) bool { - return tobool(C.uiTabMargined(t.t, C.uintmax_t(n))) + return tobool(C.uiTabMargined(t.t, C.int(n))) } // SetMargined controls whether page n (starting at 0) of the Tab // has margins around its child. The size of the margins are // determined by the OS and its best practices. func (t *Tab) SetMargined(n int, margined bool) { - C.uiTabSetMargined(t.t, C.uintmax_t(n), frombool(margined)) + C.uiTabSetMargined(t.t, C.int(n), frombool(margined)) }