diff --git a/area.go b/area.go index ae890a3..686f4b8 100644 --- a/area.go +++ b/area.go @@ -14,6 +14,7 @@ import ( // An Area has an explicit size, represented in pixels, that may be different from the size shown in its Window; Areas have both horizontal and vertical scrollbars that are hidden when not needed. // The coordinate system of an Area always has an origin of (0,0) which maps to the top-left corner; all image.Points and image.Rectangles sent across Area's channels conform to this. // The size of an Area must be at least 1x1 (that is, neither its width nor its height may be zero or negative). +// For control layout purposes, an Area prefers to be at the size you set it to (so if an Area is not stretchy in its layout, it will ask to have that size). // // To handle events to the Area, an Area must be paired with an AreaHandler. // See AreaHandler for details. diff --git a/objc_darwin.h b/objc_darwin.h index fd2058a..d4707bc 100644 --- a/objc_darwin.h +++ b/objc_darwin.h @@ -87,6 +87,7 @@ extern intptr_t listboxLen(id); extern struct xsize controlPrefSize(id); extern struct xsize listboxPrefSize(id); extern struct xsize pbarPrefSize(id); +extern struct xsize areaPrefSize(id); /* sysdata_darwin.m */ extern void addControl(id, id); diff --git a/prefsize_darwin.go b/prefsize_darwin.go index 46d72a7..ae53b8b 100644 --- a/prefsize_darwin.go +++ b/prefsize_darwin.go @@ -27,6 +27,12 @@ func pbarPrefSize(control C.id) (width int, height int) { return int(r.width), int(r.height) } +// Areas know their own preferred size +func areaPrefSize(control C.id) (width int, height int) { + r := C.areaPrefSize(control) + return int(r.width), int(r.height) +} + var prefsizefuncs = [nctypes]func(C.id) (int, int){ c_button: controlPrefSize, c_checkbox: controlPrefSize, @@ -35,6 +41,7 @@ var prefsizefuncs = [nctypes]func(C.id) (int, int){ c_label: controlPrefSize, c_listbox: listboxPrefSize, c_progressbar: pbarPrefSize, + c_area: areaPrefSize, } func (s *sysData) preferredSize() (width int, height int) { diff --git a/prefsize_darwin.m b/prefsize_darwin.m index 521b767..2f3dd7a 100644 --- a/prefsize_darwin.m +++ b/prefsize_darwin.m @@ -72,4 +72,18 @@ struct xsize pbarPrefSize(id control) s.width = (intptr_t) r.size.width; s.height = (intptr_t) r.size.height; return s; +} + +struct xsize areaPrefSize(id scrollview) +{ + NSView *c; + NSRect r; + struct xsize s; + + c = areaInScrollView(toNSScrollView(scrollview)); + // don't size to fit; the frame size is already the size we want + r = [c frame]; + s.width = (intptr_t) r.size.width; + s.height = (intptr_t) r.size.height; + return s; } \ No newline at end of file diff --git a/prefsize_windows.go b/prefsize_windows.go index 9e7a81e..17b4088 100644 --- a/prefsize_windows.go +++ b/prefsize_windows.go @@ -79,6 +79,11 @@ var ( // This function runs on uitask; call the functions directly. func (s *sysData) preferredSize() (width int, height int) { + // the preferred size of an Area is its size + if s.ctype == c_area { + return s.areawidth, s.areaheight + } + if msg := stdDlgSizes[s.ctype].getsize; msg != 0 { var size _SIZE diff --git a/todo.md b/todo.md index 6d25811..3e18105 100644 --- a/todo.md +++ b/todo.md @@ -28,11 +28,11 @@ UNIX: - resizing seems to be completely and totally broken in the Wayland backend - TODO find out if this is a problem on the GTK+/Wayland side (no initial window-configure event?) - [12:55] pietro10: I meant to mention: 1073): Gtk-WARNING **: Theme parsing error: gtk.css:72:20: Not using units is deprecated. Assuming 'px'. twice. +- make sure the preferred size of Area is its size ALL PLATFORMS: - make sure MouseEvent's documentation has dragging described correctly (both Windows and GTK+ do) - make sure the preferred size of a Listbox is the minimum size needed to display everything on all platforms (capped at the screen height, of course?) - - same for Area, using the Area's size (this will be easier) - make sure the image drawn on an Area looks correct on all platforms (is not cropped incorrectly or blurred) - make sure keyboard events on numpad off on all platforms don't switch between controls - TODO remember what this means