Set Area's preferred size in the documentation and on Windows and Mac OS X.

This commit is contained in:
Pietro Gagliardi 2014-06-06 23:03:29 -04:00
parent 84c41112b3
commit f539747546
6 changed files with 29 additions and 1 deletions

View File

@ -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.

View File

@ -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);

View File

@ -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) {

View File

@ -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;
}

View File

@ -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

View File

@ -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] <myklgo> 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