Removed a bunch of redundant draw calls
Most were related to a but with the keynav api
This commit is contained in:
parent
ce20b7d02c
commit
16a0e76145
@ -126,9 +126,10 @@ func (window *Window) Adopt (child elements.Element) {
|
|||||||
window.childMinimumSizeChangeCallback (
|
window.childMinimumSizeChangeCallback (
|
||||||
child.MinimumSize())
|
child.MinimumSize())
|
||||||
})
|
})
|
||||||
window.resizeChildToFit()
|
if !window.childMinimumSizeChangeCallback(child.MinimumSize()) {
|
||||||
window.childMinimumSizeChangeCallback(child.MinimumSize())
|
window.resizeChildToFit()
|
||||||
window.redrawChildEntirely()
|
window.redrawChildEntirely()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +304,7 @@ func (window *Window) paste (canvas canvas.Canvas) (updatedRegion image.Rectangl
|
|||||||
return bounds
|
return bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
func (window *Window) childMinimumSizeChangeCallback (width, height int) {
|
func (window *Window) childMinimumSizeChangeCallback (width, height int) (resized bool) {
|
||||||
icccm.WmNormalHintsSet (
|
icccm.WmNormalHintsSet (
|
||||||
window.backend.connection,
|
window.backend.connection,
|
||||||
window.xWindow.Id,
|
window.xWindow.Id,
|
||||||
@ -319,14 +320,17 @@ func (window *Window) childMinimumSizeChangeCallback (width, height int) {
|
|||||||
if newWidth != window.metrics.width ||
|
if newWidth != window.metrics.width ||
|
||||||
newHeight != window.metrics.height {
|
newHeight != window.metrics.height {
|
||||||
window.xWindow.Resize(newWidth, newHeight)
|
window.xWindow.Resize(newWidth, newHeight)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (window *Window) childSelectionRequestCallback () (granted bool) {
|
func (window *Window) childSelectionRequestCallback () (granted bool) {
|
||||||
if child, ok := window.child.(elements.Focusable); ok {
|
if _, ok := window.child.(elements.Focusable); ok {
|
||||||
child.HandleFocus(input.KeynavDirectionNeutral)
|
return true
|
||||||
}
|
}
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (window *Window) childSelectionMotionRequestCallback (
|
func (window *Window) childSelectionMotionRequestCallback (
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package basicElements
|
package basicElements
|
||||||
|
|
||||||
import "image"
|
import "image"
|
||||||
|
// import "runtime/debug"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/input"
|
import "git.tebibyte.media/sashakoshka/tomo/input"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||||
@ -36,7 +37,7 @@ func NewButton (text string) (element *Button) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (element *Button) HandleMouseDown (x, y int, button input.Button) {
|
func (element *Button) HandleMouseDown (x, y int, button input.Button) {
|
||||||
if !element.Enabled() { return }
|
if !element.Enabled() { return }
|
||||||
if !element.Focused() { element.Focus() }
|
if !element.Focused() { element.Focus() }
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
element.pressed = true
|
element.pressed = true
|
||||||
@ -45,16 +46,15 @@ func (element *Button) HandleMouseDown (x, y int, button input.Button) {
|
|||||||
|
|
||||||
func (element *Button) HandleMouseUp (x, y int, button input.Button) {
|
func (element *Button) HandleMouseUp (x, y int, button input.Button) {
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
|
// println("handling mouse up")
|
||||||
element.pressed = false
|
element.pressed = false
|
||||||
element.redo()
|
|
||||||
|
|
||||||
within := image.Point { x, y }.
|
within := image.Point { x, y }.
|
||||||
In(element.Bounds())
|
In(element.Bounds())
|
||||||
|
if element.Enabled() && within && element.onClick != nil {
|
||||||
if !element.Enabled() { return }
|
|
||||||
if within && element.onClick != nil {
|
|
||||||
element.onClick()
|
element.onClick()
|
||||||
}
|
}
|
||||||
|
element.redo()
|
||||||
|
// println("done handling mouse up")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Button) HandleMouseMove (x, y int) { }
|
func (element *Button) HandleMouseMove (x, y int) { }
|
||||||
@ -133,6 +133,8 @@ func (element *Button) redo () {
|
|||||||
|
|
||||||
func (element *Button) draw () {
|
func (element *Button) draw () {
|
||||||
bounds := element.Bounds()
|
bounds := element.Bounds()
|
||||||
|
// println(bounds.String(), element.text)
|
||||||
|
// debug.PrintStack()
|
||||||
|
|
||||||
state := theme.PatternState {
|
state := theme.PatternState {
|
||||||
Disabled: !element.Enabled(),
|
Disabled: !element.Enabled(),
|
||||||
|
@ -64,7 +64,10 @@ func (element *Container) Adopt (child elements.Element, expand bool) {
|
|||||||
child.OnDamage (func (region canvas.Canvas) {
|
child.OnDamage (func (region canvas.Canvas) {
|
||||||
element.core.DamageRegion(region.Bounds())
|
element.core.DamageRegion(region.Bounds())
|
||||||
})
|
})
|
||||||
child.OnMinimumSizeChange(element.updateMinimumSize)
|
child.OnMinimumSizeChange (func () {
|
||||||
|
element.updateMinimumSize()
|
||||||
|
element.redoAll()
|
||||||
|
})
|
||||||
if child0, ok := child.(elements.Flexible); ok {
|
if child0, ok := child.(elements.Flexible); ok {
|
||||||
child0.OnFlexibleHeightChange(element.updateMinimumSize)
|
child0.OnFlexibleHeightChange(element.updateMinimumSize)
|
||||||
}
|
}
|
||||||
@ -209,6 +212,7 @@ func (element *Container) childPosition (child elements.Element) (position image
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (element *Container) redoAll () {
|
func (element *Container) redoAll () {
|
||||||
|
if !element.core.HasImage() { return }
|
||||||
// do a layout
|
// do a layout
|
||||||
element.recalculate()
|
element.recalculate()
|
||||||
|
|
||||||
@ -496,7 +500,6 @@ func (element *Container) childFocusRequestCallback (
|
|||||||
child.HandleUnfocus()
|
child.HandleUnfocus()
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
child.HandleFocus(input.KeynavDirectionNeutral)
|
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
@ -37,9 +37,14 @@ func (core *FocusableCore) Focused () (focused bool) {
|
|||||||
|
|
||||||
// Focus focuses this element, if its parent element grants the request.
|
// Focus focuses this element, if its parent element grants the request.
|
||||||
func (core *FocusableCore) Focus () {
|
func (core *FocusableCore) Focus () {
|
||||||
if !core.enabled { return }
|
if !core.enabled || core.focused { return }
|
||||||
if core.onFocusRequest != nil {
|
if core.onFocusRequest != nil {
|
||||||
core.onFocusRequest()
|
if core.onFocusRequest() {
|
||||||
|
core.focused = true
|
||||||
|
if core.drawFocusChange != nil {
|
||||||
|
core.drawFocusChange()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,9 +60,11 @@ func (core *FocusableCore) HandleFocus (
|
|||||||
if core.focused && direction != input.KeynavDirectionNeutral {
|
if core.focused && direction != input.KeynavDirectionNeutral {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
core.focused = true
|
if core.focused == false {
|
||||||
if core.drawFocusChange != nil { core.drawFocusChange() }
|
core.focused = true
|
||||||
|
if core.drawFocusChange != nil { core.drawFocusChange() }
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ func run () {
|
|||||||
controlBar := basicElements.NewContainer(basicLayouts.Horizontal { true, false })
|
controlBar := basicElements.NewContainer(basicLayouts.Horizontal { true, false })
|
||||||
label := basicElements.NewLabel("Play a song!", false)
|
label := basicElements.NewLabel("Play a song!", false)
|
||||||
controlBar.Adopt(label, true)
|
controlBar.Adopt(label, true)
|
||||||
|
controlBar.Adopt(basicElements.NewLabel("Play a song!", false), true)
|
||||||
waveformButton := basicElements.NewButton("Sine")
|
waveformButton := basicElements.NewButton("Sine")
|
||||||
waveformButton.OnClick (func () {
|
waveformButton.OnClick (func () {
|
||||||
waveform = (waveform + 1) % 2
|
waveform = (waveform + 1) % 2
|
||||||
|
Reference in New Issue
Block a user