Compare commits

..

No commits in common. "d9d758b5fc4a4cb4861c2a433282f98173a2f8f8" and "8b79fec1bd93149975d7cf3279b87c95ac7d4b8d" have entirely different histories.

2 changed files with 31 additions and 52 deletions

View File

@ -2,23 +2,16 @@ package objects
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
var _ tomo.Object = new(Separator)
// Separator is a line for visually separating elements. // Separator is a line for visually separating elements.
type Separator struct { type Separator struct {
box tomo.Box tomo.Box
} }
// NewSeparator creates a new separator line. // NewSeparator creates a new separator line.
func NewSeparator () *Separator { func NewSeparator () *Separator {
this := &Separator { this := &Separator {
box: tomo.NewBox(), Box: tomo.NewBox(),
} }
this.box.SetRole(tomo.R("objects", "Separator")) this.SetRole(tomo.R("objects", "Separator"))
return this return this
} }
// GetBox returns the underlying box.
func (this *Separator) GetBox () tomo.Box {
return this.box
}

View File

@ -6,11 +6,9 @@ import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/input" import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/event" import "git.tebibyte.media/tomo/tomo/event"
var _ tomo.Object = new(Slider)
// Slider is a control that selects a numeric value between 0 and 1. // Slider is a control that selects a numeric value between 0 and 1.
type Slider struct { type Slider struct {
box tomo.ContainerBox tomo.ContainerBox
handle *sliderHandle handle *sliderHandle
layout sliderLayout layout sliderLayout
dragging bool dragging bool
@ -28,8 +26,8 @@ type sliderHandle struct {
} }
func newSlider (orient string, value float64) *Slider { func newSlider (orient string, value float64) *Slider {
slider := &Slider { this := &Slider {
box: tomo.NewContainerBox(), ContainerBox: tomo.NewContainerBox(),
handle: &sliderHandle { handle: &sliderHandle {
Box: tomo.NewBox(), Box: tomo.NewBox(),
}, },
@ -40,23 +38,23 @@ func newSlider (orient string, value float64) *Slider {
step: 0.05, step: 0.05,
} }
slider.handle.SetRole(tomo.R("objects", "SliderHandle")) this.Add(this.handle)
slider.handle.SetTag(orient, true) this.SetFocusable(true)
slider.box.SetRole(tomo.R("objects", "Slider")) this.SetValue(value)
slider.box.SetTag(orient, true)
slider.box.Add(slider.handle) this.SetInputMask(true)
slider.box.SetFocusable(true) this.OnKeyUp(this.handleKeyUp)
slider.SetValue(value) this.OnKeyDown(this.handleKeyDown)
this.OnButtonDown(this.handleButtonDown)
this.OnButtonUp(this.handleButtonUp)
this.OnMouseMove(this.handleMouseMove)
this.OnScroll(this.handleScroll)
slider.box.SetInputMask(true) this.handle.SetRole(tomo.R("objects", "SliderHandle"))
slider.box.OnKeyUp(slider.handleKeyUp) this.handle.SetTag(orient, true)
slider.box.OnKeyDown(slider.handleKeyDown) this.SetRole(tomo.R("objects", "Slider"))
slider.box.OnButtonDown(slider.handleButtonDown) this.SetTag(orient, true)
slider.box.OnButtonUp(slider.handleButtonUp) return this
slider.box.OnMouseMove(slider.handleMouseMove)
slider.box.OnScroll(slider.handleScroll)
return slider
} }
// NewVerticalSlider creates a new vertical slider with the specified value. // NewVerticalSlider creates a new vertical slider with the specified value.
@ -69,25 +67,13 @@ func NewHorizontalSlider (value float64) *Slider {
return newSlider("horizontal", value) return newSlider("horizontal", value)
} }
// GetBox returns the underlying box.
func (this *Slider) GetBox () tomo.Box {
return this.box
}
// SetFocused sets whether or not this slider has keyboard focus. If set to
// true, this method will steal focus away from whichever object currently has
// focus.
func (this *Slider) SetFocused (focused bool) {
this.box.SetFocused(focused)
}
// SetValue sets the value of the slider between 0 and 1. // SetValue sets the value of the slider between 0 and 1.
func (this *Slider) SetValue (value float64) { func (this *Slider) SetValue (value float64) {
if value < 0 { value = 0 } if value < 0 { value = 0 }
if value > 1 { value = 1 } if value > 1 { value = 1 }
if value == this.layout.value { return } if value == this.layout.value { return }
this.layout.value = value this.layout.value = value
this.box.SetAttr(tomo.ALayout(this.layout)) this.SetAttr(tomo.ALayout(this.layout))
} }
// Value returns the value of the slider between 0 and 1. // Value returns the value of the slider between 0 and 1.
@ -116,7 +102,7 @@ func (this *Slider) handleKeyDown (key input.Key, numpad bool) bool {
switch key { switch key {
case input.KeyUp, input.KeyLeft: case input.KeyUp, input.KeyLeft:
if this.box.Window().Modifiers().Alt { if this.Window().Modifiers().Alt {
this.SetValue(0) this.SetValue(0)
} else { } else {
this.SetValue(this.Value() - increment) this.SetValue(this.Value() - increment)
@ -124,7 +110,7 @@ func (this *Slider) handleKeyDown (key input.Key, numpad bool) bool {
this.on.valueChange.Broadcast() this.on.valueChange.Broadcast()
return true return true
case input.KeyDown, input.KeyRight: case input.KeyDown, input.KeyRight:
if this.box.Window().Modifiers().Alt { if this.Window().Modifiers().Alt {
this.SetValue(1) this.SetValue(1)
} else { } else {
this.SetValue(this.Value() + increment) this.SetValue(this.Value() + increment)
@ -154,7 +140,7 @@ func (this *Slider) handleKeyUp (key input.Key, numpad bool) bool {
} }
func (this *Slider) handleButtonDown (button input.Button) bool { func (this *Slider) handleButtonDown (button input.Button) bool {
pointer := this.box.Window().MousePosition() pointer := this.Window().MousePosition()
handle := this.handle.Bounds() handle := this.handle.Bounds()
within := pointer.In(handle) within := pointer.In(handle)
@ -170,7 +156,7 @@ func (this *Slider) handleButtonDown (button input.Button) bool {
this.dragging = true this.dragging = true
this.dragOffset = this.dragOffset =
pointer.Sub(this.handle.Bounds().Min). pointer.Sub(this.handle.Bounds().Min).
Add(this.box.InnerBounds().Min) Add(this.InnerBounds().Min)
this.drag() this.drag()
} else { } else {
this.dragOffset = this.fallbackDragOffset() this.dragOffset = this.fallbackDragOffset()
@ -223,8 +209,8 @@ func (this *Slider) handleScroll (x, y float64) bool {
} }
func (this *Slider) drag () { func (this *Slider) drag () {
pointer := this.box.Window().MousePosition().Sub(this.dragOffset) pointer := this.Window().MousePosition().Sub(this.dragOffset)
gutter := this.box.InnerBounds() gutter := this.InnerBounds()
handle := this.handle.Bounds() handle := this.handle.Bounds()
if this.layout.vertical { if this.layout.vertical {
@ -242,10 +228,10 @@ func (this *Slider) drag () {
func (this *Slider) fallbackDragOffset () image.Point { func (this *Slider) fallbackDragOffset () image.Point {
if this.layout.vertical { if this.layout.vertical {
return this.box.InnerBounds().Min. return this.InnerBounds().Min.
Add(image.Pt(0, this.handle.Bounds().Dy() / 2)) Add(image.Pt(0, this.handle.Bounds().Dy() / 2))
} else { } else {
return this.box.InnerBounds().Min. return this.InnerBounds().Min.
Add(image.Pt(this.handle.Bounds().Dx() / 2, 0)) Add(image.Pt(this.handle.Bounds().Dx() / 2, 0))
} }
} }