6 Commits

Author SHA1 Message Date
3b4ab56914 Fix child boxes rendering on top of borders
Closes #4
2024-08-23 15:57:53 -04:00
e7f16645eb Unset all attributes when the style changes
Progress on #4
2024-08-23 12:32:46 -04:00
ccbbb735fd Update Tomo API 2024-08-16 17:58:38 -04:00
ab6bdeaba3 Add Bounds, InnerBounds to x.Window 2024-08-16 17:25:17 -04:00
93d7eed21f Update Tomo API 2024-08-16 17:15:01 -04:00
b18f747f0c Fix tag setting not invalidating style 2024-08-14 19:59:53 -04:00
8 changed files with 71 additions and 24 deletions

2
go.mod
View File

@@ -3,7 +3,7 @@ module git.tebibyte.media/tomo/backend
go 1.20 go 1.20
require ( require (
git.tebibyte.media/tomo/tomo v0.45.0 git.tebibyte.media/tomo/tomo v0.46.1
git.tebibyte.media/tomo/typeset v0.7.1 git.tebibyte.media/tomo/typeset v0.7.1
git.tebibyte.media/tomo/xgbkb v1.0.1 git.tebibyte.media/tomo/xgbkb v1.0.1
github.com/jezek/xgb v1.1.1 github.com/jezek/xgb v1.1.1

4
go.sum
View File

@@ -1,6 +1,6 @@
git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q= git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q=
git.tebibyte.media/tomo/tomo v0.45.0 h1:fQH0WIPidW275hOq9dE6R7p064xG1RGx2QU68Avlr84= git.tebibyte.media/tomo/tomo v0.46.1 h1:/8fT6I9l4TK529zokrThbNDHGRvUsNgif1Zs++0PBSQ=
git.tebibyte.media/tomo/tomo v0.45.0/go.mod h1:WrtilgKB1y8O2Yu7X4mYcRiqOlPR8NuUnoA/ynkQWrs= git.tebibyte.media/tomo/tomo v0.46.1/go.mod h1:WrtilgKB1y8O2Yu7X4mYcRiqOlPR8NuUnoA/ynkQWrs=
git.tebibyte.media/tomo/typeset v0.7.1 h1:aZrsHwCG5ZB4f5CruRFsxLv5ezJUCFUFsQJJso2sXQ8= git.tebibyte.media/tomo/typeset v0.7.1 h1:aZrsHwCG5ZB4f5CruRFsxLv5ezJUCFUFsQJJso2sXQ8=
git.tebibyte.media/tomo/typeset v0.7.1/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g= git.tebibyte.media/tomo/typeset v0.7.1/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE= git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE=

View File

@@ -75,7 +75,8 @@ func (this *System) newBox (outer anyBox) *box {
if box.parent == nil { return nil } if box.parent == nil { return nil }
parentCanvas := box.parent.getCanvas() parentCanvas := box.parent.getCanvas()
if parentCanvas == nil { return nil } if parentCanvas == nil { return nil }
return parentCanvas.SubCanvas(box.bounds) drawableArea := box.bounds.Intersect(box.parent.getInnerClippingBounds())
return parentCanvas.SubCanvas(drawableArea)
}) })
if outer == nil { if outer == nil {
box.drawer = box box.drawer = box
@@ -130,11 +131,15 @@ func (this *box) Tag (tag string) bool {
} }
func (this *box) SetTag (tag string, on bool) { func (this *box) SetTag (tag string, on bool) {
wasOn := this.tags.Has(tag)
if on { if on {
this.tags.Add(tag) this.tags.Add(tag)
} else { } else {
delete(this.tags, tag) delete(this.tags, tag)
} }
if wasOn != on {
this.invalidateStyle()
}
} }
func (this *box) SetAttr (attr tomo.Attr) { func (this *box) SetAttr (attr tomo.Attr) {
@@ -255,6 +260,24 @@ func (this *box) unsetAttr (kind tomo.AttrKind, user bool) {
} }
} }
func (this *box) unsetAllAttrs (user bool) {
// keep this in sync with tomo.AttrKind!
this.outer.unsetAttr(tomo.AttrKindColor, user)
this.outer.unsetAttr(tomo.AttrKindTexture, user)
this.outer.unsetAttr(tomo.AttrKindTextureMode, user)
this.outer.unsetAttr(tomo.AttrKindBorder, user)
this.outer.unsetAttr(tomo.AttrKindMinimumSize, user)
this.outer.unsetAttr(tomo.AttrKindPadding, user)
this.outer.unsetAttr(tomo.AttrKindGap, user)
this.outer.unsetAttr(tomo.AttrKindTextColor, user)
this.outer.unsetAttr(tomo.AttrKindDotColor, user)
this.outer.unsetAttr(tomo.AttrKindFace, user)
this.outer.unsetAttr(tomo.AttrKindWrap, user)
this.outer.unsetAttr(tomo.AttrKindAlign, user)
this.outer.unsetAttr(tomo.AttrKindOverflow, user)
this.outer.unsetAttr(tomo.AttrKindLayout, user)
}
func (this *box) setBounds (bounds image.Rectangle) { func (this *box) setBounds (bounds image.Rectangle) {
if this.bounds == bounds { return } if this.bounds == bounds { return }
this.bounds = bounds this.bounds = bounds
@@ -620,6 +643,7 @@ func (this *box) recursiveReApply () {
// applicator for every box, it's so style applicators can cache // applicator for every box, it's so style applicators can cache
// information about the boxes they're linked to (like all rules // information about the boxes they're linked to (like all rules
// with a matching role). // with a matching role).
this.unsetAllAttrs(false)
this.lastStyleNonce = hierarchyStyleNonce this.lastStyleNonce = hierarchyStyleNonce
this.styleApplicator = hierarchy.newStyleApplicator() this.styleApplicator = hierarchy.newStyleApplicator()
this.invalidateStyle() this.invalidateStyle()

View File

@@ -298,6 +298,10 @@ func (this *containerBox) getCanvas () canvas.Canvas {
return this.canvas.Value() return this.canvas.Value()
} }
func (this *containerBox) getInnerClippingBounds () image.Rectangle {
return this.innerClippingBounds
}
func (this *containerBox) notifyMinimumSizeChange (child anyBox) { func (this *containerBox) notifyMinimumSizeChange (child anyBox) {
this.invalidateMinimum() this.invalidateMinimum()
size := child.minimumSize() size := child.minimumSize()

View File

@@ -193,6 +193,10 @@ func (this *Hierarchy) getCanvas () canvas.Canvas {
return this.canvas return this.canvas
} }
func (this *Hierarchy) getInnerClippingBounds () image.Rectangle {
return this.canvas.Bounds()
}
func (this *Hierarchy) getModifiers () input.Modifiers { func (this *Hierarchy) getModifiers () input.Modifiers {
return this.modifiers return this.modifiers
} }

View File

@@ -12,6 +12,9 @@ type parent interface {
getHierarchy () *Hierarchy getHierarchy () *Hierarchy
// canvas returns the canvas held by the parent. // canvas returns the canvas held by the parent.
getCanvas () canvas.Canvas getCanvas () canvas.Canvas
// getInnerClippingBounds returns the area of the canvas that children
// can draw to.
getInnerClippingBounds () image.Rectangle
// notifyMinimumSizeChange informs the parent that the minimum size of // notifyMinimumSizeChange informs the parent that the minimum size of
// one of its children has changed. // one of its children has changed.
notifyMinimumSizeChange (anyBox) notifyMinimumSizeChange (anyBox)

View File

@@ -146,11 +146,14 @@ func (window *window) updateBounds () {
decorGeometry, _ := window.xWindow.DecorGeometry() decorGeometry, _ := window.xWindow.DecorGeometry()
windowGeometry, _ := window.xWindow.Geometry() windowGeometry, _ := window.xWindow.Geometry()
origin := image.Pt ( origin := image.Pt (
windowGeometry.X() + decorGeometry.X(), decorGeometry.X(),
windowGeometry.Y() + decorGeometry.Y()) decorGeometry.Y())
window.metrics.bounds = image.Rectangle { innerOrigin := origin.Add(image.Pt (
Min: origin, windowGeometry.X(),
Max: origin.Add(image.Pt(windowGeometry.Width(), windowGeometry.Height())), windowGeometry.Y()))
window.metrics.innerBounds = image.Rectangle {
Min: innerOrigin,
Max: innerOrigin.Add(image.Pt(windowGeometry.Width(), windowGeometry.Height())),
} }
} }
@@ -161,9 +164,9 @@ func (window *window) handleConfigureNotify (
configureEvent := *event.ConfigureNotifyEvent configureEvent := *event.ConfigureNotifyEvent
configureEvent = window.compressConfigureNotify(configureEvent) configureEvent = window.compressConfigureNotify(configureEvent)
oldBounds := window.metrics.bounds oldBounds := window.metrics.innerBounds
window.updateBounds() window.updateBounds()
newBounds := window.metrics.bounds newBounds := window.metrics.innerBounds
sizeChanged := sizeChanged :=
oldBounds.Dx() != newBounds.Dx() || oldBounds.Dx() != newBounds.Dx() ||

View File

@@ -37,7 +37,8 @@ type window struct {
resizeY bool resizeY bool
metrics struct { metrics struct {
bounds image.Rectangle bounds image.Rectangle // bounds, including frame
innerBounds image.Rectangle // bounds of the drawable area
} }
onClose event.FuncBroadcaster onClose event.FuncBroadcaster
@@ -156,7 +157,7 @@ func (this *Backend) newWindow (
// xevent.SelectionRequestFun(window.handleSelectionRequest). // xevent.SelectionRequestFun(window.handleSelectionRequest).
// Connect(this.x, window.xWindow.Id) // Connect(this.x, window.xWindow.Id)
window.metrics.bounds = bounds window.metrics.innerBounds = bounds
window.doMinimumSize() window.doMinimumSize()
this.windows[window.xWindow.Id] = window this.windows[window.xWindow.Id] = window
@@ -165,6 +166,14 @@ func (this *Backend) newWindow (
return return
} }
func (this *window) Bounds () image.Rectangle {
return this.metrics.bounds.Sub(this.metrics.innerBounds.Min)
}
func (this *window) InnerBounds () image.Rectangle {
return this.metrics.innerBounds.Sub(this.metrics.innerBounds.Min)
}
func (this *window) SetRoot (root tomo.Object) { func (this *window) SetRoot (root tomo.Object) {
if root == nil { if root == nil {
this.hierarchy.SetRoot(nil) this.hierarchy.SetRoot(nil)
@@ -242,7 +251,7 @@ func (this *window) NewChild (bounds image.Rectangle) (tomo.Window, error) {
leader := this.leader leader := this.leader
child, err := this.backend.newWindow ( child, err := this.backend.newWindow (
bounds.Add(this.metrics.bounds.Min), false) bounds.Add(this.metrics.innerBounds.Min), false)
child.leader = leader child.leader = leader
if err != nil { return nil, err } if err != nil { return nil, err }
@@ -260,7 +269,7 @@ func (this *window) NewChild (bounds image.Rectangle) (tomo.Window, error) {
func (this *window) NewMenu (bounds image.Rectangle) (tomo.Window, error) { func (this *window) NewMenu (bounds image.Rectangle) (tomo.Window, error) {
menu, err := this.backend.newWindow ( menu, err := this.backend.newWindow (
bounds.Add(this.metrics.bounds.Min), true) bounds.Add(this.metrics.innerBounds.Min), true)
menu.shy = true menu.shy = true
icccm.WmTransientForSet ( icccm.WmTransientForSet (
this.backend.x, this.backend.x,
@@ -273,7 +282,7 @@ func (this *window) NewMenu (bounds image.Rectangle) (tomo.Window, error) {
func (this *window) NewModal (bounds image.Rectangle) (tomo.Window, error) { func (this *window) NewModal (bounds image.Rectangle) (tomo.Window, error) {
modal, err := this.backend.newWindow ( modal, err := this.backend.newWindow (
bounds.Add(this.metrics.bounds.Min), false) bounds.Add(this.metrics.innerBounds.Min), false)
icccm.WmTransientForSet ( icccm.WmTransientForSet (
this.backend.x, this.backend.x,
modal.xWindow.Id, modal.xWindow.Id,
@@ -382,8 +391,8 @@ func (this *window) reallocateCanvas () {
previousHeight = this.xCanvas.Bounds().Dy() previousHeight = this.xCanvas.Bounds().Dy()
} }
newWidth := this.metrics.bounds.Dx() newWidth := this.metrics.innerBounds.Dx()
newHeight := this.metrics.bounds.Dy() newHeight := this.metrics.innerBounds.Dy()
larger := newWidth > previousWidth || newHeight > previousHeight larger := newWidth > previousWidth || newHeight > previousHeight
smaller := newWidth < previousWidth / 2 || newHeight < previousHeight / 2 smaller := newWidth < previousWidth / 2 || newHeight < previousHeight / 2
@@ -403,7 +412,7 @@ func (this *window) reallocateCanvas () {
} }
this.hierarchy.SetCanvas(this.xCanvas.SubCanvas ( this.hierarchy.SetCanvas(this.xCanvas.SubCanvas (
this.metrics.bounds.Sub(this.metrics.bounds.Min))) this.metrics.innerBounds.Sub(this.metrics.innerBounds.Min)))
} }
func (this *window) pushAll () { func (this *window) pushAll () {
@@ -458,12 +467,12 @@ func (this *window) doMinimumSize () {
this.backend.x, this.backend.x,
this.xWindow.Id, this.xWindow.Id,
&hints) &hints)
newWidth := this.metrics.bounds.Dx() newWidth := this.metrics.innerBounds.Dx()
newHeight := this.metrics.bounds.Dy() newHeight := this.metrics.innerBounds.Dy()
if newWidth < size.X { newWidth = size.X } if newWidth < size.X { newWidth = size.X }
if newHeight < size.Y { newHeight = size.Y } if newHeight < size.Y { newHeight = size.Y }
if newWidth != this.metrics.bounds.Dx() || if newWidth != this.metrics.innerBounds.Dx() ||
newHeight != this.metrics.bounds.Dy() { newHeight != this.metrics.innerBounds.Dy() {
this.xWindow.Resize(newWidth, newHeight) this.xWindow.Resize(newWidth, newHeight)
} }
} }