3 Commits

Author SHA1 Message Date
9cba0151ce Add godoc badge to readme 2023-09-04 02:49:24 -04:00
d8d24632bb Upgraded tomo version + added an Icon object 2023-09-04 02:32:04 -04:00
05b6490095 Fixed vertical slider 2023-08-25 00:09:34 -04:00
6 changed files with 67 additions and 12 deletions

View File

@@ -1,4 +1,6 @@
# objects
[![Go Reference](https://pkg.go.dev/badge/pkg.go.dev/git.tebibyte.media/tomo/objects.svg)](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
module visually conform to whatever the theme is set to.

2
go.mod
View File

@@ -2,6 +2,6 @@ module git.tebibyte.media/tomo/objects
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

4
go.sum
View File

@@ -1,5 +1,5 @@
git.tebibyte.media/tomo/tomo v0.26.1 h1:V5ciRuixMYb79aAawgquFEfJ1icyEmMKBKFPWwi94NE=
git.tebibyte.media/tomo/tomo v0.26.1/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
git.tebibyte.media/tomo/tomo v0.27.0 h1:gCwxQe0qm1hZLfHkMI3OccNMC/lB1cfs4BbaMz/bXug=
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=
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=

47
icon.go Normal file
View 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))
}

View File

@@ -16,4 +16,3 @@ func NewSeparator () *Separator {
theme.Apply(this, theme.R("objects", "Separator", ""))
return this
}

View File

@@ -14,7 +14,7 @@ type Slider struct {
layout sliderLayout
dragging bool
dragOffset image.Point
on struct {
valueChange event.FuncBroadcaster
}
@@ -34,7 +34,7 @@ func newSlider (orient string, value float64) *Slider {
vertical: orient == "vertical",
},
}
this.Add(this.handle)
this.SetFocusable(true)
this.SetPropagateEvents(false)
@@ -74,18 +74,24 @@ func (this *Slider) OnValueChange (callback func ()) event.Cookie {
}
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 {
case input.KeyUp, input.KeyLeft:
if this.Modifiers().Alt {
this.SetValue(0)
} else {
this.SetValue(this.Value() - 0.05)
this.SetValue(this.Value() - increment)
}
case input.KeyDown, input.KeyRight:
if this.Modifiers().Alt {
this.SetValue(1)
} else {
this.SetValue(this.Value() + 0.05)
this.SetValue(this.Value() + increment)
}
case input.KeyHome:
this.SetValue(0)
@@ -98,7 +104,7 @@ func (this *Slider) handleMouseDown (button input.Button) {
pointer := this.MousePosition()
handle := this.handle.Bounds()
var above, within bool
if pointer.In(handle) {
within = true
} else if this.layout.vertical {
@@ -106,7 +112,7 @@ func (this *Slider) handleMouseDown (button input.Button) {
} else {
above = pointer.X < handle.Min.X
}
switch button {
case input.ButtonLeft:
if within {
@@ -152,6 +158,7 @@ func (this *Slider) drag () {
if this.layout.vertical {
this.SetValue (
1 -
float64(pointer.Y) /
float64(gutter.Dy() - handle.Dy()))
} else {
@@ -185,10 +192,10 @@ func (this sliderLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
if len(boxes) != 1 { return }
handle := image.Rectangle { Max: boxes[0].MinimumSize() }
gutter := hints.Bounds
if this.vertical {
height := gutter.Dy() - handle.Dy()
offset := int(float64(height) * this.value)
offset := int(float64(height) * (1 - this.value))
handle.Max.X = gutter.Dx()
boxes[0].SetBounds (
handle.