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:
parent
785d6ac4fd
commit
6e78eb94ba
|
@ -173,7 +173,7 @@ const (
|
||||||
|
|
||||||
func (l *label) labelcommitResize(c *allocation, d *sizing) {
|
func (l *label) labelcommitResize(c *allocation, d *sizing) {
|
||||||
if !l.standalone {
|
if !l.standalone {
|
||||||
yoff := int(C.MulDiv(C.int(labelYOffset), C.int(d.baseY), 8))
|
yoff := fromdlgunitsY(labelYOffset, d)
|
||||||
c.y += yoff
|
c.y += yoff
|
||||||
c.height -= yoff
|
c.height -= yoff
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ type controlbase struct {
|
||||||
*controldefs
|
*controldefs
|
||||||
hwnd C.HWND
|
hwnd C.HWND
|
||||||
parent C.HWND // for Tab and Group
|
parent C.HWND // for Tab and Group
|
||||||
|
textlen C.LONG
|
||||||
}
|
}
|
||||||
|
|
||||||
type controlParent struct {
|
type controlParent struct {
|
||||||
|
@ -50,5 +51,7 @@ func (c *controlbase) text() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controlbase) setText(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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,25 @@ type sizing struct {
|
||||||
sizingbase
|
sizingbase
|
||||||
|
|
||||||
// for size calculations
|
// for size calculations
|
||||||
baseX int
|
baseX C.int
|
||||||
baseY int
|
baseY C.int
|
||||||
|
|
||||||
// for the actual resizing
|
// for the actual resizing
|
||||||
// possibly the HDWP
|
// 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 (
|
const (
|
||||||
marginDialogUnits = 7
|
marginDialogUnits = 7
|
||||||
paddingDialogUnits = 4
|
paddingDialogUnits = 4
|
||||||
|
@ -24,14 +36,14 @@ const (
|
||||||
func (c *container) beginResize() (d *sizing) {
|
func (c *container) beginResize() (d *sizing) {
|
||||||
d = new(sizing)
|
d = new(sizing)
|
||||||
|
|
||||||
d.baseX = int(C.baseX)
|
d.baseX = C.baseX
|
||||||
d.baseY = int(C.baseY)
|
d.baseY = C.baseY
|
||||||
|
|
||||||
if spaced {
|
if spaced {
|
||||||
d.xmargin = int(C.MulDiv(marginDialogUnits, C.int(d.baseX), 4))
|
d.xmargin = fromdlgunitsX(marginDialogUnits, d)
|
||||||
d.ymargin = int(C.MulDiv(marginDialogUnits, C.int(d.baseY), 8))
|
d.ymargin = fromdlgunitsY(marginDialogUnits, d)
|
||||||
d.xpadding = int(C.MulDiv(paddingDialogUnits, C.int(d.baseX), 4))
|
d.xpadding = fromdlgunitsX(paddingDialogUnits, d)
|
||||||
d.ypadding = int(C.MulDiv(paddingDialogUnits, C.int(d.baseY), 8))
|
d.ypadding = fromdlgunitsY(paddingDialogUnits, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
@ -140,12 +152,8 @@ var stdDlgSizes = [nctypes]dlgunits{
|
||||||
width = defaultWidth
|
width = defaultWidth
|
||||||
}
|
}
|
||||||
height = stdDlgSizes[s.ctype].height
|
height = stdDlgSizes[s.ctype].height
|
||||||
width = int(C.MulDiv(C.int(width), C.int(d.baseX), 4)) // equivalent to right of rect
|
width = fromdlgunitsX(width, d) // equivalent to right of rect
|
||||||
height = int(C.MulDiv(C.int(height), C.int(d.baseY), 8)) // equivalent to bottom of rect
|
height = fromdlguntisY(height, d) // equivalent to bottom of rect
|
||||||
*/
|
*/
|
||||||
// return width, height
|
// 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
|
|
||||||
|
|
Loading…
Reference in New Issue