Fun and testing elements conform to new API

This commit is contained in:
Sasha Koshka 2023-01-31 14:57:02 -05:00
parent ee424b9125
commit d5028317ef
3 changed files with 5 additions and 13 deletions

View File

@ -19,17 +19,11 @@ type AnalogClock struct {
// NewAnalogClock creates a new analog clock that displays the specified time. // NewAnalogClock creates a new analog clock that displays the specified time.
func NewAnalogClock (newTime time.Time) (element *AnalogClock) { func NewAnalogClock (newTime time.Time) (element *AnalogClock) {
element = &AnalogClock { } element = &AnalogClock { }
element.Core, element.core = core.NewCore(element) element.Core, element.core = core.NewCore(element.draw)
element.core.SetMinimumSize(64, 64) element.core.SetMinimumSize(64, 64)
return return
} }
// Resize changes the size of the clock.
func (element *AnalogClock) Resize (width, height int) {
element.core.AllocateCanvas(width, height)
element.draw()
}
// SetTime changes the time that the clock displays. // SetTime changes the time that the clock displays.
func (element *AnalogClock) SetTime (newTime time.Time) { func (element *AnalogClock) SetTime (newTime time.Time) {
if newTime == element.time { return } if newTime == element.time { return }

View File

@ -19,13 +19,12 @@ type Artist struct {
// NewArtist creates a new artist test element. // NewArtist creates a new artist test element.
func NewArtist () (element *Artist) { func NewArtist () (element *Artist) {
element = &Artist { } element = &Artist { }
element.Core, element.core = core.NewCore(element) element.Core, element.core = core.NewCore(element.draw)
element.core.SetMinimumSize(480, 600) element.core.SetMinimumSize(480, 600)
return return
} }
func (element *Artist) Resize (width, height int) { func (element *Artist) draw () {
element.core.AllocateCanvas(width, height)
bounds := element.Bounds() bounds := element.Bounds()
element.cellBounds.Max.X = bounds.Dx() / 5 element.cellBounds.Max.X = bounds.Dx() / 5
element.cellBounds.Max.Y = (bounds.Dy() - 48) / 8 element.cellBounds.Max.Y = (bounds.Dy() - 48) / 8

View File

@ -20,14 +20,13 @@ type Mouse struct {
// NewMouse creates a new mouse test element. // NewMouse creates a new mouse test element.
func NewMouse () (element *Mouse) { func NewMouse () (element *Mouse) {
element = &Mouse { } element = &Mouse { }
element.Core, element.core = core.NewCore(element) element.Core, element.core = core.NewCore(element.draw)
element.core.SetMinimumSize(32, 32) element.core.SetMinimumSize(32, 32)
element.color = artist.NewUniform(color.Black) element.color = artist.NewUniform(color.Black)
return return
} }
func (element *Mouse) Resize (width, height int) { func (element *Mouse) draw () {
element.core.AllocateCanvas(width, height)
bounds := element.Bounds() bounds := element.Bounds()
pattern, _ := theme.AccentPattern(theme.PatternState { }) pattern, _ := theme.AccentPattern(theme.PatternState { })
artist.FillRectangle(element.core, pattern, bounds) artist.FillRectangle(element.core, pattern, bounds)