Compare commits

..

3 Commits

3 changed files with 26 additions and 24 deletions

View File

@ -484,9 +484,6 @@ func (this *box) calculateMinimumSize () image.Point {
minSize.Y = userMinSize.Y minSize.Y = userMinSize.Y
} }
if this.parent != nil {
this.parent.notifyMinimumSizeChange(this)
}
return minSize return minSize
} }
@ -564,6 +561,9 @@ func (this *box) invalidateDraw () {
func (this *box) invalidateMinimum () { func (this *box) invalidateMinimum () {
this.minSize.Invalidate() this.minSize.Invalidate()
if this.parent != nil {
this.parent.notifyMinimumSizeChange(this)
}
} }
func (this *box) recursiveReApply () { func (this *box) recursiveReApply () {

View File

@ -20,7 +20,6 @@ type containerBox struct {
attrLayout attrHierarchy[tomo.AttrLayout] attrLayout attrHierarchy[tomo.AttrLayout]
children []anyBox children []anyBox
layout tomo.Layout
on struct { on struct {
contentBoundsChange event.FuncBroadcaster contentBoundsChange event.FuncBroadcaster
@ -187,19 +186,21 @@ func (this *containerBox) setAttr (attr tomo.Attr, user bool) {
} }
func (this *containerBox) recommendedHeight (width int) int { func (this *containerBox) recommendedHeight (width int) int {
if this.layout == nil || this.attrOverflow.Value().Y { layout := this.attrLayout.Value().Layout
if layout == nil || this.attrOverflow.Value().Y {
return this.minSize.Value().Y return this.minSize.Value().Y
} else { } else {
return this.layout.RecommendedHeight(this.layoutHints(), this.boxQuerier(), width) + return layout.RecommendedHeight(this.layoutHints(), this.boxQuerier(), width) +
this.borderAndPaddingSum().Vertical() this.borderAndPaddingSum().Vertical()
} }
} }
func (this *containerBox) recommendedWidth (height int) int { func (this *containerBox) recommendedWidth (height int) int {
if this.layout == nil || this.attrOverflow.Value().X { layout := this.attrLayout.Value().Layout
if layout == nil || this.attrOverflow.Value().X {
return this.minSize.Value().X return this.minSize.Value().X
} else { } else {
return this.layout.RecommendedWidth(this.layoutHints(), this.boxQuerier(), height) + return layout.RecommendedWidth(this.layoutHints(), this.boxQuerier(), height) +
this.borderAndPaddingSum().Horizontal() this.borderAndPaddingSum().Horizontal()
} }
} }
@ -274,8 +275,9 @@ func (this *containerBox) layoutHints () tomo.LayoutHints {
func (this *containerBox) contentMinimum () image.Point { func (this *containerBox) contentMinimum () image.Point {
overflow := this.attrOverflow.Value() overflow := this.attrOverflow.Value()
minimum := this.box.contentMinimum() minimum := this.box.contentMinimum()
if this.layout != nil { layout := this.attrLayout.Value().Layout
layoutMinimum := this.layout.MinimumSize ( if layout != nil {
layoutMinimum := layout.MinimumSize (
this.layoutHints(), this.layoutHints(),
this.boxQuerier()) this.boxQuerier())
if overflow.X { layoutMinimum.X = 0 } if overflow.X { layoutMinimum.X = 0 }
@ -288,12 +290,13 @@ func (this *containerBox) contentMinimum () image.Point {
func (this *containerBox) doLayout () { func (this *containerBox) doLayout () {
this.box.doLayout() this.box.doLayout()
previousContentBounds := this.contentBounds previousContentBounds := this.contentBounds
layout := this.attrLayout.Value().Layout
// by default, use innerBounds (translated to 0, 0) for contentBounds. // by default, use innerBounds (translated to 0, 0) for contentBounds.
// if a direction overflows, use the layout's minimum size for it. // if a direction overflows, use the layout's minimum size for it.
var minimum image.Point var minimum image.Point
if this.layout != nil { if layout != nil {
minimum = this.layout.MinimumSize ( minimum = layout.MinimumSize (
this.layoutHints(), this.layoutHints(),
this.boxQuerier()) this.boxQuerier())
} }
@ -304,10 +307,10 @@ func (this *containerBox) doLayout () {
if overflow.Y { this.contentBounds.Max.Y = this.contentBounds.Min.Y + minimum.Y } if overflow.Y { this.contentBounds.Max.Y = this.contentBounds.Min.Y + minimum.Y }
// arrange children // arrange children
if this.layout != nil { if layout != nil {
layoutHints := this.layoutHints() layoutHints := this.layoutHints()
layoutHints.Bounds = this.contentBounds layoutHints.Bounds = this.contentBounds
this.layout.Arrange(layoutHints, this.boxArranger()) layout.Arrange(layoutHints, this.boxArranger())
} }
// build an accurate contentBounds by unioning the bounds of all child // build an accurate contentBounds by unioning the bounds of all child
@ -323,7 +326,7 @@ func (this *containerBox) doLayout () {
// offset children and contentBounds by scroll // offset children and contentBounds by scroll
for _, box := range this.children { for _, box := range this.children {
assertAnyBox(box).setBounds(box.Bounds().Add(this.scroll).Add(innerBounds.Min)) box.setBounds(box.Bounds().Add(this.scroll).Add(innerBounds.Min))
} }
this.contentBounds = this.contentBounds.Add(this.scroll) this.contentBounds = this.contentBounds.Add(this.scroll)

View File

@ -5,20 +5,21 @@ import "git.tebibyte.media/tomo/tomo"
type styleApplicator struct { type styleApplicator struct {
style *tomo.Style style *tomo.Style
role tomo.Role role tomo.Role
rules []*tomo.Rule rules []tomo.Rule
} }
func (this *styleApplicator) apply (box anyBox) { func (this *styleApplicator) apply (box anyBox) {
if box.Role() != this.role { if box.Role() != this.role {
this.role = box.Role()
// the role has changed, so re-cache the list of rules // the role has changed, so re-cache the list of rules
this.rules = make([]*tomo.Rule, 0, 4) this.rules = nil
for _, rule := range this.style.Rules { for _, rule := range this.style.Rules {
role := box.Role() role := box.Role()
// blank fields match anything // blank fields match anything
if rule.Role.Package == "" { role.Package = "" } if rule.Role.Package == "" { role.Package = "" }
if rule.Role.Object == "" { role.Object = "" } if rule.Role.Object == "" { role.Object = "" }
if rule.Role == role { if rule.Role == role {
this.rules = append(this.rules, &rule) this.rules = append(this.rules, rule)
} }
} }
} }
@ -27,14 +28,12 @@ func (this *styleApplicator) apply (box anyBox) {
attrs := make(tomo.AttrSet) attrs := make(tomo.AttrSet)
for _, rule := range this.rules { for _, rule := range this.rules {
satisifed := true satisifed := true
if rule.Tags != nil {
for _, tag := range rule.Tags { for _, tag := range rule.Tags {
if !box.Tag(tag) { if !box.Tag(tag) {
satisifed = false satisifed = false
break break
} }
} }
}
if satisifed { if satisifed {
attrs.MergeOver(rule.Set) attrs.MergeOver(rule.Set)