Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds compatibility for latest libui #169

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
10 changes: 5 additions & 5 deletions area.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,15 +28,15 @@ 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
// a call to SetSize). Only a portion of the Area is visible at any time;
// 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions box.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion combobox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 33 additions & 33 deletions draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,15 +38,15 @@ package ui
// static uiDrawStrokeParams *newStrokeParams(void)
// {
// uiDrawStrokeParams *b;
//
//
// b = (uiDrawStrokeParams *) malloc(sizeof (uiDrawStrokeParams));
// // TODO
// return b;
// }
// static double *newDashes(size_t n)
// {
// double *dashes;
//
//
// dashes = (double *) malloc(n * sizeof (double));
// // TODO
// return dashes;
Expand All @@ -64,7 +64,7 @@ package ui
// static uiDrawMatrix *newMatrix(void)
// {
// uiDrawMatrix *m;
//
//
// m = (uiDrawMatrix *) malloc(sizeof (uiDrawMatrix));
// // TODO
// return m;
Expand All @@ -76,15 +76,15 @@ package ui
// static uiDrawTextFontDescriptor *newFontDescriptor(void)
// {
// uiDrawTextFontDescriptor *desc;
//
//
// desc = (uiDrawTextFontDescriptor *) malloc(sizeof (uiDrawTextFontDescriptor));
// // TODO
// return desc;
// }
// static uiDrawTextFont *newFont(uiDrawTextFontDescriptor *desc)
// {
// uiDrawTextFont *font;
//
//
// font = uiDrawLoadClosestFont(desc);
// free((char *) (desc->Family));
// free(desc);
Expand All @@ -93,15 +93,15 @@ package ui
// static uiDrawTextLayout *newTextLayout(char *text, uiDrawTextFont *defaultFont, double width)
// {
// uiDrawTextLayout *layout;
//
//
// layout = uiDrawNewTextLayout(text, defaultFont, width);
// free(text);
// return layout;
// }
// static uiDrawTextFontMetrics *newFontMetrics(void)
// {
// uiDrawTextFontMetrics *m;
//
//
// m = (uiDrawTextFontMetrics *) malloc(sizeof (uiDrawTextFontMetrics));
// // TODO
// return m;
Expand All @@ -113,7 +113,7 @@ package ui
// static double *newDouble(void)
// {
// double *d;
//
//
// d = (double *) malloc(sizeof (double));
// // TODO
// return d;
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -163,7 +163,7 @@ type Path struct {
}

// TODO
//
//
// TODO disclaimer
type FillMode uint
const (
Expand Down Expand Up @@ -274,7 +274,7 @@ type DrawContext struct {
}

// BrushType defines the various types of brushes.
//
//
// TODO disclaimer
type BrushType int
const (
Expand All @@ -285,7 +285,7 @@ const (
)

// TODO
//
//
// TODO disclaimer
// TODO rename these to put LineCap at the beginning? or just Cap?
type LineCap int
Expand All @@ -296,7 +296,7 @@ const (
)

// TODO
//
//
// TODO disclaimer
type LineJoin int
const (
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -593,20 +593,20 @@ 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
}

// 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 (
Expand All @@ -624,7 +624,7 @@ const (
)

// TextItalic defines the various text italic modes.
//
//
// TODO disclaimer
type TextItalic int
const (
Expand All @@ -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 (
Expand Down Expand Up @@ -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.
Expand All @@ -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()
Expand All @@ -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))
Expand Down Expand Up @@ -764,15 +764,15 @@ 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.
// However, you may add attributes to various points of the text
// 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 {
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading