Started the work for margins; implemented for Window.

This commit is contained in:
Pietro Gagliardi 2014-10-14 22:03:56 -04:00
parent 8fd3e653d1
commit b6991d9b12
3 changed files with 62 additions and 6 deletions

View File

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

40
newctrl/window.go Normal file
View File

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

View File

@ -18,6 +18,7 @@ type window struct {
closing *event
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)
}