summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--newctrl/container_windows.go12
-rw-r--r--newctrl/window.go40
-rw-r--r--newctrl/window_windows.go16
3 files changed, 62 insertions, 6 deletions
diff --git a/newctrl/container_windows.go b/newctrl/container_windows.go
index 3db9d69..ebe9d50 100644
--- a/newctrl/container_windows.go
+++ b/newctrl/container_windows.go
@@ -85,7 +85,7 @@ func fromdlgunitsY(du int, d *sizing) int {
}
const (
- // TODO figure out how to sort this more nicely
+ // shared by multiple containers
marginDialogUnits = 7
paddingDialogUnits = 4
@@ -106,9 +106,6 @@ func (w *window) beginResize() (d *sizing) {
d.baseY = baseY
d.internalLeading = internalLeading
- d.xmargin = fromdlgunitsX(marginDialogUnits, d)
- d.ymargintop = fromdlgunitsY(marginDialogUnits, d)
- d.ymarginbottom = d.ymargintop
d.xpadding = fromdlgunitsX(paddingDialogUnits, d)
d.ypadding = fromdlgunitsY(paddingDialogUnits, d)
@@ -126,3 +123,10 @@ func (w *window) beginResize() (d *sizing) {
return d
}
+
+func marginRectDLU(r *C.RECT, top int, bottom int, left int, right int, d *sizing) {
+ r.left += fromdlgunitsX(left, d)
+ r.top += fromdlgunitsY(top, d)
+ r.right -= fromdlgunitsX(right, d)
+ r.bottom -= fromdlgunitsY(bottom, d)
+}
diff --git a/newctrl/window.go b/newctrl/window.go
new file mode 100644
index 0000000..92b7080
--- /dev/null
+++ b/newctrl/window.go
@@ -0,0 +1,40 @@
+// 7 july 2014
+
+package ui
+
+// Window represents a top-level window on screen that contains other Controls.
+// Windows in package ui can only contain one control; the Stack, Grid, and SimpleGrid layout Controls allow you to pack multiple Controls in a Window.
+// Note that a Window is not itself a Control.
+type Window interface {
+ // Title and SetTitle get and set the Window's title, respectively.
+ Title() string
+ SetTitle(title string)
+
+ // Show and Hide bring the Window on-screen and off-screen, respectively.
+ Show()
+ Hide()
+
+ // Close closes the Window.
+ // Any Controls within the Window are destroyed, and the Window itself is also destroyed.
+ // Attempting to use a Window after it has been closed results in undefined behavior.
+ // Close unconditionally closes the Window; it neither raises OnClosing nor checks for a return from OnClosing.
+ Close()
+
+ // OnClosing registers an event handler that is triggered when the user clicks the Window's close button.
+ // On systems where whole applications own windows, OnClosing is also triggered when the user asks to close the application.
+ // If this handler returns true, the Window is closed as defined by Close above.
+ // If this handler returns false, the Window is not closed.
+ OnClosing(func() bool)
+
+ // Margined and SetMargined get and set whether the contents of the Window have a margin around them.
+ // The size of the margin is platform-dependent.
+ Margined() bool
+ SetMargined(margined bool)
+
+ windowDialog
+}
+
+// NewWindow creates a new Window with the given title text, size, and control.
+func NewWindow(title string, width int, height int, control Control) Window {
+ return newWindow(title, width, height, control)
+}
diff --git a/newctrl/window_windows.go b/newctrl/window_windows.go
index 4dc5454..cfcb091 100644
--- a/newctrl/window_windows.go
+++ b/newctrl/window_windows.go
@@ -17,7 +17,8 @@ type window struct {
closing *event
- child Control
+ child Control
+ margined bool
}
func makeWindowWindowClass() error {
@@ -78,6 +79,14 @@ func (w *window) OnClosing(e func() bool) {
w.closing.setbool(e)
}
+func (w *window) Margined() bool {
+ return w.margined
+}
+
+func (w *window) SetMargined(margined bool) {
+ w.margined = margined
+}
+
//export storeWindowHWND
func storeWindowHWND(data unsafe.Pointer, hwnd C.HWND) {
w := (*window)(data)
@@ -87,7 +96,10 @@ func storeWindowHWND(data unsafe.Pointer, hwnd C.HWND) {
//export windowResize
func windowResize(data unsafe.Pointer, r *C.RECT) {
w := (*window)(data)
- TODO := &sizing{}
+ d := w.beginResize()
+ if w.margined {
+ marginRectDLU(r, marginDialogUnits, marginDialogUnits, marginDialogUnits, marginDialogUnits, d)
+ }
w.child.resize(int(r.left), int (r.top), int(r.right - r.left), int(r.bottom - r.top), TODO)
}