The whole orientation thing was stupid
This commit is contained in:
parent
ff3802ca5e
commit
580b7d2ad0
@ -17,19 +17,22 @@ type LerpSlider[T Numeric] struct {
|
||||
max T
|
||||
}
|
||||
|
||||
// NewLerpSlider creates a new LerpSlider with a minimum and maximum value.
|
||||
func NewLerpSlider[T Numeric] (
|
||||
min, max T, value T,
|
||||
orientation Orientation,
|
||||
) (
|
||||
element *LerpSlider[T],
|
||||
) {
|
||||
// NewVLerpSlider creates a new horizontal LerpSlider with a minimum and maximum
|
||||
// value.
|
||||
func NewVLerpSlider[T Numeric] (min, max T, value T) (element *LerpSlider[T]) {
|
||||
element = NewHLerpSlider(min, max, value)
|
||||
element.vertical = true
|
||||
return
|
||||
}
|
||||
|
||||
// NewHLerpSlider creates a new horizontal LerpSlider with a minimum and maximum
|
||||
// value.
|
||||
func NewHLerpSlider[T Numeric] (min, max T, value T) (element *LerpSlider[T]) {
|
||||
if min > max { min, max = max, min }
|
||||
element = &LerpSlider[T] {
|
||||
min: min,
|
||||
max: max,
|
||||
}
|
||||
element.vertical = bool(orientation)
|
||||
element.entity = tomo.NewEntity(element).(tomo.FocusableEntity)
|
||||
element.construct()
|
||||
element.SetValue(value)
|
||||
|
@ -37,7 +37,7 @@ func NewScroll (mode ScrollMode, child tomo.Scrollable) (element *Scroll) {
|
||||
element.entity = tomo.NewEntity(element).(tomo.ContainerEntity)
|
||||
|
||||
if mode.Includes(ScrollHorizontal) {
|
||||
element.horizontal = NewScrollBar(false)
|
||||
element.horizontal = NewHScrollBar()
|
||||
element.horizontal.OnScroll (func (viewport image.Point) {
|
||||
if element.child != nil {
|
||||
element.child.ScrollTo(viewport)
|
||||
@ -51,7 +51,7 @@ func NewScroll (mode ScrollMode, child tomo.Scrollable) (element *Scroll) {
|
||||
element.entity.Adopt(element.horizontal)
|
||||
}
|
||||
if mode.Includes(ScrollVertical) {
|
||||
element.vertical = NewScrollBar(true)
|
||||
element.vertical = NewVScrollBar()
|
||||
element.vertical.OnScroll (func (viewport image.Point) {
|
||||
if element.child != nil {
|
||||
element.child.ScrollTo(viewport)
|
||||
|
@ -7,13 +7,6 @@ import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
||||
|
||||
// Orientation represents an orientation configuration that can be passed to
|
||||
// scrollbars and sliders.
|
||||
type Orientation bool; const (
|
||||
Vertical Orientation = true
|
||||
Horizontal = false
|
||||
)
|
||||
|
||||
// ScrollBar is an element similar to Slider, but it has special behavior that
|
||||
// makes it well suited for controlling the viewport position on one axis of a
|
||||
// scrollable element. Instead of having a value from zero to one, it stores
|
||||
@ -26,7 +19,7 @@ type Orientation bool; const (
|
||||
// Typically, you wont't want to use a ScrollBar by itself. A ScrollContainer is
|
||||
// better for most cases.
|
||||
type ScrollBar struct {
|
||||
entity tomo.ContainerEntity
|
||||
entity tomo.Entity
|
||||
|
||||
vertical bool
|
||||
enabled bool
|
||||
@ -44,18 +37,24 @@ type ScrollBar struct {
|
||||
onScroll func (viewport image.Point)
|
||||
}
|
||||
|
||||
// NewScrollBar creates a new scroll bar.
|
||||
func NewScrollBar (orientation Orientation) (element *ScrollBar) {
|
||||
func NewVScrollBar () (element *ScrollBar) {
|
||||
element = &ScrollBar {
|
||||
vertical: bool(orientation),
|
||||
vertical: true,
|
||||
enabled: true,
|
||||
}
|
||||
if orientation == Vertical {
|
||||
element.theme.Case = tomo.C("tomo", "scrollBarHorizontal")
|
||||
} else {
|
||||
element.theme.Case = tomo.C("tomo", "scrollBarVertical")
|
||||
element.theme.Case = tomo.C("tomo", "scrollBarVertical")
|
||||
element.entity = tomo.NewEntity(element).(tomo.Entity)
|
||||
element.updateMinimumSize()
|
||||
return
|
||||
}
|
||||
|
||||
// NewHScrollBar creates a new horizontal scroll bar.
|
||||
func NewHScrollBar () (element *ScrollBar) {
|
||||
element = &ScrollBar {
|
||||
enabled: true,
|
||||
}
|
||||
element.entity = tomo.NewEntity(element).(tomo.ContainerEntity)
|
||||
element.theme.Case = tomo.C("tomo", "scrollBarHorizontal")
|
||||
element.entity = tomo.NewEntity(element).(tomo.Entity)
|
||||
element.updateMinimumSize()
|
||||
return
|
||||
}
|
||||
|
@ -12,11 +12,17 @@ type Slider struct {
|
||||
slider
|
||||
}
|
||||
|
||||
// NewSlider creates a new slider with the specified value.
|
||||
func NewSlider (value float64, orientation Orientation) (element *Slider) {
|
||||
// NewVSlider creates a new horizontal slider with the specified value.
|
||||
func NewVSlider (value float64) (element *Slider) {
|
||||
element = NewHSlider(value)
|
||||
element.vertical = true
|
||||
return
|
||||
}
|
||||
|
||||
// NewHSlider creates a new horizontal slider with the specified value.
|
||||
func NewHSlider (value float64) (element *Slider) {
|
||||
element = &Slider { }
|
||||
element.value = value
|
||||
element.vertical = bool(orientation)
|
||||
element.entity = tomo.NewEntity(element).(tomo.FocusableEntity)
|
||||
element.construct()
|
||||
return
|
||||
|
@ -46,7 +46,7 @@ func run () {
|
||||
elements.ScrollHorizontal,
|
||||
elements.NewTextBox("", "I bet you weren't expecting this!"))))
|
||||
list.Collapse(0, 32)
|
||||
scrollBar := elements.NewScrollBar(true)
|
||||
scrollBar := elements.NewVScrollBar()
|
||||
list.OnScrollBoundsChange (func () {
|
||||
scrollBar.SetBounds (
|
||||
list.ScrollContentBounds(),
|
||||
|
Reference in New Issue
Block a user