Basic and fun elements conform to new API change

This commit is contained in:
Sasha Koshka 2023-03-12 01:15:36 -05:00
parent d31aee1ba8
commit 92e5822185
10 changed files with 37 additions and 34 deletions

View File

@ -176,7 +176,7 @@ func (element *Checkbox) draw () {
backgroundPattern.Draw(element.core, bounds) backgroundPattern.Draw(element.core, bounds)
pattern := element.theme.Pattern(theme.PatternButton, state) pattern := element.theme.Pattern(theme.PatternButton, state)
artist.DrawBounds(element.core, pattern, boxBounds) pattern.Draw(element.core, boxBounds)
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
margin := element.theme.Margin(theme.PatternBackground) margin := element.theme.Margin(theme.PatternBackground)

View File

@ -138,7 +138,7 @@ func (element *Container) Disown (child elements.Element) {
} }
func (element *Container) clearChildEventHandlers (child elements.Element) { func (element *Container) clearChildEventHandlers (child elements.Element) {
child.DrawTo(nil) child.DrawTo(nil, image.Rectangle { })
child.OnDamage(nil) child.OnDamage(nil)
child.OnMinimumSizeChange(nil) child.OnMinimumSizeChange(nil)
if child0, ok := child.(elements.Focusable); ok { if child0, ok := child.(elements.Focusable); ok {
@ -203,7 +203,7 @@ func (element *Container) redoAll () {
// remove child canvasses so that any operations done in here will not // remove child canvasses so that any operations done in here will not
// cause a child to draw to a wack ass canvas. // cause a child to draw to a wack ass canvas.
for _, entry := range element.children { for _, entry := range element.children {
entry.DrawTo(nil) entry.DrawTo(nil, entry.Bounds)
} }
// do a layout // do a layout
@ -217,12 +217,13 @@ func (element *Container) redoAll () {
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternBackground, theme.PatternBackground,
theme.State { }) theme.State { })
artist.DrawShatter ( artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...)
element.core, pattern, rocks...)
// cut our canvas up and give peices to child elements // cut our canvas up and give peices to child elements
for _, entry := range element.children { for _, entry := range element.children {
entry.DrawTo(canvas.Cut(element.core, entry.Bounds)) entry.DrawTo (
canvas.Cut(element.core, entry.Bounds),
entry.Bounds)
} }
} }

View File

@ -123,7 +123,7 @@ func (element *DocumentContainer) Disown (child elements.Element) {
} }
func (element *DocumentContainer) clearChildEventHandlers (child elements.Element) { func (element *DocumentContainer) clearChildEventHandlers (child elements.Element) {
child.DrawTo(nil) child.DrawTo(nil, image.Rectangle { })
child.OnDamage(nil) child.OnDamage(nil)
child.OnMinimumSizeChange(nil) child.OnMinimumSizeChange(nil)
if child0, ok := child.(elements.Focusable); ok { if child0, ok := child.(elements.Focusable); ok {
@ -201,8 +201,7 @@ func (element *DocumentContainer) redoAll () {
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternBackground, theme.PatternBackground,
theme.State { }) theme.State { })
artist.DrawShatter ( artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...)
element.core, pattern, rocks...)
element.partition() element.partition()
if element.onScrollBoundsChange != nil { if element.onScrollBoundsChange != nil {
@ -212,13 +211,15 @@ func (element *DocumentContainer) redoAll () {
func (element *DocumentContainer) partition () { func (element *DocumentContainer) partition () {
for _, entry := range element.children { for _, entry := range element.children {
entry.DrawTo(nil) entry.DrawTo(nil, entry.Bounds)
} }
// cut our canvas up and give peices to child elements // cut our canvas up and give peices to child elements
for _, entry := range element.children { for _, entry := range element.children {
if entry.Bounds.Overlaps(element.Bounds()) { if entry.Bounds.Overlaps(element.Bounds()) {
entry.DrawTo(canvas.Cut(element.core, entry.Bounds)) entry.DrawTo (
canvas.Cut(element.core, entry.Bounds),
entry.Bounds)
} }
} }
} }

View File

@ -70,7 +70,7 @@ func (entry *ListEntry) Draw (
pattern := entry.theme.Pattern(theme.PatternRaised, state) pattern := entry.theme.Pattern(theme.PatternRaised, state)
padding := entry.theme.Padding(theme.PatternRaised) padding := entry.theme.Padding(theme.PatternRaised)
bounds := entry.Bounds().Add(offset) bounds := entry.Bounds().Add(offset)
artist.DrawBounds(destination, pattern, bounds) pattern.Draw(destination, bounds)
foreground := entry.theme.Color (theme.ColorForeground, state) foreground := entry.theme.Color (theme.ColorForeground, state)
return entry.drawer.Draw ( return entry.drawer.Draw (

View File

@ -78,5 +78,5 @@ func (element *ProgressBar) draw () {
bounds.Min.X + int(float64(bounds.Dx()) * element.progress), bounds.Min.X + int(float64(bounds.Dx()) * element.progress),
bounds.Max.Y) bounds.Max.Y)
mercury := element.theme.Pattern(theme.PatternMercury, theme.State { }) mercury := element.theme.Pattern(theme.PatternMercury, theme.State { })
artist.DrawBounds(element.core, mercury, meterBounds) mercury.Draw(element.core, meterBounds)
} }

View File

@ -315,12 +315,10 @@ func (element *ScrollBar) draw () {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Pressed: element.dragging, Pressed: element.dragging,
} }
artist.DrawBounds ( element.theme.Pattern(theme.PatternGutter, state).Draw (
element.core, element.core,
element.theme.Pattern(theme.PatternGutter, state),
bounds) bounds)
artist.DrawBounds ( element.theme.Pattern(theme.PatternHandle, state).Draw (
element.core, element.core,
element.theme.Pattern(theme.PatternHandle, state),
element.bar) element.bar)
} }

View File

@ -120,7 +120,7 @@ func (element *ScrollContainer) setChildEventHandlers (child elements.Element) {
} }
func (element *ScrollContainer) clearChildEventHandlers (child elements.Scrollable) { func (element *ScrollContainer) clearChildEventHandlers (child elements.Scrollable) {
child.DrawTo(nil) child.DrawTo(nil, image.Rectangle { })
child.OnDamage(nil) child.OnDamage(nil)
child.OnMinimumSizeChange(nil) child.OnMinimumSizeChange(nil)
child.OnScrollBoundsChange(nil) child.OnScrollBoundsChange(nil)
@ -198,19 +198,26 @@ func (element *ScrollContainer) Child (index int) (child elements.Element) {
func (element *ScrollContainer) redoAll () { func (element *ScrollContainer) redoAll () {
if !element.core.HasImage() { return } if !element.core.HasImage() { return }
if element.child != nil { element.child.DrawTo(nil) } zr := image.Rectangle { }
if element.horizontal != nil { element.horizontal.DrawTo(nil) } if element.child != nil { element.child.DrawTo(nil, zr) }
if element.vertical != nil { element.vertical.DrawTo(nil) } if element.horizontal != nil { element.horizontal.DrawTo(nil, zr) }
if element.vertical != nil { element.vertical.DrawTo(nil, zr) }
childBounds, horizontalBounds, verticalBounds := element.layout() childBounds, horizontalBounds, verticalBounds := element.layout()
if element.child != nil { if element.child != nil {
element.child.DrawTo(canvas.Cut(element.core, childBounds)) element.child.DrawTo (
canvas.Cut(element.core, childBounds),
childBounds)
} }
if element.horizontal != nil { if element.horizontal != nil {
element.horizontal.DrawTo(canvas.Cut(element.core, horizontalBounds)) element.horizontal.DrawTo (
canvas.Cut(element.core, horizontalBounds),
horizontalBounds)
} }
if element.vertical != nil { if element.vertical != nil {
element.vertical.DrawTo(canvas.Cut(element.core, verticalBounds)) element.vertical.DrawTo (
canvas.Cut(element.core, verticalBounds),
verticalBounds)
} }
element.draw() element.draw()
} }

View File

@ -4,7 +4,6 @@ import "image"
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"
import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
// Slider is a slider control with a floating point value between zero and one. // Slider is a slider control with a floating point value between zero and one.
@ -229,12 +228,10 @@ func (element *Slider) draw () {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Pressed: element.dragging, Pressed: element.dragging,
} }
artist.DrawBounds ( element.theme.Pattern(theme.PatternGutter, state).Draw (
element.core, element.core,
element.theme.Pattern(theme.PatternGutter, state),
bounds) bounds)
artist.DrawBounds ( element.theme.Pattern(theme.PatternHandle, state).Draw (
element.core, element.core,
element.theme.Pattern(theme.PatternHandle, state),
element.bar) element.bar)
} }

View File

@ -4,7 +4,6 @@ import "image"
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"
import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/textdraw" import "git.tebibyte.media/sashakoshka/tomo/textdraw"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
@ -185,11 +184,11 @@ func (element *Switch) draw () {
gutterPattern := element.theme.Pattern ( gutterPattern := element.theme.Pattern (
theme.PatternGutter, state) theme.PatternGutter, state)
artist.DrawBounds(element.core, gutterPattern, gutterBounds) gutterPattern.Draw(element.core, gutterBounds)
handlePattern := element.theme.Pattern ( handlePattern := element.theme.Pattern (
theme.PatternHandle, state) theme.PatternHandle, state)
artist.DrawBounds(element.core, handlePattern, handleBounds) handlePattern.Draw(element.core, handleBounds)
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
offset := bounds.Min.Add(image.Point { offset := bounds.Min.Add(image.Point {

View File

@ -316,7 +316,7 @@ func (element *Piano) drawFlat (
state.Pressed = pressed state.Pressed = pressed
pattern := element.theme.Theme.Pattern ( pattern := element.theme.Theme.Pattern (
theme.PatternButton, state, theme.C("fun", "flatKey")) theme.PatternButton, state, theme.C("fun", "flatKey"))
artist.DrawBounds(element.core, pattern, bounds) pattern.Draw(element.core, bounds)
} }
func (element *Piano) drawSharp ( func (element *Piano) drawSharp (
@ -327,5 +327,5 @@ func (element *Piano) drawSharp (
state.Pressed = pressed state.Pressed = pressed
pattern := element.theme.Theme.Pattern ( pattern := element.theme.Theme.Pattern (
theme.PatternButton, state, theme.C("fun", "sharpKey")) theme.PatternButton, state, theme.C("fun", "sharpKey"))
artist.DrawBounds(element.core, pattern, bounds) pattern.Draw(element.core, bounds)
} }