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
|
max T
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLerpSlider creates a new LerpSlider with a minimum and maximum value.
|
// NewVLerpSlider creates a new horizontal LerpSlider with a minimum and maximum
|
||||||
func NewLerpSlider[T Numeric] (
|
// value.
|
||||||
min, max T, value T,
|
func NewVLerpSlider[T Numeric] (min, max T, value T) (element *LerpSlider[T]) {
|
||||||
orientation Orientation,
|
element = NewHLerpSlider(min, max, value)
|
||||||
) (
|
element.vertical = true
|
||||||
element *LerpSlider[T],
|
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 }
|
if min > max { min, max = max, min }
|
||||||
element = &LerpSlider[T] {
|
element = &LerpSlider[T] {
|
||||||
min: min,
|
min: min,
|
||||||
max: max,
|
max: max,
|
||||||
}
|
}
|
||||||
element.vertical = bool(orientation)
|
|
||||||
element.entity = tomo.NewEntity(element).(tomo.FocusableEntity)
|
element.entity = tomo.NewEntity(element).(tomo.FocusableEntity)
|
||||||
element.construct()
|
element.construct()
|
||||||
element.SetValue(value)
|
element.SetValue(value)
|
||||||
|
@ -37,7 +37,7 @@ func NewScroll (mode ScrollMode, child tomo.Scrollable) (element *Scroll) {
|
|||||||
element.entity = tomo.NewEntity(element).(tomo.ContainerEntity)
|
element.entity = tomo.NewEntity(element).(tomo.ContainerEntity)
|
||||||
|
|
||||||
if mode.Includes(ScrollHorizontal) {
|
if mode.Includes(ScrollHorizontal) {
|
||||||
element.horizontal = NewScrollBar(false)
|
element.horizontal = NewHScrollBar()
|
||||||
element.horizontal.OnScroll (func (viewport image.Point) {
|
element.horizontal.OnScroll (func (viewport image.Point) {
|
||||||
if element.child != nil {
|
if element.child != nil {
|
||||||
element.child.ScrollTo(viewport)
|
element.child.ScrollTo(viewport)
|
||||||
@ -51,7 +51,7 @@ func NewScroll (mode ScrollMode, child tomo.Scrollable) (element *Scroll) {
|
|||||||
element.entity.Adopt(element.horizontal)
|
element.entity.Adopt(element.horizontal)
|
||||||
}
|
}
|
||||||
if mode.Includes(ScrollVertical) {
|
if mode.Includes(ScrollVertical) {
|
||||||
element.vertical = NewScrollBar(true)
|
element.vertical = NewVScrollBar()
|
||||||
element.vertical.OnScroll (func (viewport image.Point) {
|
element.vertical.OnScroll (func (viewport image.Point) {
|
||||||
if element.child != nil {
|
if element.child != nil {
|
||||||
element.child.ScrollTo(viewport)
|
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/theme"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
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
|
// 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
|
// 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
|
// 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
|
// Typically, you wont't want to use a ScrollBar by itself. A ScrollContainer is
|
||||||
// better for most cases.
|
// better for most cases.
|
||||||
type ScrollBar struct {
|
type ScrollBar struct {
|
||||||
entity tomo.ContainerEntity
|
entity tomo.Entity
|
||||||
|
|
||||||
vertical bool
|
vertical bool
|
||||||
enabled bool
|
enabled bool
|
||||||
@ -44,18 +37,24 @@ type ScrollBar struct {
|
|||||||
onScroll func (viewport image.Point)
|
onScroll func (viewport image.Point)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewScrollBar creates a new scroll bar.
|
func NewVScrollBar () (element *ScrollBar) {
|
||||||
func NewScrollBar (orientation Orientation) (element *ScrollBar) {
|
|
||||||
element = &ScrollBar {
|
element = &ScrollBar {
|
||||||
vertical: bool(orientation),
|
vertical: true,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
}
|
}
|
||||||
if orientation == Vertical {
|
element.theme.Case = tomo.C("tomo", "scrollBarVertical")
|
||||||
element.theme.Case = tomo.C("tomo", "scrollBarHorizontal")
|
element.entity = tomo.NewEntity(element).(tomo.Entity)
|
||||||
} else {
|
element.updateMinimumSize()
|
||||||
element.theme.Case = tomo.C("tomo", "scrollBarVertical")
|
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()
|
element.updateMinimumSize()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,17 @@ type Slider struct {
|
|||||||
slider
|
slider
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSlider creates a new slider with the specified value.
|
// NewVSlider creates a new horizontal slider with the specified value.
|
||||||
func NewSlider (value float64, orientation Orientation) (element *Slider) {
|
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 = &Slider { }
|
||||||
element.value = value
|
element.value = value
|
||||||
element.vertical = bool(orientation)
|
|
||||||
element.entity = tomo.NewEntity(element).(tomo.FocusableEntity)
|
element.entity = tomo.NewEntity(element).(tomo.FocusableEntity)
|
||||||
element.construct()
|
element.construct()
|
||||||
return
|
return
|
||||||
|
@ -46,7 +46,7 @@ func run () {
|
|||||||
elements.ScrollHorizontal,
|
elements.ScrollHorizontal,
|
||||||
elements.NewTextBox("", "I bet you weren't expecting this!"))))
|
elements.NewTextBox("", "I bet you weren't expecting this!"))))
|
||||||
list.Collapse(0, 32)
|
list.Collapse(0, 32)
|
||||||
scrollBar := elements.NewScrollBar(true)
|
scrollBar := elements.NewVScrollBar()
|
||||||
list.OnScrollBoundsChange (func () {
|
list.OnScrollBoundsChange (func () {
|
||||||
scrollBar.SetBounds (
|
scrollBar.SetBounds (
|
||||||
list.ScrollContentBounds(),
|
list.ScrollContentBounds(),
|
||||||
|
Reference in New Issue
Block a user