Use ezprof to profile
This commit is contained in:
parent
f3c1c95a57
commit
305acea285
168
elements/basic/scrollbar.go
Normal file
168
elements/basic/scrollbar.go
Normal file
@ -0,0 +1,168 @@
|
||||
package basicElements
|
||||
|
||||
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/elements/core"
|
||||
|
||||
type ScrollBar struct {
|
||||
*core.Core
|
||||
core core.CoreControl
|
||||
|
||||
vertical bool
|
||||
enabled bool
|
||||
dragging bool
|
||||
dragOffset int
|
||||
track image.Rectangle
|
||||
bar image.Rectangle
|
||||
|
||||
contentBounds image.Rectangle
|
||||
viewportBounds image.Rectangle
|
||||
|
||||
config config.Wrapped
|
||||
theme theme.Wrapped
|
||||
|
||||
onSlide func ()
|
||||
onRelease func ()
|
||||
}
|
||||
|
||||
func NewScrollBar (vertical bool) (element *ScrollBar) {
|
||||
element = &ScrollBar {
|
||||
vertical: vertical,
|
||||
enabled: true,
|
||||
}
|
||||
if vertical {
|
||||
element.theme.Case = theme.C("basic", "scrollBarHorizontal")
|
||||
} else {
|
||||
element.theme.Case = theme.C("basic", "scrollBarVertical")
|
||||
}
|
||||
element.Core, element.core = core.NewCore(element.draw)
|
||||
element.updateMinimumSize()
|
||||
return
|
||||
}
|
||||
|
||||
func (element *ScrollBar) HandleMouseDown (x, y int, button input.Button) {
|
||||
|
||||
}
|
||||
|
||||
func (element *ScrollBar) HandleMouseUp (x, y int, button input.Button) {
|
||||
|
||||
}
|
||||
|
||||
func (element *ScrollBar) HandleMouseMove (x, y int) {
|
||||
|
||||
}
|
||||
|
||||
func (element *ScrollBar) HandleMouseScroll (x, y int, deltaX, deltaY float64) {
|
||||
|
||||
}
|
||||
|
||||
// SetEnabled sets whether or not the scroll bar can be interacted with.
|
||||
func (element *ScrollBar) SetEnabled (enabled bool) {
|
||||
if element.enabled == enabled { return }
|
||||
element.enabled = enabled
|
||||
element.redo()
|
||||
}
|
||||
|
||||
// Enabled returns whether or not the element is enabled.
|
||||
func (element *ScrollBar) Enabled () (enabled bool) {
|
||||
return element.enabled
|
||||
}
|
||||
|
||||
// SetBounds sets the content and viewport bounds of the scroll bar.
|
||||
func (element *ScrollBar) SetBounds (content, viewport image.Rectangle) {
|
||||
element.contentBounds = content
|
||||
element.viewportBounds = viewport
|
||||
element.redo()
|
||||
}
|
||||
|
||||
// SetTheme sets the element's theme.
|
||||
func (element *ScrollBar) SetTheme (new theme.Theme) {
|
||||
if new == element.theme.Theme { return }
|
||||
element.theme.Theme = new
|
||||
element.redo()
|
||||
}
|
||||
|
||||
// SetConfig sets the element's configuration.
|
||||
func (element *ScrollBar) SetConfig (new config.Config) {
|
||||
if new == element.config.Config { return }
|
||||
element.config.Config = new
|
||||
element.updateMinimumSize()
|
||||
element.redo()
|
||||
}
|
||||
|
||||
func (element *ScrollBar) recalculate () {
|
||||
if element.vertical {
|
||||
element.recalculateVertical()
|
||||
} else {
|
||||
element.recalculateHorizontal()
|
||||
}
|
||||
}
|
||||
|
||||
func (element *ScrollBar) recalculateVertical () {
|
||||
bounds := element.Bounds()
|
||||
padding := element.theme.Padding(theme.PatternGutter)
|
||||
element.track = padding.Apply(bounds)
|
||||
|
||||
contentBounds := element.contentBounds
|
||||
viewportBounds := element.viewportBounds
|
||||
if element.Enabled() {
|
||||
element.bar.Min.X = element.track.Min.X
|
||||
element.bar.Max.X = element.track.Max.X
|
||||
|
||||
scale := float64(element.track.Dy()) /
|
||||
float64(contentBounds.Dy())
|
||||
element.bar.Min.Y = int(float64(viewportBounds.Min.Y) * scale)
|
||||
element.bar.Max.Y = int(float64(viewportBounds.Max.Y) * scale)
|
||||
|
||||
element.bar.Min.Y += element.track.Min.Y
|
||||
element.bar.Max.Y += element.track.Min.Y
|
||||
}
|
||||
|
||||
// if the handle is out of bounds, don't display it
|
||||
if element.bar.Dy() >= element.track.Dy() {
|
||||
element.bar = image.Rectangle { }
|
||||
}
|
||||
}
|
||||
|
||||
func (element *ScrollBar) recalculateHorizontal () {
|
||||
|
||||
}
|
||||
|
||||
func (element *ScrollBar) updateMinimumSize () {
|
||||
padding := element.theme.Padding(theme.PatternGutter)
|
||||
if element.vertical {
|
||||
element.core.SetMinimumSize (
|
||||
padding.Horizontal() + element.config.HandleWidth(),
|
||||
padding.Vertical() + element.config.HandleWidth() * 2)
|
||||
} else {
|
||||
element.core.SetMinimumSize (
|
||||
padding.Horizontal() + element.config.HandleWidth() * 2,
|
||||
padding.Vertical() + element.config.HandleWidth())
|
||||
}
|
||||
}
|
||||
|
||||
func (element *ScrollBar) redo () {
|
||||
if element.core.HasImage () {
|
||||
element.draw()
|
||||
element.core.DamageAll()
|
||||
}
|
||||
}
|
||||
|
||||
func (element *ScrollBar) draw () {
|
||||
bounds := element.Bounds()
|
||||
state := theme.State {
|
||||
Disabled: !element.Enabled(),
|
||||
Pressed: element.dragging,
|
||||
}
|
||||
artist.DrawBounds (
|
||||
element.core,
|
||||
element.theme.Pattern(theme.PatternGutter, state),
|
||||
bounds)
|
||||
artist.DrawBounds (
|
||||
element.core,
|
||||
element.theme.Pattern(theme.PatternHandle, state),
|
||||
element.bar)
|
||||
}
|
@ -123,6 +123,9 @@ func (element *Slider) SetValue (value float64) {
|
||||
if element.value == value { return }
|
||||
|
||||
element.value = value
|
||||
if element.onRelease != nil {
|
||||
element.onRelease()
|
||||
}
|
||||
element.redo()
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,7 @@ package main
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/testing"
|
||||
import _ "git.tebibyte.media/sashakoshka/tomo/backends/x"
|
||||
import _ "net/http/pprof"
|
||||
import "net/http"
|
||||
import _ "git.tebibyte.media/sashakoshka/ezprof/hook"
|
||||
|
||||
func main () {
|
||||
tomo.Run(run)
|
||||
@ -15,8 +14,4 @@ func run () {
|
||||
window.SetTitle("Draw Test")
|
||||
window.Adopt(testing.NewArtist())
|
||||
window.OnClose(tomo.Stop)
|
||||
window.Show()
|
||||
go func () {
|
||||
http.ListenAndServe("localhost:9090", nil)
|
||||
} ()
|
||||
}
|
||||
|
@ -3,8 +3,6 @@ package main
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
|
||||
import _ "git.tebibyte.media/sashakoshka/tomo/backends/x"
|
||||
import _ "net/http/pprof"
|
||||
import "net/http"
|
||||
|
||||
func main () {
|
||||
tomo.Run(run)
|
||||
@ -28,9 +26,4 @@ func run () {
|
||||
window.Adopt(button)
|
||||
window.OnClose(tomo.Stop)
|
||||
window.Show()
|
||||
|
||||
// just some stuff for profiling, this is not needed for tomo
|
||||
go func () {
|
||||
http.ListenAndServe("localhost:9090", nil)
|
||||
} ()
|
||||
}
|
||||
|
@ -11,8 +11,6 @@ import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/fun/music"
|
||||
import _ "git.tebibyte.media/sashakoshka/tomo/backends/x"
|
||||
import _ "net/http/pprof"
|
||||
import "net/http"
|
||||
|
||||
const sampleRate = 44100
|
||||
const bufferSize = 256
|
||||
@ -149,9 +147,6 @@ func run () {
|
||||
piano.Focus()
|
||||
window.OnClose(tomo.Stop)
|
||||
window.Show()
|
||||
go func () {
|
||||
http.ListenAndServe("localhost:9090", nil)
|
||||
} ()
|
||||
}
|
||||
|
||||
type Patch struct {
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module git.tebibyte.media/sashakoshka/tomo
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309011813-4cd4374e3830
|
||||
github.com/faiface/beep v1.1.0
|
||||
github.com/jezek/xgbutil v0.0.0-20210302171758-530099784e66
|
||||
golang.org/x/image v0.3.0
|
||||
|
2
go.sum
2
go.sum
@ -1,3 +1,5 @@
|
||||
git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309011813-4cd4374e3830 h1:McIAkTzD4y0tS7YprTOwRu8a8NTsMKtomQnvxnCdOmg=
|
||||
git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309011813-4cd4374e3830/go.mod h1:cpXX8SAUDEvZX5m7scoyruavUhEqQ1SByfWzPFHkTbg=
|
||||
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJXZHsaM8b6OLVo6muQUQd4CwkH/D3fnnbHXA=
|
||||
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
|
||||
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g=
|
||||
|
Reference in New Issue
Block a user