Default elements compile

This commit is contained in:
2023-02-26 22:20:17 -05:00
parent 241c297626
commit cda2d1f0ae
25 changed files with 268 additions and 205 deletions

View File

@@ -3,9 +3,10 @@ package fun
import "time"
import "math"
import "image"
import "image/color"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
// AnalogClock can display the time of day in an analog format.
@@ -58,15 +59,15 @@ func (element *AnalogClock) redo () {
func (element *AnalogClock) draw () {
bounds := element.Bounds()
state := theme.PatternState { }
state := theme.State { }
pattern := element.theme.Pattern(theme.PatternSunken, state)
inset := element.theme.Inset(theme.PatternSunken)
artist.FillRectangle(element.core, pattern, bounds)
padding := element.theme.Padding(theme.PatternSunken)
pattern.Draw(element.core, bounds)
bounds = inset.Apply(bounds)
bounds = padding.Apply(bounds)
foreground := element.theme.Pattern(theme.PatternForeground, state)
accent := element.theme.Pattern(theme.PatternAccent, state)
foreground := element.theme.Color(theme.ColorForeground, state)
accent := element.theme.Color(theme.ColorAccent, state)
for hour := 0; hour < 12; hour ++ {
element.radialLine (
@@ -93,7 +94,7 @@ func (element *AnalogClock) FlexibleHeightFor (width int) (height int) {
func (element *AnalogClock) OnFlexibleHeightChange (func ()) { }
func (element *AnalogClock) radialLine (
source artist.Pattern,
source color.RGBA,
inner float64,
outer float64,
radian float64,
@@ -107,5 +108,5 @@ func (element *AnalogClock) radialLine (
max := element.Bounds().Min.Add(image.Pt (
int(math.Cos(radian) * outer * width + width),
int(math.Sin(radian) * outer * height + height)))
artist.Line(element.core, source, 1, min, max)
shapes.ColorLine(element.core, source, 1, min, max)
}

View File

@@ -218,10 +218,11 @@ func (element *Piano) SetConfig (new config.Config) {
}
func (element *Piano) updateMinimumSize () {
inset := element.theme.Inset(theme.PatternSunken)
padding := element.theme.Padding(theme.PatternSunken)
element.core.SetMinimumSize (
pianoKeyWidth * 7 * element.countOctaves() + inset[1] + inset[3],
64 + inset[0] + inset[2])
pianoKeyWidth * 7 * element.countOctaves() +
padding[1] + padding[3],
64 + padding[0] + padding[2])
}
func (element *Piano) countOctaves () int {
@@ -247,8 +248,8 @@ func (element *Piano) recalculate () {
element.flatKeys = make([]pianoKey, element.countFlats())
element.sharpKeys = make([]pianoKey, element.countSharps())
inset := element.theme.Inset(theme.PatternPinboard)
bounds := inset.Apply(element.Bounds())
padding := element.theme.Padding(theme.PatternPinboard)
bounds := padding.Apply(element.Bounds())
dot := bounds.Min
note := element.low.Note(0)
@@ -280,7 +281,7 @@ func (element *Piano) recalculate () {
}
func (element *Piano) draw () {
state := theme.PatternState {
state := theme.State {
Focused: element.Focused(),
Disabled: !element.Enabled(),
}
@@ -303,28 +304,28 @@ func (element *Piano) draw () {
}
pattern := element.theme.Pattern(theme.PatternPinboard, state)
artist.FillRectangleShatter (
element.core, pattern, element.Bounds(), element.contentBounds)
artist.DrawShatter (
element.core, pattern, element.contentBounds)
}
func (element *Piano) drawFlat (
bounds image.Rectangle,
pressed bool,
state theme.PatternState,
state theme.State,
) {
state.Pressed = pressed
pattern := element.theme.Theme.Pattern (
theme.PatternButton, state, theme.C("fun", "flatKey"))
artist.FillRectangle(element.core, pattern, bounds)
artist.DrawBounds(element.core, pattern, bounds)
}
func (element *Piano) drawSharp (
bounds image.Rectangle,
pressed bool,
state theme.PatternState,
state theme.State,
) {
state.Pressed = pressed
pattern := element.theme.Theme.Pattern (
theme.PatternButton, state, theme.C("fun", "sharpKey"))
artist.FillRectangle(element.core, pattern, bounds)
artist.DrawBounds(element.core, pattern, bounds)
}