Mostly fixed Labels on Windows being offset slightly; need to finish the fix by making it not apply to standalone Labels and adding comments.
This commit is contained in:
parent
21dbda72e2
commit
f24e177d99
|
@ -20,8 +20,9 @@ type sizing struct {
|
||||||
sizingbase
|
sizingbase
|
||||||
|
|
||||||
// for size calculations
|
// for size calculations
|
||||||
baseX C.int
|
baseX C.int
|
||||||
baseY C.int
|
baseY C.int
|
||||||
|
internalLeading C.LONG
|
||||||
|
|
||||||
// for the actual resizing
|
// for the actual resizing
|
||||||
// possibly the HDWP
|
// possibly the HDWP
|
||||||
|
@ -105,12 +106,14 @@ const (
|
||||||
|
|
||||||
func (c *container) beginResize() (d *sizing) {
|
func (c *container) beginResize() (d *sizing) {
|
||||||
var baseX, baseY C.int
|
var baseX, baseY C.int
|
||||||
|
var internalLeading C.LONG
|
||||||
|
|
||||||
d = new(sizing)
|
d = new(sizing)
|
||||||
|
|
||||||
C.calculateBaseUnits(c.hwnd, &baseX, &baseY)
|
C.calculateBaseUnits(c.hwnd, &baseX, &baseY, &internalLeading)
|
||||||
d.baseX = baseX
|
d.baseX = baseX
|
||||||
d.baseY = baseY
|
d.baseY = baseY
|
||||||
|
d.internalLeading = internalLeading
|
||||||
|
|
||||||
if spaced {
|
if spaced {
|
||||||
d.xmargin = fromdlgunitsX(marginDialogUnits, d)
|
d.xmargin = fromdlgunitsX(marginDialogUnits, d)
|
||||||
|
|
|
@ -81,6 +81,8 @@ func (l *label) commitResize(c *allocation, d *sizing) {
|
||||||
c.y += yoff
|
c.y += yoff
|
||||||
c.height -= yoff
|
c.height -= yoff
|
||||||
}
|
}
|
||||||
|
c.y -= int(d.internalLeading)
|
||||||
|
c.height += int(d.internalLeading)
|
||||||
basecommitResize(l, c, d)
|
basecommitResize(l, c, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
/* TODO figure out where these should go */
|
/* TODO figure out where these should go */
|
||||||
|
|
||||||
void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY)
|
void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY, LONG *internalLeading)
|
||||||
{
|
{
|
||||||
HDC dc;
|
HDC dc;
|
||||||
HFONT prevFont;
|
HFONT prevFont;
|
||||||
|
@ -21,6 +21,7 @@ void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY)
|
||||||
xpanic("error getting text metrics for preferred size calculations", GetLastError());
|
xpanic("error getting text metrics for preferred size calculations", GetLastError());
|
||||||
*baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */
|
*baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */
|
||||||
*baseY = (int) tm.tmHeight;
|
*baseY = (int) tm.tmHeight;
|
||||||
|
*internalLeading = tm.tmInternalLeading;
|
||||||
if (SelectObject(dc, prevFont) != controlFont)
|
if (SelectObject(dc, prevFont) != controlFont)
|
||||||
xpanic("error restoring previous font into device context after preferred size calculations", GetLastError());
|
xpanic("error restoring previous font into device context after preferred size calculations", GetLastError());
|
||||||
if (ReleaseDC(hwnd, dc) == 0)
|
if (ReleaseDC(hwnd, dc) == 0)
|
||||||
|
|
|
@ -69,7 +69,7 @@ extern HBRUSH hollowBrush;
|
||||||
extern DWORD initWindows(char **);
|
extern DWORD initWindows(char **);
|
||||||
|
|
||||||
/* sizing_windows.c */
|
/* sizing_windows.c */
|
||||||
extern void calculateBaseUnits(HWND, int *, int *);
|
extern void calculateBaseUnits(HWND, int *, int *, LONG *);
|
||||||
extern void moveWindow(HWND, int, int, int, int);
|
extern void moveWindow(HWND, int, int, int, int);
|
||||||
extern LONG controlTextLength(HWND, LPWSTR);
|
extern LONG controlTextLength(HWND, LPWSTR);
|
||||||
|
|
||||||
|
|
|
@ -87,15 +87,17 @@ func (tw *testwin) make(done chan struct{}) {
|
||||||
NewTextField(),
|
NewTextField(),
|
||||||
NewPasswordField(),
|
NewPasswordField(),
|
||||||
NewTable(reflect.TypeOf(struct{A,B,C int}{})),
|
NewTable(reflect.TypeOf(struct{A,B,C int}{})),
|
||||||
NewStandaloneLabel("hello"))
|
NewStandaloneLabel("hello ÉÀÔ"))
|
||||||
tw.t.Append("Pref Height", tw.sph)
|
tw.t.Append("Pref Height", tw.sph)
|
||||||
stack1 := NewHorizontalStack(NewLabel("Test"), NewTextField())
|
stack1 := NewHorizontalStack(NewLabel("Test"), NewTextField())
|
||||||
stack1.SetStretchy(1)
|
stack1.SetStretchy(1)
|
||||||
stack2 := NewHorizontalStack(NewLabel("Test 2"),
|
stack2 := NewHorizontalStack(NewLabel("ÉÀÔ"), NewTextField())
|
||||||
NewTable(reflect.TypeOf(struct{A,B,C int}{})))
|
|
||||||
stack2.SetStretchy(1)
|
stack2.SetStretchy(1)
|
||||||
tw.s = NewVerticalStack(stack1, stack2)
|
stack3 := NewHorizontalStack(NewLabel("Test 2"),
|
||||||
tw.s.SetStretchy(1)
|
NewTable(reflect.TypeOf(struct{A,B,C int}{})))
|
||||||
|
stack3.SetStretchy(1)
|
||||||
|
tw.s = NewVerticalStack(stack1, stack2, stack3)
|
||||||
|
tw.s.SetStretchy(2)
|
||||||
tw.t.Append("Stack", tw.s)
|
tw.t.Append("Stack", tw.s)
|
||||||
tw.l = NewStandaloneLabel("hello")
|
tw.l = NewStandaloneLabel("hello")
|
||||||
tw.t.Append("Label", tw.l)
|
tw.t.Append("Label", tw.l)
|
||||||
|
|
Loading…
Reference in New Issue