summaryrefslogtreecommitdiff
path: root/redo/basicctrls_darwin.go
diff options
context:
space:
mode:
Diffstat (limited to 'redo/basicctrls_darwin.go')
-rw-r--r--redo/basicctrls_darwin.go34
1 files changed, 32 insertions, 2 deletions
diff --git a/redo/basicctrls_darwin.go b/redo/basicctrls_darwin.go
index 1899133..13470f5 100644
--- a/redo/basicctrls_darwin.go
+++ b/redo/basicctrls_darwin.go
@@ -103,7 +103,8 @@ func (t *textField) SetText(text string) {
// cheap trick
type label struct {
*textField
- standalone bool
+ standalone bool
+ supercommitResize func(c *allocation, d *sizing)
}
func finishNewLabel(text string, standalone bool) *label {
@@ -112,6 +113,8 @@ func finishNewLabel(text string, standalone bool) *label {
standalone: standalone,
}
l.SetText(text)
+ l.supercommitResize = l.fcommitResize
+ l.fcommitResize = l.labelcommitResize
return l
}
@@ -123,4 +126,31 @@ func newStandaloneLabel(text string) Label {
return finishNewLabel(text, true)
}
-// TODO label commitResize
+func (l *label) labelcommitResize(c *allocation, d *sizing) {
+ if !l.standalone && c.neighbor != nil {
+ c.neighbor.getAuxResizeInfo(d)
+ if d.neighborAlign.baseline != 0 { // no adjustment needed if the given control has no baseline
+ // in order for the baseline value to be correct, the label MUST BE AT THE HEIGHT THAT OS X WANTS IT TO BE!
+ // otherwise, the baseline calculation will be relative to the bottom of the control, and everything will be wrong
+ origsize := C.controlPrefSize(l.id)
+ c.height = int(origsize.height)
+ newrect := C.struct_xrect{
+ x: C.intptr_t(c.x),
+ y: C.intptr_t(c.y),
+ width: C.intptr_t(c.width),
+ height: C.intptr_t(c.height),
+ }
+ ourAlign := C.alignmentInfo(l.id, newrect)
+ // we need to find the exact Y positions of the baselines
+ // fortunately, this is easy now that (x,y) is the bottom-left corner
+ thisbasey := ourAlign.rect.y + ourAlign.baseline
+ neighborbasey := d.neighborAlign.rect.y + d.neighborAlign.baseline
+ // now the amount we have to move the label down by is easy to find
+ yoff := neighborbasey - thisbasey
+ // and we just add that
+ c.y += int(yoff)
+ }
+ // TODO if there's no baseline, the alignment should be to the top /of the alignment rect/, not the frame
+ }
+ l.supercommitResize(c, d)
+}