Default elements compile

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

View File

@ -48,3 +48,13 @@ func (inset Inset) Inverse () (prime Inset) {
inset[3] * -1, inset[3] * -1,
} }
} }
// Horizontal returns the sum of SideRight and SideLeft.
func (inset Inset) Horizontal () int {
return inset[SideRight] + inset[SideLeft]
}
// Vertical returns the sum of SideTop and SideBottom.
func (inset Inset) Vertical () int {
return inset[SideTop] + inset[SideBottom]
}

View File

@ -2,6 +2,7 @@ package artist
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/shatter"
// Pattern is capable of drawing to a canvas within the bounds of a given // Pattern is capable of drawing to a canvas within the bounds of a given
// clipping rectangle. // clipping rectangle.
@ -20,24 +21,38 @@ func Draw (
destination canvas.Canvas, destination canvas.Canvas,
source Pattern, source Pattern,
clips ...image.Rectangle, clips ...image.Rectangle,
) (
updatedRegion image.Rectangle,
) { ) {
for _, clip := range clips { for _, clip := range clips {
source.Draw(destination, clip) source.Draw(destination, clip)
updatedRegion = updatedRegion.Union(clip)
} }
return
} }
// DrawBounds is like Draw, but lets you specify an overall bounding rectangle // DrawBounds lets you specify an overall bounding rectangle for drawing a
// for the pattern. The destination is cut to this rectangle. // pattern. The destination is cut to this rectangle.
func DrawBounds ( func DrawBounds (
destination canvas.Canvas, destination canvas.Canvas,
bounds image.Rectangle,
source Pattern, source Pattern,
clips ...image.Rectangle, bounds image.Rectangle,
) (
updatedRegion image.Rectangle,
) { ) {
cut := canvas.Cut(destination, bounds) return Draw(canvas.Cut(destination, bounds), source, bounds)
for _, clip := range clips {
source.Draw(cut, clip)
} }
// DrawShatter is like an inverse of Draw, drawing nothing in the areas
// specified in "rocks".
func DrawShatter (
destination canvas.Canvas,
source Pattern,
rocks ...image.Rectangle,
) (
updatedRegion image.Rectangle,
) {
return Draw(destination, source, shatter.Shatter(destination.Bounds(), rocks...)...)
} }
// AllocateSample returns a new canvas containing the result of a pattern. The // AllocateSample returns a new canvas containing the result of a pattern. The

View File

