From 912a3f9f66cbe2a44ffd8f23f9a7332243f37a52 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 4 Mar 2023 16:18:43 -0500 Subject: [PATCH] oops lmao --- elements/basic/button.go | 78 +++++++++++++++------------------------- theme/default.go | 8 +++++ theme/theme.go | 5 +++ theme/wrapped.go | 7 ++++ 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/elements/basic/button.go b/elements/basic/button.go index e11a827..3b5cf9b 100644 --- a/elements/basic/button.go +++ b/elements/basic/button.go @@ -5,8 +5,8 @@ import "image" import "git.tebibyte.media/sashakoshka/tomo/input" 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/shatter" +// 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/elements/core" @@ -33,9 +33,7 @@ func NewButton (text string) (element *Button) { element.theme.Case = theme.C("basic", "button") element.Core, element.core = core.NewCore(element.drawAll) element.FocusableCore, - element.focusableControl = core.NewFocusableCore (func () { - element.drawAndPush(true) - }) + element.focusableControl = core.NewFocusableCore(element.drawAndPush) element.SetText(text) return } @@ -45,7 +43,7 @@ func (element *Button) HandleMouseDown (x, y int, button input.Button) { if !element.Focused() { element.Focus() } if button != input.ButtonLeft { return } element.pressed = true - element.drawAndPush(true) + element.drawAndPush() } func (element *Button) HandleMouseUp (x, y int, button input.Button) { @@ -56,7 +54,7 @@ func (element *Button) HandleMouseUp (x, y int, button input.Button) { if element.Enabled() && within && element.onClick != nil { element.onClick() } - element.drawAndPush(true) + element.drawAndPush() } func (element *Button) HandleMouseMove (x, y int) { } @@ -66,14 +64,14 @@ func (element *Button) HandleKeyDown (key input.Key, modifiers input.Modifiers) if !element.Enabled() { return } if key == input.KeyEnter { element.pressed = true - element.drawAndPush(true) + element.drawAndPush() } } func (element *Button) HandleKeyUp(key input.Key, modifiers input.Modifiers) { if key == input.KeyEnter && element.pressed { element.pressed = false - element.drawAndPush(true) + element.drawAndPush() if !element.Enabled() { return } if element.onClick != nil { element.onClick() @@ -98,7 +96,7 @@ func (element *Button) SetText (text string) { element.text = text element.drawer.SetText([]rune(text)) element.updateMinimumSize() - element.drawAndPush(false) + element.drawAndPush() } // SetTheme sets the element's theme. @@ -109,7 +107,7 @@ func (element *Button) SetTheme (new theme.Theme) { theme.FontStyleRegular, theme.FontSizeNormal)) element.updateMinimumSize() - element.drawAndPush(false) + element.drawAndPush() } // SetConfig sets the element's configuration. @@ -117,7 +115,7 @@ func (element *Button) SetConfig (new config.Config) { if new == element.config.Config { return } element.config.Config = new element.updateMinimumSize() - element.drawAndPush(false) + element.drawAndPush() } func (element *Button) updateMinimumSize () { @@ -127,19 +125,6 @@ func (element *Button) updateMinimumSize () { element.core.SetMinimumSize(minimumSize.Dx(), minimumSize.Dy()) } -func (element *Button) drawAndPush (partial bool) { - if element.core.HasImage () { - if partial { - element.core.DamageRegion (append ( - element.drawBackground(true), - element.drawText(true))...) - } else { - element.drawAll() - element.core.DamageAll() - } - } -} - func (element *Button) state () theme.State { return theme.State { Disabled: !element.Enabled(), @@ -148,23 +133,28 @@ func (element *Button) state () theme.State { } } -func (element *Button) drawBackground (partial bool) []image.Rectangle { - state := element.state() - bounds := element.Bounds() - pattern := element.theme.Pattern(theme.PatternButton, state) - static := element.theme.Hints(theme.PatternButton).StaticInset - - if partial && static != (artist.Inset { }) { - tiles := shatter.Shatter(bounds, static.Apply(bounds)) - artist.Draw(element.core, pattern, tiles...) - return tiles - } else { - pattern.Draw(element.core, bounds) - return []image.Rectangle { bounds } +func (element *Button) drawAndPush () { + if element.core.HasImage () { + element.drawAll() + element.core.DamageAll() } } -func (element *Button) drawText (partial bool) image.Rectangle { +func (element *Button) drawAll () { + element.drawBackground() + element.drawText() +} + +func (element *Button) drawBackground () []image.Rectangle { + state := element.state() + bounds := element.Bounds() + pattern := element.theme.Pattern(theme.PatternButton, state) + + pattern.Draw(element.core, bounds) + return []image.Rectangle { bounds } +} + +func (element *Button) drawText () image.Rectangle { state := element.state() bounds := element.Bounds() foreground := element.theme.Color(theme.ColorForeground, state) @@ -182,17 +172,7 @@ func (element *Button) drawText (partial bool) image.Rectangle { if element.pressed { offset = offset.Add(sink) } - - if partial { - pattern := element.theme.Pattern(theme.PatternButton, state) - pattern.Draw(element.core, region) - } element.drawer.Draw(element.core, foreground, offset) return region } - -func (element *Button) drawAll () { - element.drawBackground(false) - element.drawText(false) -} diff --git a/theme/default.go b/theme/default.go index 061db58..7233cc5 100644 --- a/theme/default.go +++ b/theme/default.go @@ -6,6 +6,7 @@ import _ "embed" import _ "image/png" import "image/color" import "golang.org/x/image/font" +import "git.tebibyte.media/sashakoshka/tomo/data" import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/defaultfont" @@ -88,6 +89,13 @@ func (Default) Icon (string, IconSize, Case) canvas.Image { return nil } +// MimeIcon returns an icon from the default set corresponding to the given mime. +// type. +func (Default) MimeIcon (data.Mime, IconSize, Case) canvas.Image { + // TODO + return nil +} + // Pattern returns a pattern from the default theme corresponding to the given // pattern ID. func (Default) Pattern (id Pattern, state State, c Case) artist.Pattern { diff --git a/theme/theme.go b/theme/theme.go index 840c599..85437b8 100644 --- a/theme/theme.go +++ b/theme/theme.go @@ -3,6 +3,7 @@ package theme import "image" import "image/color" import "golang.org/x/image/font" +import "git.tebibyte.media/sashakoshka/tomo/data" import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/canvas" @@ -83,6 +84,10 @@ type Theme interface { // Icon returns an appropriate icon given an icon name, size, and case. Icon (string, IconSize, Case) canvas.Image + + // Icon returns an appropriate icon given a file mime type, size, and, + // case. + MimeIcon (data.Mime, IconSize, Case) canvas.Image // Pattern returns an appropriate pattern given a pattern name, case, // and state. diff --git a/theme/wrapped.go b/theme/wrapped.go index 731c6fc..200a5e2 100644 --- a/theme/wrapped.go +++ b/theme/wrapped.go @@ -3,6 +3,7 @@ package theme import "image" import "image/color" import "golang.org/x/image/font" +import "git.tebibyte.media/sashakoshka/tomo/data" import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/canvas" @@ -26,6 +27,12 @@ func (wrapped Wrapped) Icon (name string, size IconSize) canvas.Image { return real.Icon(name, size, wrapped.Case) } +// MimeIcon returns an appropriate icon given file mime type. +func (wrapped Wrapped) MimeIcon (mime data.Mime, size IconSize) canvas.Image { + real := wrapped.ensure() + return real.MimeIcon(mime, size, wrapped.Case) +} + // Pattern returns an appropriate pattern given a pattern name and state. func (wrapped Wrapped) Pattern (id Pattern, state State) artist.Pattern { real := wrapped.ensure()