Began the big sizer cleanup: renamed sizer to container, renamed sizer.go to container.go, did the Mac OS X migration, moved containerctrls.go out of the way by merging its declarations into basicctrls.go, and did a quick cleanup fix to container_darwin.m.
This commit is contained in:
parent
74e2214f43
commit
88c01bf695
|
@ -63,6 +63,27 @@ func NewPasswordField() TextField {
|
|||
return newPasswordField()
|
||||
}
|
||||
|
||||
// Tab is a Control that contains multiple pages of tabs, each containing a single Control.
|
||||
// You can add and remove tabs from the Tab at any time.
|
||||
//
|
||||
// [TODO if each tab of your Tab is going to have the same content Controls, then use LikeTab instead, to conserve resources]
|
||||
type Tab interface {
|
||||
Control
|
||||
|
||||
// Append adds a new tab to Tab.
|
||||
// The tab is added to the end of the current list of tabs.
|
||||
Append(name string, control Control)
|
||||
|
||||
// Delete removes the given tab.
|
||||
// It panics if index is out of range.
|
||||
// Delete(index int)
|
||||
//TODO
|
||||
}
|
||||
|
||||
// NewTab creates a new Tab with no tabs.
|
||||
func NewTab() Tab {
|
||||
return newTab()
|
||||
}
|
||||
|
||||
// Label is a Control that shows a static line of text.
|
||||
// Label shows one line of text; any text that does not fit is truncated.
|
||||
|
|
|
@ -25,18 +25,18 @@ type controlSizing interface {
|
|||
getAuxResizeInfo(*sizing)
|
||||
}
|
||||
|
||||
// A sizer hosts a Control and resizes that Control based on changes in size to the parent Window.
|
||||
// sizer is used by Window, Tab, and [TODO implement] Group to contain and control their respective controls.
|
||||
// Window is the beginning of the resize chain; resizes happen on the system side.
|
||||
// Tab and Group are Controls and thus implement controlSizing; they should call their internal sizers's resize() method in their own commitResize().
|
||||
type sizer struct {
|
||||
// A container hosts a Control and resizes that Control based on changes in size to the parent Window.
|
||||
// container is used by Window, Tab, and [TODO implement] Group to contain and control their respective Controls.
|
||||
// Tab and Group use containers for their content; as such, their commitResize() functions should only change the size of the Tab and Group themselves, and have their containers do the real work.
|
||||
// All containers must embed containerbase.
|
||||
type containerbase struct {
|
||||
child Control
|
||||
}
|
||||
|
||||
// set to true to apply spacing to all windows
|
||||
var spaced bool = false
|
||||
|
||||
func (c *sizer) resize(x, y, width, height int) {
|
||||
func (c *container) resize(x, y, width, height int) {
|
||||
if c.child == nil { // no children; nothing to do
|
||||
return
|
||||
}
|
|
@ -10,15 +10,23 @@ import (
|
|||
import "C"
|
||||
|
||||
type container struct {
|
||||
containerbase
|
||||
// TODO rename to id
|
||||
view C.id
|
||||
*sizer
|
||||
view C.id
|
||||
}
|
||||
|
||||
type sizing struct {
|
||||
sizingbase
|
||||
|
||||
// for size calculations
|
||||
// nothing for mac
|
||||
|
||||
// for the actual resizing
|
||||
neighborAlign C.struct_xalignment
|
||||
}
|
||||
|
||||
func newContainer(child Control) *container {
|
||||
c := &container{
|
||||
sizer: new(sizer),
|
||||
}
|
||||
c := new(container)
|
||||
c.view = C.newContainerView(unsafe.Pointer(c))
|
||||
c.child = child
|
||||
c.child.setParent(&controlParent{c.view})
|
||||
|
@ -31,3 +39,31 @@ func containerResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t)
|
|||
// the origin of a view's content area is always (0, 0)
|
||||
c.resize(0, 0, int(width), int(height))
|
||||
}
|
||||
|
||||
// THIS IS A GUESS. TODO.
|
||||
// The only indication that this is remotely correct is the Auto Layout Guide implying that 12 pixels is the "Aqua space".
|
||||
const (
|
||||
macXMargin = 12
|
||||
macYMargin = 12
|
||||
macXPadding = 12
|
||||
macYPadding = 12
|
||||
)
|
||||
|
||||
func (c *container) beginResize() (d *sizing) {
|
||||
d = new(sizing)
|
||||
if spaced {
|
||||
d.xmargin = macXMargin
|
||||
d.ymargin = macYMargin
|
||||
d.xpadding = macXPadding
|
||||
d.ypadding = macYPadding
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
||||
for _, a := range allocations {
|
||||
// winheight - y because (0,0) is the bottom-left corner of the window and not the top-left corner
|
||||
// (winheight - y) - height because (x, y) is the bottom-left corner of the control and not the top-left
|
||||
a.y = (winheight - a.y) - a.height
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "_cgo_export.h"
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
#define toNSView(x) ((NSView *) (x))
|
||||
|
||||
// calling -[className] on the content views of NSWindow, NSTabItem, and NSBox all return NSView, so I'm assuming I just need to override these
|
||||
// fornunately:
|
||||
// - NSWindow resizing calls -[setFrameSize:] (but not -[setFrame:])
|
||||
|
@ -23,8 +25,7 @@
|
|||
- (void)setFrameSize:(NSSize)s
|
||||
{
|
||||
[super setFrameSize:s];
|
||||
if (self->gocontainer != NULL)
|
||||
containerResized(self->gocontainer, (intptr_t) s.width, (intptr_t) s.height);
|
||||
containerResized(self->gocontainer, (intptr_t) s.width, (intptr_t) s.height);
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -37,3 +38,8 @@ id newContainerView(void *gocontainer)
|
|||
c->gocontainer = gocontainer;
|
||||
return (id) c;
|
||||
}
|
||||
|
||||
void moveControl(id c, intptr_t x, intptr_t y, intptr_t width, intptr_t height)
|
||||
{
|
||||
[toNSView(c) setFrame:NSMakeRect((CGFloat) x, (CGFloat) y, (CGFloat) width, (CGFloat) height)];
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
// 25 july 2014
|
||||
|
||||
package ui
|
||||
|
||||
// Tab is a Control that contains multiple pages of tabs, each containing a single Control.
|
||||
// You can add and remove tabs from the Tab at any time.
|
||||
//
|
||||
// [TODO if each tab of your Tab is going to have the same content Controls, then use LikeTab instead, to conserve resources]
|
||||
type Tab interface {
|
||||
Control
|
||||
|
||||
// Append adds a new tab to Tab.
|
||||
// The tab is added to the end of the current list of tabs.
|
||||
Append(name string, control Control)
|
||||
|
||||
// Delete removes the given tab.
|
||||
// It panics if index is out of range.
|
||||
// Delete(index int)
|
||||
//TODO
|
||||
}
|
||||
|
||||
// NewTab creates a new Tab with no tabs.
|
||||
func NewTab() Tab {
|
||||
return newTab()
|
||||
}
|
|
@ -51,7 +51,8 @@ extern const char *textFieldText(id);
|
|||
extern void textFieldSetText(id, char *);
|
||||
extern id newLabel(void);
|
||||
|
||||
/* sizing_darwin.m */
|
||||
/* container_darwin.m */
|
||||
extern id newContainerView(void *);
|
||||
extern void moveControl(id, intptr_t, intptr_t, intptr_t, intptr_t);
|
||||
|
||||
/* tab_darwin.m */
|
||||
|
@ -88,7 +89,4 @@ extern struct xsize areaPrefSize(id);
|
|||
extern struct xalignment alignmentInfo(id, struct xrect);
|
||||
extern struct xrect frame(id);
|
||||
|
||||
/* container_darwin.m */
|
||||
extern id newContainerView(void *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
// 1 march 2014
|
||||
|
||||
package ui
|
||||
|
||||
// #include "objc_darwin.h"
|
||||
import "C"
|
||||
|
||||
type sizing struct {
|
||||
sizingbase
|
||||
|
||||
// for size calculations
|
||||
// nothing for mac
|
||||
|
||||
// for the actual resizing
|
||||
neighborAlign C.struct_xalignment
|
||||
}
|
||||
|
||||
// THIS IS A GUESS. TODO.
|
||||
// The only indication that this is remotely correct is the Auto Layout Guide implying that 12 pixels is the "Aqua space".
|
||||
const (
|
||||
macXMargin = 12
|
||||
macYMargin = 12
|
||||
macXPadding = 12
|
||||
macYPadding = 12
|
||||
)
|
||||
|
||||
func (s *sizer) beginResize() (d *sizing) {
|
||||
d = new(sizing)
|
||||
if spaced {
|
||||
d.xmargin = macXMargin
|
||||
d.ymargin = macYMargin
|
||||
d.xpadding = macXPadding
|
||||
d.ypadding = macYPadding
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (s *sizer) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
||||
for _, a := range allocations {
|
||||
// winheight - y because (0,0) is the bottom-left corner of the window and not the top-left corner
|
||||
// (winheight - y) - height because (x, y) is the bottom-left corner of the control and not the top-left
|
||||
a.y = (winheight - a.y) - a.height
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
// 17 july 2014
|
||||
|
||||
#import "objc_darwin.h"
|
||||
#import "_cgo_export.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#define toNSView(x) ((NSView *) (x))
|
||||
|
||||
void moveControl(id c, intptr_t x, intptr_t y, intptr_t width, intptr_t height)
|
||||
{
|
||||
[toNSView(c) setFrame:NSMakeRect((CGFloat) x, (CGFloat) y, (CGFloat) width, (CGFloat) height)];
|
||||
}
|
Loading…
Reference in New Issue