Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9cba0151ce | |||
| d8d24632bb | |||
| 05b6490095 |
@@ -1,4 +1,6 @@
|
|||||||
# objects
|
# objects
|
||||||
|
|
||||||
|
[](https://pkg.go.dev/pkg.go.dev/git.tebibyte.media/tomo/objects)
|
||||||
|
|
||||||
Objects contains a standard collection of re-usable objects. All objects in this
|
Objects contains a standard collection of re-usable objects. All objects in this
|
||||||
module visually conform to whatever the theme is set to.
|
module visually conform to whatever the theme is set to.
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -2,6 +2,6 @@ module git.tebibyte.media/tomo/objects
|
|||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require git.tebibyte.media/tomo/tomo v0.26.1
|
require git.tebibyte.media/tomo/tomo v0.27.0
|
||||||
|
|
||||||
require golang.org/x/image v0.11.0 // indirect
|
require golang.org/x/image v0.11.0 // indirect
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,5 +1,5 @@
|
|||||||
git.tebibyte.media/tomo/tomo v0.26.1 h1:V5ciRuixMYb79aAawgquFEfJ1icyEmMKBKFPWwi94NE=
|
git.tebibyte.media/tomo/tomo v0.27.0 h1:gCwxQe0qm1hZLfHkMI3OccNMC/lB1cfs4BbaMz/bXug=
|
||||||
git.tebibyte.media/tomo/tomo v0.26.1/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
|
git.tebibyte.media/tomo/tomo v0.27.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
|||||||
47
icon.go
Normal file
47
icon.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package objects
|
||||||
|
|
||||||
|
import "git.tebibyte.media/tomo/tomo"
|
||||||
|
import "git.tebibyte.media/tomo/tomo/data"
|
||||||
|
import "git.tebibyte.media/tomo/tomo/theme"
|
||||||
|
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||||
|
|
||||||
|
// Icon displays a single icon.
|
||||||
|
type Icon struct {
|
||||||
|
tomo.Box
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewIcon creates a new icon from an icon ID.
|
||||||
|
func NewIcon (id theme.Icon, size theme.IconSize) *Icon {
|
||||||
|
this := &Icon {
|
||||||
|
Box: tomo.NewBox(),
|
||||||
|
}
|
||||||
|
theme.Apply(this, theme.R("objects", "Icon", size.String()))
|
||||||
|
this.SetTexture(id.Texture(size))
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMimeIcon creates a new icon from a MIME type.
|
||||||
|
func NewMimeIcon (mime data.Mime, size theme.IconSize) *Icon {
|
||||||
|
this := &Icon {
|
||||||
|
Box: tomo.NewBox(),
|
||||||
|
}
|
||||||
|
theme.Apply(this, theme.R("objects", "Icon", size.String()))
|
||||||
|
this.SetTexture(theme.MimeIcon(mime, size))
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewApplicationIcon creates a new icon from an application description.
|
||||||
|
func NewApplicationIcon (id theme.ApplicationIcon, size theme.IconSize) *Icon {
|
||||||
|
this := &Icon {
|
||||||
|
Box: tomo.NewBox(),
|
||||||
|
}
|
||||||
|
theme.Apply(this, theme.R("objects", "Icon", size.String()))
|
||||||
|
this.SetTexture(id.Texture(size))
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Icon) SetTexture (texture canvas.Texture) {
|
||||||
|
bounds := texture.Bounds()
|
||||||
|
this.Box.SetTexture(texture)
|
||||||
|
this.SetMinimumSize(bounds.Max.Sub(bounds.Min))
|
||||||
|
}
|
||||||
@@ -16,4 +16,3 @@ func NewSeparator () *Separator {
|
|||||||
theme.Apply(this, theme.R("objects", "Separator", ""))
|
theme.Apply(this, theme.R("objects", "Separator", ""))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
slider.go
13
slider.go
@@ -74,18 +74,24 @@ func (this *Slider) OnValueChange (callback func ()) event.Cookie {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleKeyDown (key input.Key, numpad bool) {
|
func (this *Slider) handleKeyDown (key input.Key, numpad bool) {
|
||||||
|
var increment float64; if this.layout.vertical {
|
||||||
|
increment = -0.05
|
||||||
|
} else {
|
||||||
|
increment = 0.05
|
||||||
|
}
|
||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case input.KeyUp, input.KeyLeft:
|
case input.KeyUp, input.KeyLeft:
|
||||||
if this.Modifiers().Alt {
|
if this.Modifiers().Alt {
|
||||||
this.SetValue(0)
|
this.SetValue(0)
|
||||||
} else {
|
} else {
|
||||||
this.SetValue(this.Value() - 0.05)
|
this.SetValue(this.Value() - increment)
|
||||||
}
|
}
|
||||||
case input.KeyDown, input.KeyRight:
|
case input.KeyDown, input.KeyRight:
|
||||||
if this.Modifiers().Alt {
|
if this.Modifiers().Alt {
|
||||||
this.SetValue(1)
|
this.SetValue(1)
|
||||||
} else {
|
} else {
|
||||||
this.SetValue(this.Value() + 0.05)
|
this.SetValue(this.Value() + increment)
|
||||||
}
|
}
|
||||||
case input.KeyHome:
|
case input.KeyHome:
|
||||||
this.SetValue(0)
|
this.SetValue(0)
|
||||||
@@ -152,6 +158,7 @@ func (this *Slider) drag () {
|
|||||||
|
|
||||||
if this.layout.vertical {
|
if this.layout.vertical {
|
||||||
this.SetValue (
|
this.SetValue (
|
||||||
|
1 -
|
||||||
float64(pointer.Y) /
|
float64(pointer.Y) /
|
||||||
float64(gutter.Dy() - handle.Dy()))
|
float64(gutter.Dy() - handle.Dy()))
|
||||||
} else {
|
} else {
|
||||||
@@ -188,7 +195,7 @@ func (this sliderLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
|
|
||||||
if this.vertical {
|
if this.vertical {
|
||||||
height := gutter.Dy() - handle.Dy()
|
height := gutter.Dy() - handle.Dy()
|
||||||
offset := int(float64(height) * this.value)
|
offset := int(float64(height) * (1 - this.value))
|
||||||
handle.Max.X = gutter.Dx()
|
handle.Max.X = gutter.Dx()
|
||||||
boxes[0].SetBounds (
|
boxes[0].SetBounds (
|
||||||
handle.
|
handle.
|
||||||
|
|||||||
Reference in New Issue
Block a user