@ -34,6 +34,21 @@ func NewBasicCanvas (width, height int) (canvas BasicCanvas) {
return return
} }
// FromImage creates a new BasicCanvas from an image.Image.
func FromImage (img image.Image) (canvas BasicCanvas) {
bounds := img.Bounds()
canvas = NewBasicCanvas(bounds.Dx(), bounds.Dy())
point := image.Point { }
for point.Y = bounds.Min.Y; point.Y < bounds.Max.Y; point.Y ++ {
for point.X = bounds.Min.X; point.X < bounds.Max.X; point.X ++ {
canvasPoint := point.Sub(bounds.Min)
canvas.Set (
canvasPoint.X, canvasPoint.Y,
img.At(point.X, point.Y))
}}
return
}
// you know what it do // you know what it do
func (canvas BasicCanvas) Bounds () (bounds image.Rectangle) { func (canvas BasicCanvas) Bounds () (bounds image.Rectangle) {
return canvas.rect return canvas.rect

View File

@ -6,6 +6,7 @@ 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/artist"
import "git.tebibyte.media/sashakoshka/tomo/shatter"
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"
@ -121,7 +122,8 @@ func (element *Button) SetConfig (new config.Config) {
func (element *Button) updateMinimumSize () { func (element *Button) updateMinimumSize () {
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
minimumSize := textBounds.Inset(-element.config.Padding()) padding := element.theme.Padding(theme.PatternButton)
minimumSize := padding.Inverse().Apply(textBounds)
element.core.SetMinimumSize(minimumSize.Dx(), minimumSize.Dy()) element.core.SetMinimumSize(minimumSize.Dx(), minimumSize.Dy())
} }
@ -138,8 +140,8 @@ func (element *Button) drawAndPush (partial bool) {
} }
} }
func (element *Button) state () theme.PatternState { func (element *Button) state () theme.State {
return theme.PatternState { return theme.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
Pressed: element.pressed, Pressed: element.pressed,
@ -152,20 +154,20 @@ func (element *Button) drawBackground (partial bool) []image.Rectangle {
pattern := element.theme.Pattern(theme.PatternButton, state) pattern := element.theme.Pattern(theme.PatternButton, state)
static := element.theme.Hints(theme.PatternButton).StaticInset static := element.theme.Hints(theme.PatternButton).StaticInset
if partial && static != (theme.Inset { }) { if partial && static != (artist.Inset { }) {
return artist.FillRectangleShatter ( tiles := shatter.Shatter(bounds, static.Apply(bounds))
element.core, pattern, bounds, static.Apply(bounds)) artist.Draw(element.core, pattern, tiles...)
return tiles
} else { } else {
return []image.Rectangle { pattern.Draw(element.core, bounds)
artist.FillRectangle(element.core, pattern, bounds), return []image.Rectangle { bounds }
}
} }
} }
func (element *Button) drawText (partial bool) image.Rectangle { func (element *Button) drawText (partial bool) image.Rectangle {
state := element.state() state := element.state()
bounds := element.Bounds() bounds := element.Bounds()
foreground := element.theme.Pattern(theme.PatternForeground, state) foreground := element.theme.Color(theme.ColorForeground, state)
sink := element.theme.Sink(theme.PatternButton) sink := element.theme.Sink(theme.PatternButton)
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
@ -183,8 +185,7 @@ func (element *Button) drawText (partial bool) image.Rectangle {
if partial { if partial {
pattern := element.theme.Pattern(theme.PatternButton, state) pattern := element.theme.Pattern(theme.PatternButton, state)
artist.FillRectangleClip ( pattern.Draw(element.core, region)
element.core, pattern, bounds, region)
} }
element.drawer.Draw(element.core, foreground, offset) element.drawer.Draw(element.core, foreground, offset)

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"
@ -146,8 +145,9 @@ func (element *Checkbox) updateMinimumSize () {
if element.text == "" { if element.text == "" {
element.core.SetMinimumSize(textBounds.Dy(), textBounds.Dy()) element.core.SetMinimumSize(textBounds.Dy(), textBounds.Dy())
} else { } else {
margin := element.theme.Margin(theme.PatternBackground)
element.core.SetMinimumSize ( element.core.SetMinimumSize (
textBounds.Dy() + element.config.Padding() + textBounds.Dx(), textBounds.Dy() + margin.X + textBounds.Dx(),
textBounds.Dy()) textBounds.Dy())
} }
} }
@ -163,7 +163,7 @@ func (element *Checkbox) draw () {
bounds := element.Bounds() bounds := element.Bounds()
boxBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min) boxBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min)
state := theme.PatternState { state := theme.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
Pressed: element.pressed, Pressed: element.pressed,
@ -172,19 +172,20 @@ func (element *Checkbox) draw () {
backgroundPattern := element.theme.Pattern ( backgroundPattern := element.theme.Pattern (
theme.PatternBackground, state) theme.PatternBackground, state)
artist.FillRectangle(element.core, backgroundPattern, bounds) backgroundPattern.Draw(element.core, bounds)
pattern := element.theme.Pattern(theme.PatternButton, state) pattern := element.theme.Pattern(theme.PatternButton, state)
artist.FillRectangle(element.core, pattern, boxBounds) pattern.Draw(element.core, boxBounds)
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
margin := element.theme.Margin(theme.PatternBackground)
offset := bounds.Min.Add(image.Point { offset := bounds.Min.Add(image.Point {
X: bounds.Dy() + element.config.Padding(), X: bounds.Dy() + margin.X,
}) })
offset.Y -= textBounds.Min.Y offset.Y -= textBounds.Min.Y
offset.X -= textBounds.Min.X offset.X -= textBounds.Min.X
foreground := element.theme.Pattern(theme.PatternForeground, state) foreground := element.theme.Color(theme.ColorForeground, state)
element.drawer.Draw(element.core, foreground, offset) element.drawer.Draw(element.core, foreground, offset)
} }

View File

@ -226,9 +226,9 @@ func (element *Container) redoAll () {
} }
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternBackground, theme.PatternBackground,
theme.PatternState { }) theme.State { })
artist.FillRectangleShatter ( 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 {
@ -311,9 +311,11 @@ func (element *Container) HandleKeyUp (key input.Key, modifiers input.Modifiers)
} }
func (element *Container) FlexibleHeightFor (width int) (height int) { func (element *Container) FlexibleHeightFor (width int) (height int) {
margin := element.theme.Margin(theme.PatternBackground)
// TODO: have layouts take in x and y margins
return element.layout.FlexibleHeightFor ( return element.layout.FlexibleHeightFor (
element.children, element.children,
element.config.Margin(), width) margin.X, width)
} }
func (element *Container) OnFlexibleHeightChange (callback func ()) { func (element *Container) OnFlexibleHeightChange (callback func ()) {
@ -515,16 +517,20 @@ func (element *Container) childFocusRequestCallback (
} }
func (element *Container) updateMinimumSize () { func (element *Container) updateMinimumSize () {
width, height := element.layout.MinimumSize ( margin := element.theme.Margin(theme.PatternBackground)
element.children, element.config.Margin()) // TODO: have layouts take in x and y margins
width, height := element.layout.MinimumSize(element.children, margin.X)
if element.flexible { if element.flexible {
height = element.layout.FlexibleHeightFor ( height = element.layout.FlexibleHeightFor (
element.children, element.config.Margin(), width) element.children,
margin.X, width)
} }
element.core.SetMinimumSize(width, height) element.core.SetMinimumSize(width, height)
} }
func (element *Container) doLayout () { func (element *Container) doLayout () {
margin := element.theme.Margin(theme.PatternBackground)
// TODO: have layouts take in x and y margins
element.layout.Arrange ( element.layout.Arrange (
element.children, element.config.Margin(), element.Bounds()) element.children, margin.X, element.Bounds())
} }

View File

@ -1,17 +1,18 @@
package basicElements package basicElements
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
import "git.tebibyte.media/sashakoshka/tomo/artist/patterns"
type Image struct { type Image struct {
*core.Core *core.Core
core core.CoreControl core core.CoreControl
buffer artist.Pattern buffer canvas.Canvas
} }
func NewImage (image image.Image) (element *Image) { func NewImage (image image.Image) (element *Image) {
element = &Image { buffer: artist.NewTexture(image) } element = &Image { buffer: canvas.FromImage(image) }
element.Core, element.core = core.NewCore(element.draw) element.Core, element.core = core.NewCore(element.draw)
bounds := image.Bounds() bounds := image.Bounds()
element.core.SetMinimumSize(bounds.Dx(), bounds.Dy()) element.core.SetMinimumSize(bounds.Dx(), bounds.Dy())
@ -19,5 +20,6 @@ func NewImage (image image.Image) (element *Image) {
} }
func (element *Image) draw () { func (element *Image) draw () {
artist.FillRectangle(element.core, element.buffer, element.Bounds()) (patterns.Texture { Canvas: element.buffer }).
Draw(element.core, element.Bounds())
} }

View File

@ -2,7 +2,6 @@ package basicElements
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"
@ -137,7 +136,9 @@ func (element *Label) SetConfig (new config.Config) {
func (element *Label) updateMinimumSize () { func (element *Label) updateMinimumSize () {
if element.wrap { if element.wrap {
em := element.drawer.Em().Round() em := element.drawer.Em().Round()
if em < 1 { em = element.config.Padding() } if em < 1 {
em = element.theme.Padding(theme.PatternBackground)[0]
}
element.core.SetMinimumSize ( element.core.SetMinimumSize (
em, element.drawer.LineHeight().Round()) em, element.drawer.LineHeight().Round())
if element.onFlexibleHeightChange != nil { if element.onFlexibleHeightChange != nil {
@ -154,13 +155,13 @@ func (element *Label) draw () {
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternBackground, theme.PatternBackground,
theme.PatternState { }) theme.State { })
artist.FillRectangle(element.core, pattern, bounds) pattern.Draw(element.core, bounds)
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
foreground := element.theme.Pattern ( foreground := element.theme.Color (
theme.PatternForeground, theme.ColorForeground,
theme.PatternState { }) theme.State { })
element.drawer.Draw(element.core, foreground, bounds.Min.Sub(textBounds.Min)) element.drawer.Draw(element.core, foreground, bounds.Min.Sub(textBounds.Min))
} }

View File

@ -221,8 +221,8 @@ func (element *List) ScrollAxes () (horizontal, vertical bool) {
} }
func (element *List) scrollViewportHeight () (height int) { func (element *List) scrollViewportHeight () (height int) {
inset := element.theme.Inset(theme.PatternSunken) padding := element.theme.Padding(theme.PatternSunken)
return element.Bounds().Dy() - inset[0] - inset[2] return element.Bounds().Dy() - padding[0] - padding[2]
} }
func (element *List) maxScrollHeight () (height int) { func (element *List) maxScrollHeight () (height int) {
@ -355,8 +355,8 @@ func (element *List) Select (index int) {
} }
func (element *List) selectUnderMouse (x, y int) (updated bool) { func (element *List) selectUnderMouse (x, y int) (updated bool) {
inset := element.theme.Inset(theme.PatternSunken) padding := element.theme.Padding(theme.PatternSunken)
bounds := inset.Apply(element.Bounds()) bounds := padding.Apply(element.Bounds())
mousePoint := image.Pt(x, y) mousePoint := image.Pt(x, y)
dot := image.Pt ( dot := image.Pt (
bounds.Min.X, bounds.Min.X,
@ -398,8 +398,8 @@ func (element *List) changeSelectionBy (delta int) (updated bool) {
func (element *List) resizeEntryToFit (entry ListEntry) (resized ListEntry) { func (element *List) resizeEntryToFit (entry ListEntry) (resized ListEntry) {
bounds := element.Bounds() bounds := element.Bounds()
inset := element.theme.Inset(theme.PatternSunken) padding := element.theme.Padding(theme.PatternSunken)
entry.Resize(inset.Apply(bounds).Dx()) entry.Resize(padding.Apply(bounds).Dx())
return entry return entry
} }
@ -425,17 +425,17 @@ func (element *List) updateMinimumSize () {
minimumHeight = element.contentHeight minimumHeight = element.contentHeight
} }
inset := element.theme.Inset(theme.PatternSunken) padding := element.theme.Padding(theme.PatternSunken)
minimumHeight += inset[0] + inset[2] minimumHeight += padding[0] + padding[2]
element.core.SetMinimumSize(minimumWidth, minimumHeight) element.core.SetMinimumSize(minimumWidth, minimumHeight)
} }
func (element *List) draw () { func (element *List) draw () {
bounds := element.Bounds() bounds := element.Bounds()
inset := element.theme.Inset(theme.PatternSunken) padding := element.theme.Padding(theme.PatternSunken)
innerBounds := inset.Apply(bounds) innerBounds := padding.Apply(bounds)
state := theme.PatternState { state := theme.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
} }
@ -460,6 +460,6 @@ func (element *List) draw () {
innerBounds.Dx(), element.contentHeight, innerBounds.Dx(), element.contentHeight,
).Add(innerBounds.Min).Intersect(innerBounds) ).Add(innerBounds.Min).Intersect(innerBounds)
pattern := element.theme.Pattern(theme.PatternSunken, state) pattern := element.theme.Pattern(theme.PatternSunken, state)
artist.FillRectangleShatter ( artist.DrawShatter (
element.core, pattern, bounds, covered) element.core, pattern, bounds, covered)
} }

View File

@ -47,8 +47,8 @@ func (entry *ListEntry) SetConfig (new config.Config) {
} }
func (entry *ListEntry) updateBounds () { func (entry *ListEntry) updateBounds () {
inset := entry.theme.Inset(theme.PatternRaised) padding := entry.theme.Padding(theme.PatternRaised)
entry.bounds = inset.Inverse().Apply(entry.drawer.LayoutBounds()) entry.bounds = padding.Inverse().Apply(entry.drawer.LayoutBounds())
entry.bounds = entry.bounds.Sub(entry.bounds.Min) entry.bounds = entry.bounds.Sub(entry.bounds.Min)
entry.minimumWidth = entry.bounds.Dx() entry.minimumWidth = entry.bounds.Dx()
entry.bounds.Max.X = entry.width entry.bounds.Max.X = entry.width
@ -62,23 +62,21 @@ func (entry *ListEntry) Draw (
) ( ) (
updatedRegion image.Rectangle, updatedRegion image.Rectangle,
) { ) {
state := theme.PatternState { state := theme.State {
Focused: focused, Focused: focused,
On: on, On: on,
} }
pattern := entry.theme.Pattern (theme.PatternRaised, state) pattern := entry.theme.Pattern (theme.PatternRaised, state)
inset := entry.theme.Inset(theme.PatternRaised) padding := entry.theme.Padding(theme.PatternRaised)
artist.FillRectangle ( bounds := entry.Bounds().Add(offset)
destination, artist.DrawBounds(destination, pattern, bounds)
pattern,
entry.Bounds().Add(offset))
foreground := entry.theme.Pattern (theme.PatternForeground, state) foreground := entry.theme.Color (theme.ColorForeground, state)
return entry.drawer.Draw ( return entry.drawer.Draw (
destination, destination,
foreground, foreground,
offset.Add(image.Pt(inset[3], inset[0])). offset.Add(image.Pt(padding[3], padding[0])).
Sub(entry.drawer.LayoutBounds().Min)) Sub(entry.drawer.LayoutBounds().Min))
} }

View File

@ -3,7 +3,7 @@ package basicElements
import "image" import "image"
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/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
// ProgressBar displays a visual indication of how far along a task is. // ProgressBar displays a visual indication of how far along a task is.
@ -52,9 +52,10 @@ func (element *ProgressBar) SetConfig (new config.Config) {
} }
func (element (ProgressBar)) updateMinimumSize() { func (element (ProgressBar)) updateMinimumSize() {
padding := element.theme.Padding(theme.PatternSunken)
element.core.SetMinimumSize ( element.core.SetMinimumSize (
element.config.Padding() * 2, padding[3] + padding[1],
element.config.Padding() * 2) padding[0] + padding[2])
} }
func (element *ProgressBar) redo () { func (element *ProgressBar) redo () {
@ -67,18 +68,15 @@ func (element *ProgressBar) redo () {
func (element *ProgressBar) draw () { func (element *ProgressBar) draw () {
bounds := element.Bounds() bounds := element.Bounds()
pattern := element.theme.Pattern ( pattern := element.theme.Pattern(theme.PatternSunken, theme.State { })
theme.PatternSunken, padding := element.theme.Padding(theme.PatternSunken)
theme.PatternState { }) pattern.Draw(element.core, bounds)
inset := element.theme.Inset(theme.PatternSunken) bounds = padding.Apply(bounds)
artist.FillRectangle(element.core, pattern, bounds)
bounds = inset.Apply(bounds)
meterBounds := image.Rect ( meterBounds := image.Rect (
bounds.Min.X, bounds.Min.Y, bounds.Min.X, bounds.Min.Y,
bounds.Min.X + int(float64(bounds.Dx()) * element.progress), bounds.Min.X + int(float64(bounds.Dx()) * element.progress),
bounds.Max.Y) bounds.Max.Y)
accent := element.theme.Pattern ( // TODO: maybe dont use the accent color here...
theme.PatternAccent, accent := element.theme.Color(theme.ColorAccent, theme.State { })
theme.PatternState { }) shapes.FillColorRectangle(element.core, accent, meterBounds)
artist.FillRectangle(element.core, accent, meterBounds)
} }

View File

@ -302,7 +302,7 @@ func (element *ScrollContainer) OnFocusMotionRequest (
} }
func (element *ScrollContainer) childDamageCallback (region canvas.Canvas) { func (element *ScrollContainer) childDamageCallback (region canvas.Canvas) {
element.core.DamageRegion(artist.Paste(element.core, region, image.Point { })) element.core.DamageRegion(region.Bounds())
} }
func (element *ScrollContainer) childFocusRequestCallback () (granted bool) { func (element *ScrollContainer) childFocusRequestCallback () (granted bool) {
@ -352,8 +352,8 @@ func (element *ScrollContainer) recalculate () {
horizontal := &element.horizontal horizontal := &element.horizontal
vertical := &element.vertical vertical := &element.vertical
gutterInsetHorizontal := horizontal.theme.Inset(theme.PatternGutter) gutterInsetHorizontal := horizontal.theme.Padding(theme.PatternGutter)
gutterInsetVertical := vertical.theme.Inset(theme.PatternGutter) gutterInsetVertical := vertical.theme.Padding(theme.PatternGutter)
bounds := element.Bounds() bounds := element.Bounds()
thicknessHorizontal := thicknessHorizontal :=
@ -438,8 +438,8 @@ func (element *ScrollContainer) recalculate () {
func (element *ScrollContainer) draw () { func (element *ScrollContainer) draw () {
deadPattern := element.theme.Pattern ( deadPattern := element.theme.Pattern (
theme.PatternDead, theme.PatternState { }) theme.PatternDead, theme.State { })
artist.FillRectangle ( artist.DrawBounds (
element.core, deadPattern, element.core, deadPattern,
image.Rect ( image.Rect (
element.vertical.gutter.Min.X, element.vertical.gutter.Min.X,
@ -451,27 +451,27 @@ func (element *ScrollContainer) draw () {
} }
func (element *ScrollContainer) drawHorizontalBar () { func (element *ScrollContainer) drawHorizontalBar () {
state := theme.PatternState { state := theme.State {
Disabled: !element.horizontal.enabled, Disabled: !element.horizontal.enabled,
Pressed: element.horizontal.dragging, Pressed: element.horizontal.dragging,
} }
gutterPattern := element.horizontal.theme.Pattern(theme.PatternGutter, state) gutterPattern := element.horizontal.theme.Pattern(theme.PatternGutter, state)
artist.FillRectangle(element.core, gutterPattern, element.horizontal.gutter) artist.DrawBounds(element.core, gutterPattern, element.horizontal.gutter)
handlePattern := element.horizontal.theme.Pattern(theme.PatternHandle, state) handlePattern := element.horizontal.theme.Pattern(theme.PatternHandle, state)
artist.FillRectangle(element.core, handlePattern, element.horizontal.bar) artist.DrawBounds(element.core, handlePattern, element.horizontal.bar)
} }
func (element *ScrollContainer) drawVerticalBar () { func (element *ScrollContainer) drawVerticalBar () {
state := theme.PatternState { state := theme.State {
Disabled: !element.vertical.enabled, Disabled: !element.vertical.enabled,
Pressed: element.vertical.dragging, Pressed: element.vertical.dragging,
} }
gutterPattern := element.vertical.theme.Pattern(theme.PatternGutter, state) gutterPattern := element.vertical.theme.Pattern(theme.PatternGutter, state)
artist.FillRectangle(element.core, gutterPattern, element.vertical.gutter) artist.DrawBounds(element.core, gutterPattern, element.vertical.gutter)
handlePattern := element.vertical.theme.Pattern(theme.PatternHandle, state) handlePattern := element.vertical.theme.Pattern(theme.PatternHandle, state)
artist.FillRectangle(element.core, handlePattern, element.vertical.bar) artist.DrawBounds(element.core, handlePattern, element.vertical.bar)
} }
func (element *ScrollContainer) dragHorizontalBar (mousePosition image.Point) { func (element *ScrollContainer) dragHorizontalBar (mousePosition image.Point) {
@ -493,8 +493,8 @@ func (element *ScrollContainer) dragVerticalBar (mousePosition image.Point) {
} }
func (element *ScrollContainer) updateMinimumSize () { func (element *ScrollContainer) updateMinimumSize () {
gutterInsetHorizontal := element.horizontal.theme.Inset(theme.PatternGutter) gutterInsetHorizontal := element.horizontal.theme.Padding(theme.PatternGutter)
gutterInsetVertical := element.vertical.theme.Inset(theme.PatternGutter) gutterInsetVertical := element.vertical.theme.Padding(theme.PatternGutter)
thicknessHorizontal := thicknessHorizontal :=
element.config.HandleWidth() + element.config.HandleWidth() +

View File

@ -173,7 +173,7 @@ func (element *Slider) redo () {
func (element *Slider) draw () { func (element *Slider) draw () {
bounds := element.Bounds() bounds := element.Bounds()
element.track = element.theme.Inset(theme.PatternGutter).Apply(bounds) element.track = element.theme.Padding(theme.PatternGutter).Apply(bounds)
if element.vertical { if element.vertical {
barSize := element.track.Dx() barSize := element.track.Dx()
element.bar = image.Rect(0, 0, barSize, barSize).Add(bounds.Min) element.bar = image.Rect(0, 0, barSize, barSize).Add(bounds.Min)
@ -190,16 +190,16 @@ func (element *Slider) draw () {
element.bar = element.bar.Add(image.Pt(int(barOffset), 0)) element.bar = element.bar.Add(image.Pt(int(barOffset), 0))
} }
state := theme.PatternState { state := theme.State {
Focused: element.Focused(), Focused: element.Focused(),
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Pressed: element.dragging, Pressed: element.dragging,
} }
artist.FillRectangle ( artist.DrawBounds (
element.core, element.core,
element.theme.Pattern(theme.PatternGutter, state), element.theme.Pattern(theme.PatternGutter, state),
bounds) bounds)
artist.FillRectangle ( artist.DrawBounds (
element.core, element.core,
element.theme.Pattern(theme.PatternHandle, state), element.theme.Pattern(theme.PatternHandle, state),
element.bar) element.bar)

View File

@ -2,7 +2,7 @@ package basicElements
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/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
// Spacer can be used to put space between two elements.. // Spacer can be used to put space between two elements..
@ -61,14 +61,14 @@ func (element *Spacer) draw () {
bounds := element.Bounds() bounds := element.Bounds()
if element.line { if element.line {
pattern := element.theme.Pattern ( color := element.theme.Color (
theme.PatternForeground, theme.ColorForeground,
theme.PatternState { }) theme.State { })
artist.FillRectangle(element.core, pattern, bounds) shapes.FillColorRectangle(element.core, color, bounds)
} else { } else {
pattern := element.theme.Pattern ( pattern := element.theme.Pattern (
theme.PatternBackground, theme.PatternBackground,
theme.PatternState { }) theme.State { })
artist.FillRectangle(element.core, pattern, bounds) pattern.Draw(element.core, bounds)
} }
} }

View File

@ -149,7 +149,7 @@ func (element *Switch) updateMinimumSize () {
} else { } else {
element.core.SetMinimumSize ( element.core.SetMinimumSize (
lineHeight * 2 + lineHeight * 2 +
element.config.Padding() + element.theme.Margin(theme.PatternBackground).X +
textBounds.Dx(), textBounds.Dx(),
lineHeight) lineHeight)
} }
@ -160,14 +160,14 @@ func (element *Switch) draw () {
handleBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min) handleBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min)
gutterBounds := image.Rect(0, 0, bounds.Dy() * 2, bounds.Dy()).Add(bounds.Min) gutterBounds := image.Rect(0, 0, bounds.Dy() * 2, bounds.Dy()).Add(bounds.Min)
state := theme.PatternState { state := theme.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
Pressed: element.pressed, Pressed: element.pressed,
} }
backgroundPattern := element.theme.Pattern ( backgroundPattern := element.theme.Pattern (
theme.PatternBackground, state) theme.PatternBackground, state)
artist.FillRectangle (element.core, backgroundPattern, bounds) backgroundPattern.Draw(element.core, bounds)
if element.checked { if element.checked {
handleBounds.Min.X += bounds.Dy() handleBounds.Min.X += bounds.Dy()
@ -185,21 +185,22 @@ func (element *Switch) draw () {
gutterPattern := element.theme.Pattern ( gutterPattern := element.theme.Pattern (
theme.PatternGutter, state) theme.PatternGutter, state)
artist.FillRectangle(element.core, gutterPattern, gutterBounds) artist.DrawBounds(element.core, gutterPattern, gutterBounds)
handlePattern := element.theme.Pattern ( handlePattern := element.theme.Pattern (
theme.PatternHandle, state) theme.PatternHandle, state)
artist.FillRectangle(element.core, handlePattern, handleBounds) artist.DrawBounds(element.core, handlePattern, handleBounds)
textBounds := element.drawer.LayoutBounds() textBounds := element.drawer.LayoutBounds()
offset := bounds.Min.Add(image.Point { offset := bounds.Min.Add(image.Point {
X: bounds.Dy() * 2 + element.config.Padding(), X: bounds.Dy() * 2 +
element.theme.Margin(theme.PatternBackground).X,
}) })
offset.Y -= textBounds.Min.Y offset.Y -= textBounds.Min.Y
offset.X -= textBounds.Min.X offset.X -= textBounds.Min.X
foreground := element.theme.Pattern ( foreground := element.theme.Color (
theme.PatternForeground, state) theme.ColorForeground, state)
element.drawer.Draw(element.core, foreground, offset) element.drawer.Draw(element.core, foreground, offset)
} }

View File

@ -9,6 +9,7 @@ import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/textdraw" import "git.tebibyte.media/sashakoshka/tomo/textdraw"
import "git.tebibyte.media/sashakoshka/tomo/textmanip" import "git.tebibyte.media/sashakoshka/tomo/textmanip"
import "git.tebibyte.media/sashakoshka/tomo/fixedutil" import "git.tebibyte.media/sashakoshka/tomo/fixedutil"
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
// TextBox is a single-line text input. // TextBox is a single-line text input.
@ -92,9 +93,10 @@ func (element *TextBox) HandleMouseMove (x, y int) {
} }
func (element *TextBox) atPosition (position image.Point) int { func (element *TextBox) atPosition (position image.Point) int {
padding := element.theme.Padding(theme.PatternSunken)
offset := element.Bounds().Min.Add (image.Pt ( offset := element.Bounds().Min.Add (image.Pt (
element.config.Padding() - element.scroll, padding[artist.SideLeft] - element.scroll,
element.config.Padding())) padding[artist.SideTop]))
textBoundsMin := element.valueDrawer.LayoutBounds().Min textBoundsMin := element.valueDrawer.LayoutBounds().Min
return element.valueDrawer.AtPosition ( return element.valueDrawer.AtPosition (
fixedutil.Pt(position.Sub(offset).Add(textBoundsMin))) fixedutil.Pt(position.Sub(offset).Add(textBoundsMin)))
@ -251,7 +253,8 @@ func (element *TextBox) ScrollViewportBounds () (bounds image.Rectangle) {
} }
func (element *TextBox) scrollViewportWidth () (width int) { func (element *TextBox) scrollViewportWidth () (width int) {
return element.Bounds().Inset(element.config.Padding()).Dx() padding := element.theme.Padding(theme.PatternSunken)
return padding.Apply(element.Bounds()).Dx()
} }
// ScrollTo scrolls the viewport to the specified point relative to // ScrollTo scrolls the viewport to the specified point relative to
@ -290,7 +293,8 @@ func (element *TextBox) runOnChange () {
func (element *TextBox) scrollToCursor () { func (element *TextBox) scrollToCursor () {
if !element.core.HasImage() { return } if !element.core.HasImage() { return }
bounds := element.Bounds().Inset(element.config.Padding()) padding := element.theme.Padding(theme.PatternSunken)
bounds := padding.Apply(element.Bounds())
bounds = bounds.Sub(bounds.Min) bounds = bounds.Sub(bounds.Min)
bounds.Max.X -= element.valueDrawer.Em().Round() bounds.Max.X -= element.valueDrawer.Em().Round()
cursorPosition := fixedutil.RoundPt ( cursorPosition := fixedutil.RoundPt (
@ -329,11 +333,11 @@ func (element *TextBox) SetConfig (new config.Config) {
func (element *TextBox) updateMinimumSize () { func (element *TextBox) updateMinimumSize () {
textBounds := element.placeholderDrawer.LayoutBounds() textBounds := element.placeholderDrawer.LayoutBounds()
padding := element.theme.Padding(theme.PatternSunken)
element.core.SetMinimumSize ( element.core.SetMinimumSize (
textBounds.Dx() + padding.Horizontal() + textBounds.Dx(),
element.config.Padding() * 2, padding.Vertical() +
element.placeholderDrawer.LineHeight().Round() + element.placeholderDrawer.LineHeight().Round())
element.config.Padding() * 2)
} }
func (element *TextBox) redo () { func (element *TextBox) redo () {
@ -346,30 +350,29 @@ func (element *TextBox) redo () {
func (element *TextBox) draw () { func (element *TextBox) draw () {
bounds := element.Bounds() bounds := element.Bounds()
state := theme.PatternState { state := theme.State {
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
Focused: element.Focused(), Focused: element.Focused(),
} }
pattern := element.theme.Pattern(theme.PatternSunken, state) pattern := element.theme.Pattern(theme.PatternSunken, state)
inset := element.theme.Inset(theme.PatternSunken) padding := element.theme.Padding(theme.PatternSunken)
innerCanvas := canvas.Cut(element.core, inset.Apply(bounds)) innerCanvas := canvas.Cut(element.core, padding.Apply(bounds))
artist.FillRectangle(element.core, pattern, bounds) pattern.Draw(element.core, bounds)
offset := bounds.Min.Add (image.Point { offset := bounds.Min.Add (image.Point {
X: element.config.Padding() - element.scroll, X: -element.scroll,
Y: element.config.Padding(), Y: 0,
}) })
if element.Focused() && !element.dot.Empty() { if element.Focused() && !element.dot.Empty() {
// draw selection bounds // draw selection bounds
accent := element.theme.Pattern ( accent := element.theme.Color(theme.ColorAccent, state)
theme.PatternAccent, state)
canon := element.dot.Canon() canon := element.dot.Canon()
foff := fixedutil.Pt(offset) foff := fixedutil.Pt(offset)
start := element.valueDrawer.PositionAt(canon.Start).Add(foff) start := element.valueDrawer.PositionAt(canon.Start).Add(foff)
end := element.valueDrawer.PositionAt(canon.End).Add(foff) end := element.valueDrawer.PositionAt(canon.End).Add(foff)
end.Y += element.valueDrawer.LineHeight() end.Y += element.valueDrawer.LineHeight()
artist.FillRectangle ( shapes.FillColorRectangle (
innerCanvas, innerCanvas,
accent, accent,
image.Rectangle { image.Rectangle {
@ -381,9 +384,9 @@ func (element *TextBox) draw () {
if len(element.text) == 0 { if len(element.text) == 0 {
// draw placeholder // draw placeholder
textBounds := element.placeholderDrawer.LayoutBounds() textBounds := element.placeholderDrawer.LayoutBounds()
foreground := element.theme.Pattern ( foreground := element.theme.Color (
theme.PatternForeground, theme.ColorForeground,
theme.PatternState { Disabled: true }) theme.State { Disabled: true })
element.placeholderDrawer.Draw ( element.placeholderDrawer.Draw (
innerCanvas, innerCanvas,
foreground, foreground,
@ -391,8 +394,7 @@ func (element *TextBox) draw () {
} else { } else {
// draw input value // draw input value
textBounds := element.valueDrawer.LayoutBounds() textBounds := element.valueDrawer.LayoutBounds()
foreground := element.theme.Pattern ( foreground := element.theme.Color(theme.ColorForeground, state)
theme.PatternForeground, state)
element.valueDrawer.Draw ( element.valueDrawer.Draw (
innerCanvas, innerCanvas,
foreground, foreground,
@ -401,11 +403,10 @@ func (element *TextBox) draw () {
if element.Focused() && element.dot.Empty() { if element.Focused() && element.dot.Empty() {
// draw cursor // draw cursor
foreground := element.theme.Pattern ( foreground := element.theme.Color(theme.ColorForeground, state)
theme.PatternForeground, state)
cursorPosition := fixedutil.RoundPt ( cursorPosition := fixedutil.RoundPt (
element.valueDrawer.PositionAt(element.dot.End)) element.valueDrawer.PositionAt(element.dot.End))
artist.Line ( shapes.ColorLine (
innerCanvas, innerCanvas,
foreground, 1, foreground, 1,
cursorPosition.Add(offset), cursorPosition.Add(offset),

View File

@ -3,9 +3,10 @@ package fun
import "time" import "time"
import "math" import "math"
import "image" import "image"
import "image/color"
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/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
// AnalogClock can display the time of day in an analog format. // AnalogClock can display the time of day in an analog format.
@ -58,15 +59,15 @@ func (element *AnalogClock) redo () {
func (element *AnalogClock) draw () { func (element *AnalogClock) draw () {
bounds := element.Bounds() bounds := element.Bounds()
state := theme.PatternState { } state := theme.State { }
pattern := element.theme.Pattern(theme.PatternSunken, state) pattern := element.theme.Pattern(theme.PatternSunken, state)
inset := element.theme.Inset(theme.PatternSunken) padding := element.theme.Padding(theme.PatternSunken)
artist.FillRectangle(element.core, pattern, bounds) pattern.Draw(element.core, bounds)
bounds = inset.Apply(bounds) bounds = padding.Apply(bounds)
foreground := element.theme.Pattern(theme.PatternForeground, state) foreground := element.theme.Color(theme.ColorForeground, state)
accent := element.theme.Pattern(theme.PatternAccent, state) accent := element.theme.Color(theme.ColorAccent, state)
for hour := 0; hour < 12; hour ++ { for hour := 0; hour < 12; hour ++ {
element.radialLine ( element.radialLine (
@ -93,7 +94,7 @@ func (element *AnalogClock) FlexibleHeightFor (width int) (height int) {
func (element *AnalogClock) OnFlexibleHeightChange (func ()) { } func (element *AnalogClock) OnFlexibleHeightChange (func ()) { }
func (element *AnalogClock) radialLine ( func (element *AnalogClock) radialLine (
source artist.Pattern, source color.RGBA,
inner float64, inner float64,
outer float64, outer float64,
radian float64, radian float64,
@ -107,5 +108,5 @@ func (element *AnalogClock) radialLine (
max := element.Bounds().Min.Add(image.Pt ( max := element.Bounds().Min.Add(image.Pt (
int(math.Cos(radian) * outer * width + width), int(math.Cos(radian) * outer * width + width),
int(math.Sin(radian) * outer * height + height))) 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 () { func (element *Piano) updateMinimumSize () {
inset := element.theme.Inset(theme.PatternSunken) padding := element.theme.Padding(theme.PatternSunken)
element.core.SetMinimumSize ( element.core.SetMinimumSize (
pianoKeyWidth * 7 * element.countOctaves() + inset[1] + inset[3], pianoKeyWidth * 7 * element.countOctaves() +
64 + inset[0] + inset[2]) padding[1] + padding[3],
64 + padding[0] + padding[2])
} }
func (element *Piano) countOctaves () int { func (element *Piano) countOctaves () int {
@ -247,8 +248,8 @@ func (element *Piano) recalculate () {
element.flatKeys = make([]pianoKey, element.countFlats()) element.flatKeys = make([]pianoKey, element.countFlats())
element.sharpKeys = make([]pianoKey, element.countSharps()) element.sharpKeys = make([]pianoKey, element.countSharps())
inset := element.theme.Inset(theme.PatternPinboard) padding := element.theme.Padding(theme.PatternPinboard)
bounds := inset.Apply(element.Bounds()) bounds := padding.Apply(element.Bounds())
dot := bounds.Min dot := bounds.Min
note := element.low.Note(0) note := element.low.Note(0)
@ -280,7 +281,7 @@ func (element *Piano) recalculate () {
} }
func (element *Piano) draw () { func (element *Piano) draw () {
state := theme.PatternState { state := theme.State {
Focused: element.Focused(), Focused: element.Focused(),
Disabled: !element.Enabled(), Disabled: !element.Enabled(),
} }
@ -303,28 +304,28 @@ func (element *Piano) draw () {
} }
pattern := element.theme.Pattern(theme.PatternPinboard, state) pattern := element.theme.Pattern(theme.PatternPinboard, state)
artist.FillRectangleShatter ( artist.DrawShatter (
element.core, pattern, element.Bounds(), element.contentBounds) element.core, pattern, element.contentBounds)
} }
func (element *Piano) drawFlat ( func (element *Piano) drawFlat (
bounds image.Rectangle, bounds image.Rectangle,
pressed bool, pressed bool,
state theme.PatternState, state theme.State,
) { ) {
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.FillRectangle(element.core, pattern, bounds) artist.DrawBounds(element.core, pattern, bounds)
} }
func (element *Piano) drawSharp ( func (element *Piano) drawSharp (
bounds image.Rectangle, bounds image.Rectangle,
pressed bool, pressed bool,
state theme.PatternState, state theme.State,
) { ) {
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.FillRectangle(element.core, pattern, bounds) artist.DrawBounds(element.core, pattern, bounds)
} }

View File

@ -80,7 +80,7 @@ func (element *Artist) draw () {
tiles := shatter.Shatter(c41.Bounds(), rocks...) tiles := shatter.Shatter(c41.Bounds(), rocks...)
for index, tile := range tiles { for index, tile := range tiles {
artist.DrawBounds ( artist.DrawBounds (
element.core, tile, element.core,
[]artist.Pattern { []artist.Pattern {
patterns.Uhex(0xFF0000FF), patterns.Uhex(0xFF0000FF),
patterns.Uhex(0x00FF00FF), patterns.Uhex(0x00FF00FF),

View File

@ -49,11 +49,11 @@ func (element *Mouse) redo () {
func (element *Mouse) draw () { func (element *Mouse) draw () {
bounds := element.Bounds() bounds := element.Bounds()
pattern := element.theme.Pattern ( accent := element.theme.Color (
theme.PatternAccent, theme.ColorAccent,
theme.PatternState { }, theme.State { },
element.c) element.c)
pattern.Draw(element.core, bounds) shapes.FillColorRectangle(element.core, accent, bounds)
shapes.StrokeColorRectangle ( shapes.StrokeColorRectangle (
element.core, element.core,
artist.Hex(0x000000FF), artist.Hex(0x000000FF),

View File

@ -7,6 +7,7 @@ import "image/color"
import "git.tebibyte.media/sashakoshka/tomo/input" import "git.tebibyte.media/sashakoshka/tomo/input"
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/artist"
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/elements/core" import "git.tebibyte.media/sashakoshka/tomo/elements/core"
type ControlState struct { type ControlState struct {
@ -202,9 +203,9 @@ func (element *Raycaster) drawMinimap () {
if cell > 0 { if cell > 0 {
cellColor = color.RGBA { 0xFF, 0xFF, 0xFF, 0xFF } cellColor = color.RGBA { 0xFF, 0xFF, 0xFF, 0xFF }
} }
artist.FillRectangle ( shapes.FillColorRectangle (
element.core, element.core,
artist.NewUniform(cellColor), cellColor,
cellBounds.Inset(1)) cellBounds.Inset(1))
}} }}
@ -217,18 +218,18 @@ func (element *Raycaster) drawMinimap () {
hitPt := hit.Mul(float64(scale)).Point().Add(bounds.Min) hitPt := hit.Mul(float64(scale)).Point().Add(bounds.Min)
playerBounds := image.Rectangle { playerPt, playerPt }.Inset(scale / -8) playerBounds := image.Rectangle { playerPt, playerPt }.Inset(scale / -8)
artist.FillEllipse ( shapes.FillColorEllipse (
element.core, element.core,
artist.Uhex(0xFFFFFFFF), artist.Hex(0xFFFFFFFF),
playerBounds) playerBounds)
artist.Line ( shapes.ColorLine (
element.core, element.core,
artist.Uhex(0xFFFFFFFF), 1, artist.Hex(0xFFFFFFFF), 1,
playerPt, playerPt,
playerAnglePt) playerAnglePt)
artist.Line ( shapes.ColorLine (
element.core, element.core,
artist.Uhex(0x00FF00FF), 1, artist.Hex(0x00FF00FF), 1,
playerPt, playerPt,
hitPt) hitPt)
} }

View File

@ -1,6 +1,7 @@
package theme package theme
import "image" import "image"
import "image/color"
import "golang.org/x/image/font" import "golang.org/x/image/font"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
@ -32,18 +33,9 @@ func (Default) Icon (string, IconSize, Case) canvas.Image {
// Pattern returns a pattern from the default theme corresponding to the given // Pattern returns a pattern from the default theme corresponding to the given
// pattern ID. // pattern ID.
func (Default) Pattern ( func (Default) Pattern (id Pattern, state State, c Case) artist.Pattern {
pattern Pattern, switch id {
state PatternState, case PatternBackground: return patterns.Uhex(0x000000FF)
c Case,
) artist.Pattern {
switch pattern {
case PatternAccent:
return patterns.Uhex(0xFF8800FF)
case PatternBackground:
return patterns.Uhex(0x000000FF)
case PatternForeground:
return patterns.Uhex(0xFFFFFFFF)
// case PatternDead: // case PatternDead:
// case PatternRaised: // case PatternRaised:
// case PatternSunken: // case PatternSunken:
@ -56,6 +48,14 @@ func (Default) Pattern (
} }
} }
func (Default) Color (id Color, state State, c Case) color.RGBA {
switch id {
case ColorAccent: return artist.Hex(0xFF8800FF)
case ColorForeground: return artist.Hex(0xFFFFFFFF)
default: return artist.Hex(0x888888FF)
}
}
// Padding returns the default padding value for the given pattern. // Padding returns the default padding value for the given pattern.
func (Default) Padding (pattern Pattern, c Case) artist.Inset { func (Default) Padding (pattern Pattern, c Case) artist.Inset {
return artist.Inset { 4, 4, 4, 4} return artist.Inset { 4, 4, 4, 4}

View File

@ -8,7 +8,7 @@ package theme
// specific elements. // specific elements.
type Case struct { Namespace, Element string } type Case struct { Namespace, Element string }
// C can be used as shorthand to generate a case struct as used in PatternState. // C can be used as shorthand to generate a case struct as used in State.
func C (namespace, element string) (c Case) { func C (namespace, element string) (c Case) {
return Case { return Case {
Namespace: namespace, Namespace: namespace,
@ -16,14 +16,14 @@ func C (namespace, element string) (c Case) {
} }
} }
// PatternState lists parameters which can change the appearance of some // State lists parameters which can change the appearance of some patterns and
// patterns. For example, passing a PatternState with Selected set to true may // colors. For example, passing a State with Selected set to true may result in
// result in a pattern that has a colored border within it. // a pattern that has a colored border within it.
type PatternState struct { type State struct {
// On should be set to true if the element that is using this pattern is // On should be set to true if the element that is using this pattern is
// in some sort of "on" state, such as if a checkbox is checked or a // in some sort of selected or "on" state, such as if a checkbox is
// switch is toggled on. This is only necessary if the element in // checked or a switch is toggled on. This is only necessary if the
// question is capable of being toggled. // element in question is capable of being toggled or selected.
On bool On bool
// Focused should be set to true if the element that is using this // Focused should be set to true if the element that is using this

View File

@ -18,17 +18,9 @@ const (
// This allows custom elements to follow themes, even those that do not // This allows custom elements to follow themes, even those that do not
// explicitly support them. // explicitly support them.
type Pattern int; const ( type Pattern int; const (
// PatternAccent is the accent color of the theme. It is safe to assume // PatternBackground is the window background of the theme. It appears
// that this is, by default, a solid color. // in things like containers and behind text.
PatternAccent Pattern = iota PatternBackground Pattern = iota
// PatternBackground is the background color of the theme. It is safe to
// assume that this is, by default, a solid color.
PatternBackground
// PatternForeground is the foreground text color of the theme. It is
// safe to assume that this is, by default, a solid color.
PatternForeground
// PatternDead is a pattern that is displayed on a "dead area" where no // PatternDead is a pattern that is displayed on a "dead area" where no
// controls exist, but there still must be some indication of visual // controls exist, but there still must be some indication of visual
@ -57,6 +49,14 @@ type Pattern int; const (
PatternHandle PatternHandle
) )
type Color int; const (
// ColorAccent is the accent color of the theme.
ColorAccent Color = iota
// ColorForeground is the text/icon color of the theme.
ColorForeground
)
// Hints specifies rendering hints for a particular pattern. Elements can take // Hints specifies rendering hints for a particular pattern. Elements can take
// these into account in order to gain extra performance. // these into account in order to gain extra performance.
type Hints struct { type Hints struct {
@ -80,7 +80,11 @@ type Theme interface {
// Pattern returns an appropriate pattern given a pattern name, case, // Pattern returns an appropriate pattern given a pattern name, case,
// and state. // and state.
Pattern (Pattern, PatternState, Case) artist.Pattern Pattern (Pattern, State, Case) artist.Pattern
// Color returns an appropriate pattern given a color name, case, and
// state.
Color (Color, State, Case) color.RGBA
// Padding returns how much space should be between the bounds of a // Padding returns how much space should be between the bounds of a
// pattern whatever an element draws inside of it. // pattern whatever an element draws inside of it.

View File

@ -1,6 +1,7 @@
package theme package theme
import "image" import "image"
import "image/color"
import "golang.org/x/image/font" import "golang.org/x/image/font"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/canvas"
@ -26,11 +27,17 @@ func (wrapped Wrapped) Icon (name string, size IconSize) canvas.Image {
} }
// Pattern returns an appropriate pattern given a pattern name and state. // Pattern returns an appropriate pattern given a pattern name and state.
func (wrapped Wrapped) Pattern (id Pattern, state PatternState) artist.Pattern { func (wrapped Wrapped) Pattern (id Pattern, state State) artist.Pattern {
real := wrapped.ensure() real := wrapped.ensure()
return real.Pattern(id, state, wrapped.Case) return real.Pattern(id, state, wrapped.Case)
} }
// Color returns an appropriate color given a color name and state.
func (wrapped Wrapped) Color (id Color, state State) color.RGBA {
real := wrapped.ensure()
return real.Color(id, state, wrapped.Case)
}
// Padding returns how much space should be between the bounds of a // Padding returns how much space should be between the bounds of a
// pattern whatever an element draws inside of it. // pattern whatever an element draws inside of it.
func (wrapped Wrapped) Padding (id Pattern) artist.Inset { func (wrapped Wrapped) Padding (id Pattern) artist.Inset {