diff options
| author | Pietro Gagliardi <[email protected]> | 2014-03-23 20:54:11 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-03-23 20:54:11 -0400 |
| commit | a41f58286646057d1c022e260662944efd7b85ce (patch) | |
| tree | d675fabc592c366821ad143439fcc5aece4d7a48 /area.go | |
| parent | 0cc13633cb99b59a605296591c81732c11ba06f8 (diff) | |
Added Area resizing. Everything mostly works, but not making things smaller...
Diffstat (limited to 'area.go')
| -rw-r--r-- | area.go | 37 |
1 files changed, 28 insertions, 9 deletions
@@ -21,12 +21,14 @@ import ( // in platform-native ways is painful. // [Use TextArea instead, providing a TextAreaHandler.] // -// To facilitate development and debugging, for the time being, Areas have a fixed size of 320x240 and only work on GTK+. +// To facilitate development and debugging, for the time being, Areas only work on GTK+. type Area struct { - lock sync.Mutex - created bool - sysData *sysData - handler AreaHandler + lock sync.Mutex + created bool + sysData *sysData + handler AreaHandler + initwidth int + initheight int } // AreaHandler represents the events that an Area should respond to. @@ -210,18 +212,34 @@ const ( // TODO add Super ) -// NewArea creates a new Area. +// NewArea creates a new Area with the given size and handler. // It panics if handler is nil. -func NewArea(handler AreaHandler) *Area { +func NewArea(width int, height int, handler AreaHandler) *Area { if handler == nil { panic("handler passed to NewArea() must not be nil") } return &Area{ - sysData: mksysdata(c_area), - handler: handler, + sysData: mksysdata(c_area), + handler: handler, + initwidth: width, + initheight: height, } } +// SetSize sets the Area's internal drawing size. +// It has no effect on the actual control size. +func (a *Area) SetSize(width int, height int) { + a.lock.Lock() + defer a.lock.Unlock() + + if a.created { + a.sysData.setAreaSize(width, height) + return + } + a.initwidth = width + a.initheight = height +} + func (a *Area) make(window *sysData) error { a.lock.Lock() defer a.lock.Unlock() @@ -231,6 +249,7 @@ func (a *Area) make(window *sysData) error { if err != nil { return err } + a.sysData.setAreaSize(a.initwidth, a.initheight) a.created = true return nil } |
