More Windows sizing framework code: merged together the MulDiv() instances into wrapper functions and added the basic text length storage into controlbase.

This commit is contained in:
Pietro Gagliardi 2014-08-01 19:24:57 -04:00
parent 785d6ac4fd
commit 6e78eb94ba
3 changed files with 27 additions and 16 deletions

View File

@ -173,7 +173,7 @@ const (
func (l *label) labelcommitResize(c *allocation, d *sizing) {
if !l.standalone {
yoff := int(C.MulDiv(C.int(labelYOffset), C.int(d.baseY), 8))
yoff := fromdlgunitsY(labelYOffset, d)
c.y += yoff
c.height -= yoff
}

View File

@ -9,6 +9,7 @@ type controlbase struct {
*controldefs
hwnd C.HWND
parent C.HWND // for Tab and Group
textlen C.LONG
}
type controlParent struct {
@ -50,5 +51,7 @@ func (c *controlbase) text() string {
}
func (c *controlbase) setText(text string) {
C.setWindowText(c.hwnd, toUTF16(text))
t := toUTF16(text)
C.setWindowText(c.hwnd, t)
c.textlen = C.controlTextLength(c.hwnd, t)
}

View File

@ -9,13 +9,25 @@ type sizing struct {
sizingbase
// for size calculations
baseX int
baseY int
baseX C.int
baseY C.int
// for the actual resizing
// possibly the HDWP
}
// note on MulDiv():
// div will not be 0 in the usages below
// we also ignore overflow; that isn't likely to happen for our use case anytime soon
func fromdlgunitsX(du int, d *sizing) int {
return int(C.MulDiv(C.int(du), d.baseX, 4))
}
func fromdlgunitsY(du int, d *sizing) int {
return int(C.MulDiv(C.int(du), d.baseY, 8))
}
const (
marginDialogUnits = 7
paddingDialogUnits = 4
@ -24,14 +36,14 @@ const (
func (c *container) beginResize() (d *sizing) {
d = new(sizing)
d.baseX = int(C.baseX)
d.baseY = int(C.baseY)
d.baseX = C.baseX
d.baseY = C.baseY
if spaced {
d.xmargin = int(C.MulDiv(marginDialogUnits, C.int(d.baseX), 4))
d.ymargin = int(C.MulDiv(marginDialogUnits, C.int(d.baseY), 8))
d.xpadding = int(C.MulDiv(paddingDialogUnits, C.int(d.baseX), 4))
d.ypadding = int(C.MulDiv(paddingDialogUnits, C.int(d.baseY), 8))
d.xmargin = fromdlgunitsX(marginDialogUnits, d)
d.ymargin = fromdlgunitsY(marginDialogUnits, d)
d.xpadding = fromdlgunitsX(paddingDialogUnits, d)
d.ypadding = fromdlgunitsY(paddingDialogUnits, d)
}
return d
@ -140,12 +152,8 @@ var stdDlgSizes = [nctypes]dlgunits{
width = defaultWidth
}
height = stdDlgSizes[s.ctype].height
width = int(C.MulDiv(C.int(width), C.int(d.baseX), 4)) // equivalent to right of rect
height = int(C.MulDiv(C.int(height), C.int(d.baseY), 8)) // equivalent to bottom of rect
width = fromdlgunitsX(width, d) // equivalent to right of rect
height = fromdlguntisY(height, d) // equivalent to bottom of rect
*/
// return width, height
//}
// note on MulDiv():
// div will not be 0 in the usages above
// we also ignore overflow; that isn't likely to happen for our use case anytime soon