summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/basicctrls.go21
-rw-r--r--redo/container.go (renamed from redo/sizer.go)12
-rw-r--r--redo/container_darwin.go46
-rw-r--r--redo/container_darwin.m10
-rw-r--r--redo/containerctrls.go25
-rw-r--r--redo/objc_darwin.h6
-rw-r--r--redo/sizer_darwin.go44
-rw-r--r--redo/sizing_darwin.m12
8 files changed, 78 insertions, 98 deletions
diff --git a/redo/basicctrls.go b/redo/basicctrls.go
index a119fb8..f4f1297 100644
--- a/redo/basicctrls.go
+++ b/redo/basicctrls.go
@@ -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.
diff --git a/redo/sizer.go b/redo/container.go
index 4862ac0..a7eb7f4 100644
--- a/redo/sizer.go
+++ b/redo/container.go
@@ -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
}
diff --git a/redo/container_darwin.go b/redo/container_darwin.go
index 1f8a477..96aca31 100644
--- a/redo/container_darwin.go
+++ b/redo/container_darwin.go
@@ -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
+ }
+}
diff --git a/redo/container_darwin.m b/redo/container_darwin.m
index 46d4edb..7129b61 100644
--- a/redo/container_darwin.m
+++ b/redo/container_darwin.m
@@ -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)];
+}
diff --git a/redo/containerctrls.go b/redo/containerctrls.go
deleted file mode 100644
index 9b0c0b1..0000000
--- a/redo/containerctrls.go
+++ /dev/null
@@ -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()
-}
diff --git a/redo/objc_darwin.h b/redo/objc_darwin.h
index 703f757..f0dac12 100644
--- a/redo/objc_darwin.h
+++ b/redo/objc_darwin.h
@@ -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
diff --git a/redo/sizer_darwin.go b/redo/sizer_darwin.go
deleted file mode 100644
index 500d35f..0000000
--- a/redo/sizer_darwin.go
+++ /dev/null
@@ -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
- }
-}
diff --git a/redo/sizing_darwin.m b/redo/sizing_darwin.m
deleted file mode 100644
index b379465..0000000
--- a/redo/sizing_darwin.m
+++ /dev/null
@@ -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)];
-}