More go fmt.
This commit is contained in:
parent
3c1a61049b
commit
09e3fcd9cb
38
stack.go
38
stack.go
|
@ -11,7 +11,7 @@ type orientation bool
|
||||||
|
|
||||||
const (
|
const (
|
||||||
horizontal orientation = false
|
horizontal orientation = false
|
||||||
vertical orientation = true
|
vertical orientation = true
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Stack stacks controls horizontally or vertically within the Stack's parent.
|
// A Stack stacks controls horizontally or vertically within the Stack's parent.
|
||||||
|
@ -20,21 +20,21 @@ const (
|
||||||
// Any extra space at the end of a Stack is left blank.
|
// Any extra space at the end of a Stack is left blank.
|
||||||
// Some controls may be marked as "stretchy": when the Window they are in changes size, stretchy controls resize to take up the remaining space after non-stretchy controls are laid out. If multiple controls are marked stretchy, they are alloted equal distribution of the remaining space.
|
// Some controls may be marked as "stretchy": when the Window they are in changes size, stretchy controls resize to take up the remaining space after non-stretchy controls are laid out. If multiple controls are marked stretchy, they are alloted equal distribution of the remaining space.
|
||||||
type Stack struct {
|
type Stack struct {
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
created bool
|
created bool
|
||||||
orientation orientation
|
orientation orientation
|
||||||
controls []Control
|
controls []Control
|
||||||
stretchy []bool
|
stretchy []bool
|
||||||
width, height []int // caches to avoid reallocating these each time
|
width, height []int // caches to avoid reallocating these each time
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStack(o orientation, controls ...Control) *Stack {
|
func newStack(o orientation, controls ...Control) *Stack {
|
||||||
return &Stack{
|
return &Stack{
|
||||||
orientation: o,
|
orientation: o,
|
||||||
controls: controls,
|
controls: controls,
|
||||||
stretchy: make([]bool, len(controls)),
|
stretchy: make([]bool, len(controls)),
|
||||||
width: make([]int, len(controls)),
|
width: make([]int, len(controls)),
|
||||||
height: make([]int, len(controls)),
|
height: make([]int, len(controls)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ func (s *Stack) make(window *sysData) error {
|
||||||
func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
|
func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
|
||||||
var stretchywid, stretchyht int
|
var stretchywid, stretchyht int
|
||||||
|
|
||||||
if len(s.controls) == 0 { // do nothing if there's nothing to do
|
if len(s.controls) == 0 { // do nothing if there's nothing to do
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 1) get height and width of non-stretchy controls; figure out how much space is alloted to stretchy controls
|
// 1) get height and width of non-stretchy controls; figure out how much space is alloted to stretchy controls
|
||||||
|
@ -93,11 +93,11 @@ func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w, h := c.preferredSize()
|
w, h := c.preferredSize()
|
||||||
if s.orientation == horizontal { // all controls have same height
|
if s.orientation == horizontal { // all controls have same height
|
||||||
s.width[i] = w
|
s.width[i] = w
|
||||||
s.height[i] = height
|
s.height[i] = height
|
||||||
stretchywid -= w
|
stretchywid -= w
|
||||||
} else { // all controls have same width
|
} else { // all controls have same width
|
||||||
s.width[i] = width
|
s.width[i] = width
|
||||||
s.height[i] = h
|
s.height[i] = h
|
||||||
stretchyht -= h
|
stretchyht -= h
|
||||||
|
@ -105,9 +105,9 @@ func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest
|
||||||
}
|
}
|
||||||
// 2) figure out size of stretchy controls
|
// 2) figure out size of stretchy controls
|
||||||
if nStretchy != 0 {
|
if nStretchy != 0 {
|
||||||
if s.orientation == horizontal { // split rest of width
|
if s.orientation == horizontal { // split rest of width
|
||||||
stretchywid /= nStretchy
|
stretchywid /= nStretchy
|
||||||
} else { // split rest of height
|
} else { // split rest of height
|
||||||
stretchyht /= nStretchy
|
stretchyht /= nStretchy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ func (s *Stack) preferredSize() (width int, height int) {
|
||||||
var nStretchy int
|
var nStretchy int
|
||||||
var maxswid, maxsht int
|
var maxswid, maxsht int
|
||||||
|
|
||||||
if len(s.controls) == 0 { // no controls, so return emptiness
|
if len(s.controls) == 0 { // no controls, so return emptiness
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
for i, c := range s.controls {
|
for i, c := range s.controls {
|
||||||
|
@ -152,7 +152,7 @@ func (s *Stack) preferredSize() (width int, height int) {
|
||||||
maxswid = max(maxswid, w)
|
maxswid = max(maxswid, w)
|
||||||
maxsht = max(maxsht, h)
|
maxsht = max(maxsht, h)
|
||||||
}
|
}
|
||||||
if s.orientation == horizontal { // max vertical size
|
if s.orientation == horizontal { // max vertical size
|
||||||
if !s.stretchy[i] {
|
if !s.stretchy[i] {
|
||||||
width += w
|
width += w
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,56 +4,55 @@ package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
// "syscall"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
controlFont _HANDLE // really the font for messagebox text, but everyone and everything says to use it
|
controlFont _HANDLE // really the font for messagebox text, but everyone and everything says to use it
|
||||||
titleFont _HANDLE
|
titleFont _HANDLE
|
||||||
smallTitleFont _HANDLE
|
smallTitleFont _HANDLE
|
||||||
menubarFont _HANDLE
|
menubarFont _HANDLE
|
||||||
statusbarFont _HANDLE
|
statusbarFont _HANDLE
|
||||||
)
|
)
|
||||||
|
|
||||||
type _LOGFONT struct {
|
type _LOGFONT struct {
|
||||||
lfHeight int32
|
lfHeight int32
|
||||||
lfWidth int32
|
lfWidth int32
|
||||||
lfEscapement int32
|
lfEscapement int32
|
||||||
lfOrientation int32
|
lfOrientation int32
|
||||||
lfWeight int32
|
lfWeight int32
|
||||||
lfItalic byte
|
lfItalic byte
|
||||||
lfUnderline byte
|
lfUnderline byte
|
||||||
lfStrikeOut byte
|
lfStrikeOut byte
|
||||||
lfCharSet byte
|
lfCharSet byte
|
||||||
lfOutPrecision byte
|
lfOutPrecision byte
|
||||||
lfClipPrecision byte
|
lfClipPrecision byte
|
||||||
lfQuality byte
|
lfQuality byte
|
||||||
lfPitchAndFamily byte
|
lfPitchAndFamily byte
|
||||||
lfFaceName [_LF_FACESIZE]uint16
|
lfFaceName [_LF_FACESIZE]uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
type _NONCLIENTMETRICS struct {
|
type _NONCLIENTMETRICS struct {
|
||||||
cbSize uint32
|
cbSize uint32
|
||||||
iBorderWidth int32 // originally int
|
iBorderWidth int32 // originally int
|
||||||
iScrollWidth int32 // originally int
|
iScrollWidth int32 // originally int
|
||||||
iScrollHeight int32 // originally int
|
iScrollHeight int32 // originally int
|
||||||
iCaptionWidth int32 // originally int
|
iCaptionWidth int32 // originally int
|
||||||
iCaptionHeight int32 // originally int
|
iCaptionHeight int32 // originally int
|
||||||
lfCaptionFont _LOGFONT
|
lfCaptionFont _LOGFONT
|
||||||
iSmCaptionWidth int32 // originally int
|
iSmCaptionWidth int32 // originally int
|
||||||
iSmCaptionHeight int32 // originally int
|
iSmCaptionHeight int32 // originally int
|
||||||
lfSmCaptionFont _LOGFONT
|
lfSmCaptionFont _LOGFONT
|
||||||
iMenuWidth int32 // originally int
|
iMenuWidth int32 // originally int
|
||||||
iMenuHeight int32 // originally int
|
iMenuHeight int32 // originally int
|
||||||
lfMenuFont _LOGFONT
|
lfMenuFont _LOGFONT
|
||||||
lfStatusFont _LOGFONT
|
lfStatusFont _LOGFONT
|
||||||
lfMessageFont _LOGFONT
|
lfMessageFont _LOGFONT
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_systemParametersInfo = user32.NewProc("SystemParametersInfoW")
|
_systemParametersInfo = user32.NewProc("SystemParametersInfoW")
|
||||||
_createFontIndirect = gdi32.NewProc("CreateFontIndirectW")
|
_createFontIndirect = gdi32.NewProc("CreateFontIndirectW")
|
||||||
)
|
)
|
||||||
|
|
||||||
func getStandardWindowFonts() (err error) {
|
func getStandardWindowFonts() (err error) {
|
||||||
|
@ -65,13 +64,13 @@ func getStandardWindowFonts() (err error) {
|
||||||
uintptr(unsafe.Sizeof(ncm)),
|
uintptr(unsafe.Sizeof(ncm)),
|
||||||
uintptr(unsafe.Pointer(&ncm)),
|
uintptr(unsafe.Pointer(&ncm)),
|
||||||
0)
|
0)
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
return fmt.Errorf("error getting system parameters: %v", err)
|
return fmt.Errorf("error getting system parameters: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
getfont := func(which *_LOGFONT, what string) (_HANDLE, error) {
|
getfont := func(which *_LOGFONT, what string) (_HANDLE, error) {
|
||||||
r1, _, err = _createFontIndirect.Call(uintptr(unsafe.Pointer(which)))
|
r1, _, err = _createFontIndirect.Call(uintptr(unsafe.Pointer(which)))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
return _NULL, fmt.Errorf("error getting %s font; Windows last error: %v", what, err)
|
return _NULL, fmt.Errorf("error getting %s font; Windows last error: %v", what, err)
|
||||||
}
|
}
|
||||||
return _HANDLE(r1), nil
|
return _HANDLE(r1), nil
|
||||||
|
@ -97,5 +96,5 @@ func getStandardWindowFonts() (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil // all good
|
return nil // all good
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ func storeSysData(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRES
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_getFocus = user32.NewProc("GetFocus")
|
_getFocus = user32.NewProc("GetFocus")
|
||||||
_isChild = user32.NewProc("IsChild")
|
_isChild = user32.NewProc("IsChild")
|
||||||
// _setFocus in area_windows.go
|
// _setFocus in area_windows.go
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -78,15 +78,15 @@ var (
|
||||||
// from http://blogs.msdn.com/b/oldnewthing/archive/2014/05/21/10527168.aspx
|
// from http://blogs.msdn.com/b/oldnewthing/archive/2014/05/21/10527168.aspx
|
||||||
func (s *sysData) handleFocus(wParam _WPARAM) {
|
func (s *sysData) handleFocus(wParam _WPARAM) {
|
||||||
// parameter splitting from Microsoft's windowsx.h
|
// parameter splitting from Microsoft's windowsx.h
|
||||||
state := uint32(wParam.LOWORD()) // originally UINT
|
state := uint32(wParam.LOWORD()) // originally UINT
|
||||||
minimized := wParam.HIWORD() != 0
|
minimized := wParam.HIWORD() != 0
|
||||||
|
|
||||||
if minimized { // don't do anything on minimize
|
if minimized { // don't do anything on minimize
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if state == _WA_INACTIVE { // focusing out
|
if state == _WA_INACTIVE { // focusing out
|
||||||
old, _, _ := _getFocus.Call()
|
old, _, _ := _getFocus.Call()
|
||||||
if _HWND(old) != _HWND(_NULL) { // if there is one
|
if _HWND(old) != _HWND(_NULL) { // if there is one
|
||||||
r1, _, _ := _isChild.Call(
|
r1, _, _ := _isChild.Call(
|
||||||
uintptr(s.hwnd),
|
uintptr(s.hwnd),
|
||||||
old)
|
old)
|
||||||
|
@ -94,8 +94,8 @@ func (s *sysData) handleFocus(wParam _WPARAM) {
|
||||||
s.lastfocus = _HWND(old)
|
s.lastfocus = _HWND(old)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // focusing in
|
} else { // focusing in
|
||||||
if s.lastfocus != _HWND(_NULL) { // if we have one
|
if s.lastfocus != _HWND(_NULL) { // if we have one
|
||||||
// don't bother checking SetFocus()'s error; see http://stackoverflow.com/questions/24073695/winapi-can-setfocus-return-null-without-an-error-because-thats-what-im-see/24074912#24074912
|
// don't bother checking SetFocus()'s error; see http://stackoverflow.com/questions/24073695/winapi-can-setfocus-return-null-without-an-error-because-thats-what-im-see/24074912#24074912
|
||||||
_setFocus.Call(uintptr(s.lastfocus))
|
_setFocus.Call(uintptr(s.lastfocus))
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ func (s *sysData) handleFocus(wParam _WPARAM) {
|
||||||
|
|
||||||
func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
|
func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
|
||||||
s := getSysData(hwnd)
|
s := getSysData(hwnd)
|
||||||
if s == nil { // not yet saved
|
if s == nil { // not yet saved
|
||||||
return storeSysData(hwnd, uMsg, wParam, lParam)
|
return storeSysData(hwnd, uMsg, wParam, lParam)
|
||||||
}
|
}
|
||||||
switch uMsg {
|
switch uMsg {
|
||||||
|
@ -134,7 +134,7 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL
|
||||||
_sendMessage.Call(
|
_sendMessage.Call(
|
||||||
uintptr(ss.hwnd),
|
uintptr(ss.hwnd),
|
||||||
uintptr(_BM_SETCHECK),
|
uintptr(_BM_SETCHECK),
|
||||||
state, // already uintptr
|
state, // already uintptr
|
||||||
uintptr(0))
|
uintptr(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL
|
||||||
panic("GetClientRect failed: " + err.Error())
|
panic("GetClientRect failed: " + err.Error())
|
||||||
}
|
}
|
||||||
// top-left corner is (0,0) so no need for winheight
|
// top-left corner is (0,0) so no need for winheight
|
||||||
s.doResize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top), 0)
|
s.doResize(int(r.left), int(r.top), int(r.right-r.left), int(r.bottom-r.top), 0)
|
||||||
// TODO use the Defer movement functions here?
|
// TODO use the Defer movement functions here?
|
||||||
// TODO redraw window and all children here?
|
// TODO redraw window and all children here?
|
||||||
}
|
}
|
||||||
|
@ -173,16 +173,16 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL
|
||||||
}
|
}
|
||||||
|
|
||||||
type _WNDCLASS struct {
|
type _WNDCLASS struct {
|
||||||
style uint32
|
style uint32
|
||||||
lpfnWndProc uintptr
|
lpfnWndProc uintptr
|
||||||
cbClsExtra int32 // originally int
|
cbClsExtra int32 // originally int
|
||||||
cbWndExtra int32 // originally int
|
cbWndExtra int32 // originally int
|
||||||
hInstance _HANDLE
|
hInstance _HANDLE
|
||||||
hIcon _HANDLE
|
hIcon _HANDLE
|
||||||
hCursor _HANDLE
|
hCursor _HANDLE
|
||||||
hbrBackground _HBRUSH
|
hbrBackground _HBRUSH
|
||||||
lpszMenuName *uint16
|
lpszMenuName *uint16
|
||||||
lpszClassName uintptr
|
lpszClassName uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -195,15 +195,15 @@ var (
|
||||||
|
|
||||||
func registerStdWndClass() (err error) {
|
func registerStdWndClass() (err error) {
|
||||||
wc := &_WNDCLASS{
|
wc := &_WNDCLASS{
|
||||||
lpszClassName: utf16ToArg(stdWndClass),
|
lpszClassName: utf16ToArg(stdWndClass),
|
||||||
lpfnWndProc: syscall.NewCallback(stdWndProc),
|
lpfnWndProc: syscall.NewCallback(stdWndProc),
|
||||||
hInstance: hInstance,
|
hInstance: hInstance,
|
||||||
hIcon: icon,
|
hIcon: icon,
|
||||||
hCursor: cursor,
|
hCursor: cursor,
|
||||||
hbrBackground: _HBRUSH(_COLOR_BTNFACE + 1),
|
hbrBackground: _HBRUSH(_COLOR_BTNFACE + 1),
|
||||||
}
|
}
|
||||||
r1, _, err := _registerClass.Call(uintptr(unsafe.Pointer(wc)))
|
r1, _, err := _registerClass.Call(uintptr(unsafe.Pointer(wc)))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -214,7 +214,7 @@ func initWndClassInfo() (err error) {
|
||||||
r1, _, err := user32.NewProc("LoadIconW").Call(
|
r1, _, err := user32.NewProc("LoadIconW").Call(
|
||||||
uintptr(_NULL),
|
uintptr(_NULL),
|
||||||
uintptr(_IDI_APPLICATION))
|
uintptr(_IDI_APPLICATION))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
return fmt.Errorf("error getting window icon: %v", err)
|
return fmt.Errorf("error getting window icon: %v", err)
|
||||||
}
|
}
|
||||||
icon = _HANDLE(r1)
|
icon = _HANDLE(r1)
|
||||||
|
@ -222,7 +222,7 @@ func initWndClassInfo() (err error) {
|
||||||
r1, _, err = user32.NewProc("LoadCursorW").Call(
|
r1, _, err = user32.NewProc("LoadCursorW").Call(
|
||||||
uintptr(_NULL),
|
uintptr(_NULL),
|
||||||
uintptr(_IDC_ARROW))
|
uintptr(_IDC_ARROW))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
return fmt.Errorf("error getting window cursor: %v", err)
|
return fmt.Errorf("error getting window cursor: %v", err)
|
||||||
}
|
}
|
||||||
cursor = _HANDLE(r1)
|
cursor = _HANDLE(r1)
|
||||||
|
|
Loading…
Reference in New Issue