Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c7c77d8da | |||
| 8139d871cc | |||
| bb320dfcc9 | |||
| 2ab920eb26 | |||
| d8ae20d739 | |||
| 06561bb671 | |||
| a71d81af48 | |||
| bd9dbb762d |
@@ -6,7 +6,7 @@ import "git.tebibyte.media/tomo/tomo/event"
|
|||||||
import "git.tebibyte.media/tomo/objects/layouts"
|
import "git.tebibyte.media/tomo/objects/layouts"
|
||||||
|
|
||||||
var buttonLayout = layouts.NewGrid([]bool { true }, []bool { true })
|
var buttonLayout = layouts.NewGrid([]bool { true }, []bool { true })
|
||||||
var iconButtonLayout = layouts.NewGrid([]bool { false }, []bool { true })
|
var iconButtonLayout = layouts.NewGrid([]bool { true }, []bool { true })
|
||||||
var bothButtonLayout = layouts.NewGrid([]bool { false, true }, []bool { true })
|
var bothButtonLayout = layouts.NewGrid([]bool { false, true }, []bool { true })
|
||||||
|
|
||||||
// Button is a clickable button.
|
// Button is a clickable button.
|
||||||
@@ -28,7 +28,8 @@ func NewButton (text string) *Button {
|
|||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
label: NewLabel(text),
|
label: NewLabel(text),
|
||||||
}
|
}
|
||||||
tomo.Apply(box, tomo.R("objects", "Button", ""))
|
box.SetRole(tomo.R("objects", "Button", ""))
|
||||||
|
tomo.Apply(box)
|
||||||
box.label.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
|
box.label.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
|
||||||
box.SetLayout(buttonLayout)
|
box.SetLayout(buttonLayout)
|
||||||
box.SetText(text)
|
box.SetText(text)
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ func NewCheckbox (value bool) *Checkbox {
|
|||||||
box := &Checkbox {
|
box := &Checkbox {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
tomo.Apply(box, tomo.R("objects", "Checkbox", ""))
|
box.SetRole(tomo.R("objects", "Checkbox", ""))
|
||||||
|
tomo.Apply(box)
|
||||||
box.SetValue(false)
|
box.SetValue(false)
|
||||||
|
|
||||||
box.OnMouseUp(box.handleMouseUp)
|
box.OnMouseUp(box.handleMouseUp)
|
||||||
@@ -31,10 +32,9 @@ func NewCheckbox (value bool) *Checkbox {
|
|||||||
func (this *Checkbox) SetValue (value bool) {
|
func (this *Checkbox) SetValue (value bool) {
|
||||||
this.value = value
|
this.value = value
|
||||||
if this.value {
|
if this.value {
|
||||||
// FIXME: we need checkbox icons
|
this.SetTextureCenter(tomo.IconCheckboxChecked.Texture(tomo.IconSizeSmall))
|
||||||
this.SetTextureCenter(tomo.Icon("").Texture(tomo.IconSizeSmall))
|
|
||||||
} else {
|
} else {
|
||||||
this.SetTextureCenter(nil)
|
this.SetTextureCenter(tomo.IconCheckboxUnchecked.Texture(tomo.IconSizeSmall))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ func newContainer (layout tomo.Layout, children ...tomo.Object) *Container {
|
|||||||
// window, tab pane, etc.
|
// window, tab pane, etc.
|
||||||
func NewOuterContainer (layout tomo.Layout, children ...tomo.Object) *Container {
|
func NewOuterContainer (layout tomo.Layout, children ...tomo.Object) *Container {
|
||||||
this := newContainer(layout, children...)
|
this := newContainer(layout, children...)
|
||||||
tomo.Apply(this, tomo.R("objects", "Container", "outer"))
|
this.SetRole(tomo.R("objects", "Container", "outer"))
|
||||||
|
tomo.Apply(this)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,14 +36,16 @@ func NewOuterContainer (layout tomo.Layout, children ...tomo.Object) *Container
|
|||||||
// around it. It is meant to be used as a root container for a ScrollContainer.
|
// around it. It is meant to be used as a root container for a ScrollContainer.
|
||||||
func NewSunkenContainer (layout tomo.Layout, children ...tomo.Object) *Container {
|
func NewSunkenContainer (layout tomo.Layout, children ...tomo.Object) *Container {
|
||||||
this := newContainer(layout, children...)
|
this := newContainer(layout, children...)
|
||||||
tomo.Apply(this, tomo.R("objects", "Container", "sunken"))
|
this.SetRole(tomo.R("objects", "Container", "sunken"))
|
||||||
|
tomo.Apply(this)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInnerContainer creates a new container that has no padding around it.
|
// NewInnerContainer creates a new container that has no padding around it.
|
||||||
func NewInnerContainer (layout tomo.Layout, children ...tomo.Object) *Container {
|
func NewInnerContainer (layout tomo.Layout, children ...tomo.Object) *Container {
|
||||||
this := newContainer(layout, children...)
|
this := newContainer(layout, children...)
|
||||||
tomo.Apply(this, tomo.R("objects", "Container", "inner"))
|
this.SetRole(tomo.R("objects", "Container", "inner"))
|
||||||
|
tomo.Apply(this)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,8 +75,7 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
|
|||||||
// NewDialogOk creates a new dialog window with an OK option.
|
// NewDialogOk creates a new dialog window with an OK option.
|
||||||
func NewDialogOk (kind DialogKind, parent tomo.Window, title, message string, onOk func ()) (*Dialog, error) {
|
func NewDialogOk (kind DialogKind, parent tomo.Window, title, message string, onOk func ()) (*Dialog, error) {
|
||||||
okButton := NewButton("OK")
|
okButton := NewButton("OK")
|
||||||
// FIXME: need dialog accept/reject action icons
|
okButton.SetIcon(tomo.IconDialogOkay)
|
||||||
// okButton.SetIcon(tomo.IconStatusOkay)
|
|
||||||
okButton.OnClick(func () {
|
okButton.OnClick(func () {
|
||||||
if onOk != nil { onOk() }
|
if onOk != nil { onOk() }
|
||||||
})
|
})
|
||||||
@@ -88,12 +87,10 @@ func NewDialogOk (kind DialogKind, parent tomo.Window, title, message string, on
|
|||||||
// NewDialogOkCancel creates a new dialog window with OK and Cancel options.
|
// NewDialogOkCancel creates a new dialog window with OK and Cancel options.
|
||||||
func NewDialogOkCancel (kind DialogKind, parent tomo.Window, title, message string, onOk func ()) (*Dialog, error) {
|
func NewDialogOkCancel (kind DialogKind, parent tomo.Window, title, message string, onOk func ()) (*Dialog, error) {
|
||||||
cancelButton := NewButton("Cancel")
|
cancelButton := NewButton("Cancel")
|
||||||
// FIXME: need dialog accept/reject action icons
|
cancelButton.SetIcon(tomo.IconDialogCancel)
|
||||||
// cancelButton.SetIcon(tomo.IconStatusCancel)
|
|
||||||
|
|
||||||
okButton := NewButton("OK")
|
okButton := NewButton("OK")
|
||||||
// FIXME: need dialog accept/reject action icons
|
okButton.SetIcon(tomo.IconDialogOkay)
|
||||||
// okButton.SetIcon(tomo.IconStatusOkay)
|
|
||||||
okButton.OnClick(func () {
|
okButton.OnClick(func () {
|
||||||
if onOk != nil { onOk() }
|
if onOk != nil { onOk() }
|
||||||
})
|
})
|
||||||
|
|||||||
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.33.0
|
require git.tebibyte.media/tomo/tomo v0.36.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.33.0 h1:BBm1oRsogBLeqVKeevNqG9RPCOdmbGeiQM/9hd2GHE8=
|
git.tebibyte.media/tomo/tomo v0.36.0 h1:V9vyPYb4kpUceBhcDF/XyLDACzE5lY8kYEGHAkIsqs0=
|
||||||
git.tebibyte.media/tomo/tomo v0.33.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
|
git.tebibyte.media/tomo/tomo v0.36.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=
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ func NewHeading (level int, text string) *Heading {
|
|||||||
if level < 0 { level = 0 }
|
if level < 0 { level = 0 }
|
||||||
if level > 2 { level = 2 }
|
if level > 2 { level = 2 }
|
||||||
this := &Heading { TextBox: tomo.NewTextBox() }
|
this := &Heading { TextBox: tomo.NewTextBox() }
|
||||||
tomo.Apply(this, tomo.R("objects", "Heading", fmt.Sprint(level)))
|
this.SetRole(tomo.R("objects", "Heading", fmt.Sprint(level)))
|
||||||
|
tomo.Apply(this)
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
6
icon.go
6
icon.go
@@ -15,7 +15,8 @@ func NewIcon (id tomo.Icon, size tomo.IconSize) *Icon {
|
|||||||
this := &Icon {
|
this := &Icon {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
tomo.Apply(this, tomo.R("objects", "Icon", size.String()))
|
this.SetRole(tomo.R("objects", "Icon", size.String()))
|
||||||
|
tomo.Apply(this)
|
||||||
this.SetTexture(id.Texture(size))
|
this.SetTexture(id.Texture(size))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@@ -25,7 +26,8 @@ func NewMimeIcon (mime data.Mime, size tomo.IconSize) *Icon {
|
|||||||
this := &Icon {
|
this := &Icon {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
tomo.Apply(this, tomo.R("objects", "Icon", size.String()))
|
this.SetRole(tomo.R("objects", "Icon", size.String()))
|
||||||
|
tomo.Apply(this)
|
||||||
this.SetTexture(tomo.MimeIcon(mime, size))
|
this.SetTexture(tomo.MimeIcon(mime, size))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
3
label.go
3
label.go
@@ -10,7 +10,8 @@ type Label struct {
|
|||||||
// NewLabel creates a new text label.
|
// NewLabel creates a new text label.
|
||||||
func NewLabel (text string) *Label {
|
func NewLabel (text string) *Label {
|
||||||
this := &Label { TextBox: tomo.NewTextBox() }
|
this := &Label { TextBox: tomo.NewTextBox() }
|
||||||
tomo.Apply(this, tomo.R("objects", "Label", ""))
|
this.SetRole(tomo.R("objects", "Label", ""))
|
||||||
|
tomo.Apply(this)
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
|
|||||||
checkbox: NewCheckbox(value),
|
checkbox: NewCheckbox(value),
|
||||||
label: NewLabel(text),
|
label: NewLabel(text),
|
||||||
}
|
}
|
||||||
tomo.Apply(box, tomo.R("objects", "LabelCheckbox", ""))
|
box.SetRole(tomo.R("objects", "LabelCheckbox", ""))
|
||||||
|
tomo.Apply(box)
|
||||||
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
||||||
box.Add(box.checkbox)
|
box.Add(box.checkbox)
|
||||||
box.Add(box.label)
|
box.Add(box.label)
|
||||||
|
|||||||
101
menu.go
Normal file
101
menu.go
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
package objects
|
||||||
|
|
||||||
|
import "image"
|
||||||
|
import "git.tebibyte.media/tomo/tomo"
|
||||||
|
import "git.tebibyte.media/tomo/tomo/input"
|
||||||
|
// import "git.tebibyte.media/tomo/tomo/event"
|
||||||
|
import "git.tebibyte.media/tomo/objects/layouts"
|
||||||
|
|
||||||
|
// Menu is a menu window.
|
||||||
|
type Menu struct {
|
||||||
|
tomo.Window
|
||||||
|
|
||||||
|
parent tomo.Window
|
||||||
|
bounds image.Rectangle
|
||||||
|
rootContainer tomo.ContainerBox
|
||||||
|
tearLine tomo.Box
|
||||||
|
torn bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMenu creates a new menu with the specified items. The menu will appear
|
||||||
|
// directly under the anchor Object. If the anchor is nil, it will appear
|
||||||
|
// directly under the mouse pointer instead.
|
||||||
|
func NewMenu (anchor tomo.Object, items ...tomo.Object) (*Menu, error) {
|
||||||
|
menu := &Menu { }
|
||||||
|
if anchor == nil {
|
||||||
|
// TODO: *actually* put it under the mouse
|
||||||
|
window, err := tomo.NewWindow(menu.bounds)
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
menu.Window = window
|
||||||
|
} else {
|
||||||
|
menu.bounds = menuBoundsFromAnchor(anchor)
|
||||||
|
menu.parent = anchor.GetBox().Window()
|
||||||
|
window, err := menu.parent.NewMenu(menu.bounds)
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
menu.Window = window
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.rootContainer = tomo.NewContainerBox()
|
||||||
|
menu.rootContainer.SetLayout(layouts.ContractVertical)
|
||||||
|
|
||||||
|
if !menu.torn {
|
||||||
|
menu.tearLine = tomo.NewBox()
|
||||||
|
menu.tearLine.SetRole(tomo.R("objects", "TearLine", ""))
|
||||||
|
tomo.Apply(menu.tearLine)
|
||||||
|
menu.tearLine.SetFocusable(true)
|
||||||
|
menu.tearLine.OnKeyUp(func (key input.Key, numberPad bool) {
|
||||||
|
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||||
|
menu.TearOff()
|
||||||
|
})
|
||||||
|
menu.tearLine.OnMouseUp(func (button input.Button) {
|
||||||
|
if button != input.ButtonLeft { return }
|
||||||
|
if menu.tearLine.MousePosition().In(menu.tearLine.Bounds()) {
|
||||||
|
menu.TearOff()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
menu.rootContainer.Add(menu.tearLine)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range items {
|
||||||
|
menu.rootContainer.Add(item)
|
||||||
|
if item, ok := item.(*MenuItem); ok {
|
||||||
|
item.OnClick(func () {
|
||||||
|
if !menu.torn {
|
||||||
|
menu.Close()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
menu.rootContainer.SetRole(tomo.R("objects", "Container", "menu"))
|
||||||
|
tomo.Apply(menu.rootContainer)
|
||||||
|
|
||||||
|
menu.Window.SetRoot(menu.rootContainer)
|
||||||
|
return menu, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TearOff converts this menu into a tear-off menu.
|
||||||
|
func (this *Menu) TearOff () {
|
||||||
|
if this.torn { return }
|
||||||
|
if this.parent == nil { return }
|
||||||
|
this.torn = true
|
||||||
|
|
||||||
|
window, err := this.parent.NewChild(this.bounds)
|
||||||
|
if err != nil { return }
|
||||||
|
|
||||||
|
visible := this.Window.Visible()
|
||||||
|
this.Window.SetRoot(nil)
|
||||||
|
this.Window.Close()
|
||||||
|
|
||||||
|
this.rootContainer.Remove(this.tearLine)
|
||||||
|
|
||||||
|
this.Window = window
|
||||||
|
this.Window.SetRoot(this.rootContainer)
|
||||||
|
this.Window.SetVisible(visible)
|
||||||
|
}
|
||||||
|
|
||||||
|
func menuBoundsFromAnchor (anchor tomo.Object) image.Rectangle {
|
||||||
|
bounds := anchor.GetBox().Bounds()
|
||||||
|
return image.Rect (
|
||||||
|
bounds.Min.X, bounds.Max.Y,
|
||||||
|
bounds.Max.X, bounds.Max.Y)//.Add(windowBounds.Min)
|
||||||
|
}
|
||||||
74
menuitem.go
Normal file
74
menuitem.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package objects
|
||||||
|
|
||||||
|
import "git.tebibyte.media/tomo/tomo"
|
||||||
|
import "git.tebibyte.media/tomo/tomo/input"
|
||||||
|
import "git.tebibyte.media/tomo/tomo/event"
|
||||||
|
import "git.tebibyte.media/tomo/objects/layouts"
|
||||||
|
|
||||||
|
// MenuItem is a clickable button.
|
||||||
|
type MenuItem struct {
|
||||||
|
tomo.ContainerBox
|
||||||
|
|
||||||
|
label *Label
|
||||||
|
icon *Icon
|
||||||
|
labelActive bool
|
||||||
|
|
||||||
|
on struct {
|
||||||
|
click event.FuncBroadcaster
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMenuItem creates a new menu item with the specified text.
|
||||||
|
func NewMenuItem (text string) *MenuItem {
|
||||||
|
box := &MenuItem {
|
||||||
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
|
label: NewLabel(text),
|
||||||
|
icon: NewIcon("", tomo.IconSizeSmall),
|
||||||
|
}
|
||||||
|
box.SetRole(tomo.R("objects", "MenuItem", ""))
|
||||||
|
tomo.Apply(box)
|
||||||
|
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
||||||
|
box.SetLayout(layouts.NewGrid([]bool { false, true }, []bool { true }))
|
||||||
|
|
||||||
|
box.Add(box.icon)
|
||||||
|
box.Add(box.label)
|
||||||
|
|
||||||
|
box.CaptureDND(true)
|
||||||
|
box.CaptureMouse(true)
|
||||||
|
box.CaptureScroll(true)
|
||||||
|
box.CaptureKeyboard(true)
|
||||||
|
|
||||||
|
box.OnMouseUp(box.handleMouseUp)
|
||||||
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
|
box.SetFocusable(true)
|
||||||
|
return box
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetText sets the text of the items's label.
|
||||||
|
func (this *MenuItem) SetText (text string) {
|
||||||
|
this.label.SetText(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIcon sets an icon for this item. Setting the icon to IconUnknown will
|
||||||
|
// remove it.
|
||||||
|
func (this *MenuItem) SetIcon (id tomo.Icon) {
|
||||||
|
if this.icon != nil { this.Remove(this.icon) }
|
||||||
|
this.Insert(NewIcon(id, tomo.IconSizeSmall), this.label)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnClick specifies a function to be called when the menu item is clicked.
|
||||||
|
func (this *MenuItem) OnClick (callback func ()) event.Cookie {
|
||||||
|
return this.on.click.Connect(callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MenuItem) handleKeyUp (key input.Key, numberPad bool) {
|
||||||
|
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||||
|
this.on.click.Broadcast()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MenuItem) handleMouseUp (button input.Button) {
|
||||||
|
if button != input.ButtonLeft { return }
|
||||||
|
if this.MousePosition().In(this.Bounds()) {
|
||||||
|
this.on.click.Broadcast()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,13 +28,14 @@ func NewNumberInput (value float64) *NumberInput {
|
|||||||
increment: NewButton(""),
|
increment: NewButton(""),
|
||||||
decrement: NewButton(""),
|
decrement: NewButton(""),
|
||||||
}
|
}
|
||||||
tomo.Apply(box, tomo.R("objects", "NumberInput", ""))
|
box.SetRole(tomo.R("objects", "NumberInput", ""))
|
||||||
|
tomo.Apply(box)
|
||||||
box.Add(box.input)
|
box.Add(box.input)
|
||||||
box.Add(box.decrement)
|
box.Add(box.decrement)
|
||||||
box.Add(box.increment)
|
box.Add(box.increment)
|
||||||
box.SetLayout(layouts.NewGrid([]bool { true, false, false }, []bool { true }))
|
box.SetLayout(layouts.NewGrid([]bool { true, false, false }, []bool { true }))
|
||||||
box.increment.SetIcon(tomo.IconListAdd) // FIXME: need incr/decrment icons
|
box.increment.SetIcon(tomo.IconValueIncrement)
|
||||||
box.decrement.SetIcon(tomo.IconListRemove)
|
box.decrement.SetIcon(tomo.IconValueDecrement)
|
||||||
|
|
||||||
box.SetValue(value)
|
box.SetValue(value)
|
||||||
|
|
||||||
|
|||||||
28
scrollbar.go
28
scrollbar.go
@@ -45,8 +45,11 @@ func newScrollbar (orient string) *Scrollbar {
|
|||||||
this.OnMouseUp(this.handleMouseUp)
|
this.OnMouseUp(this.handleMouseUp)
|
||||||
this.OnMouseMove(this.handleMouseMove)
|
this.OnMouseMove(this.handleMouseMove)
|
||||||
this.OnScroll(this.handleScroll)
|
this.OnScroll(this.handleScroll)
|
||||||
tomo.Apply(this.handle, tomo.R("objects", "SliderHandle", orient))
|
|
||||||
tomo.Apply(this, tomo.R("objects", "Slider", orient))
|
this.handle.SetRole(tomo.R("objects", "SliderHandle", orient))
|
||||||
|
tomo.Apply(this.handle)
|
||||||
|
this.SetRole(tomo.R("objects", "Slider", orient))
|
||||||
|
tomo.Apply(this)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,9 +63,9 @@ func NewHorizontalScrollbar () *Scrollbar {
|
|||||||
return newScrollbar("horizontal")
|
return newScrollbar("horizontal")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link assigns this scrollbar to a ContentBox. Closing the returned cookie will
|
// Link assigns this scrollbar to a ContentObject. Closing the returned cookie
|
||||||
// unlink it.
|
// will unlink it.
|
||||||
func (this *Scrollbar) Link (box tomo.ContentBox) event.Cookie {
|
func (this *Scrollbar) Link (box tomo.ContentObject) event.Cookie {
|
||||||
this.layout.linked = box
|
this.layout.linked = box
|
||||||
this.linkCookie = this.newLinkCookie (
|
this.linkCookie = this.newLinkCookie (
|
||||||
box.OnContentBoundsChange(this.handleLinkedContentBoundsChange))
|
box.OnContentBoundsChange(this.handleLinkedContentBoundsChange))
|
||||||
@@ -230,7 +233,7 @@ func (this *Scrollbar) fallbackDragOffset () image.Point {
|
|||||||
|
|
||||||
func (this *Scrollbar) pageSize () int {
|
func (this *Scrollbar) pageSize () int {
|
||||||
if this.layout.linked == nil { return 0 }
|
if this.layout.linked == nil { return 0 }
|
||||||
viewport := this.layout.linked.InnerBounds()
|
viewport := this.layout.linked.GetBox().InnerBounds()
|
||||||
if this.layout.vertical {
|
if this.layout.vertical {
|
||||||
return viewport.Dy()
|
return viewport.Dy()
|
||||||
} else {
|
} else {
|
||||||
@@ -279,7 +282,7 @@ func (this *scrollbarCookie) Close () {
|
|||||||
type scrollbarLayout struct {
|
type scrollbarLayout struct {
|
||||||
vertical bool
|
vertical bool
|
||||||
value float64
|
value float64
|
||||||
linked tomo.ContentBox
|
linked tomo.ContentObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scrollbarLayout) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
func (scrollbarLayout) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
||||||
@@ -306,9 +309,10 @@ func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
handleLength := gutterLength * this.viewportContentRatio()
|
handleLength := gutterLength * this.viewportContentRatio()
|
||||||
if handleLength < handleMin { handleLength = handleMin }
|
if handleLength < handleMin { handleLength = handleMin }
|
||||||
if handleLength >= gutterLength {
|
if handleLength >= gutterLength {
|
||||||
// just hide the handle if it isn't needed.
|
// just hide the handle if it isn't needed. we are the layout
|
||||||
// TODO: we need a way to hide and show boxes, this is janky as
|
// and we shouldn't be adding and removing boxes, so this is
|
||||||
// fuck
|
// really the only good way to hide things.
|
||||||
|
// TODO perhaps have a "Hidden" rectangle in the Tomo API?
|
||||||
boxes[0].SetBounds(image.Rect(-16, -16, 0, 0))
|
boxes[0].SetBounds(image.Rect(-16, -16, 0, 0))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -340,9 +344,9 @@ func (this scrollbarLayout) viewportContentRatio () float64 {
|
|||||||
|
|
||||||
func (this scrollbarLayout) viewportLength () float64 {
|
func (this scrollbarLayout) viewportLength () float64 {
|
||||||
if this.vertical {
|
if this.vertical {
|
||||||
return float64(this.linked.InnerBounds().Dy())
|
return float64(this.linked.GetBox().InnerBounds().Dy())
|
||||||
} else {
|
} else {
|
||||||
return float64(this.linked.InnerBounds().Dx())
|
return float64(this.linked.GetBox().InnerBounds().Dx())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
|||||||
}
|
}
|
||||||
this.CaptureScroll(true)
|
this.CaptureScroll(true)
|
||||||
this.OnScroll(this.handleScroll)
|
this.OnScroll(this.handleScroll)
|
||||||
tomo.Apply(this, tomo.R("objects", "ScrollContainer", sides.String()))
|
this.SetRole(tomo.R("objects", "ScrollContainer", sides.String()))
|
||||||
|
tomo.Apply(this)
|
||||||
this.SetLayout(this.layout)
|
this.SetLayout(this.layout)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@@ -68,7 +69,7 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
|||||||
// SetRoot sets the root child of the ScrollContainer. There can only be one at
|
// SetRoot sets the root child of the ScrollContainer. There can only be one at
|
||||||
// a time, and setting it will remove and unlink the current child if there is
|
// a time, and setting it will remove and unlink the current child if there is
|
||||||
// one.
|
// one.
|
||||||
func (this *ScrollContainer) SetRoot (root tomo.ContentBox) {
|
func (this *ScrollContainer) SetRoot (root tomo.ContentObject) {
|
||||||
if this.layout.root != nil {
|
if this.layout.root != nil {
|
||||||
// remove root and close cookies
|
// remove root and close cookies
|
||||||
this.Remove(this.layout.root)
|
this.Remove(this.layout.root)
|
||||||
@@ -134,14 +135,14 @@ func (this *ScrollContainer) handleScroll (x, y float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type scrollContainerLayout struct {
|
type scrollContainerLayout struct {
|
||||||
root tomo.ContentBox
|
root tomo.ContentObject
|
||||||
horizontal *Scrollbar
|
horizontal *Scrollbar
|
||||||
vertical *Scrollbar
|
vertical *Scrollbar
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *scrollContainerLayout) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
func (this *scrollContainerLayout) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
||||||
var minimum image.Point; if this.root != nil {
|
var minimum image.Point; if this.root != nil {
|
||||||
minimum = this.root.MinimumSize()
|
minimum = this.root.GetBox().MinimumSize()
|
||||||
}
|
}
|
||||||
if this.horizontal != nil {
|
if this.horizontal != nil {
|
||||||
minimum.Y += this.horizontal.MinimumSize().Y
|
minimum.Y += this.horizontal.MinimumSize().Y
|
||||||
@@ -165,7 +166,7 @@ func (this *scrollContainerLayout) Arrange (hints tomo.LayoutHints, boxes []tomo
|
|||||||
rootBounds.Max.X -= this.vertical.MinimumSize().X
|
rootBounds.Max.X -= this.vertical.MinimumSize().X
|
||||||
}
|
}
|
||||||
if this.root != nil {
|
if this.root != nil {
|
||||||
this.root.SetBounds(rootBounds)
|
this.root.GetBox().SetBounds(rootBounds)
|
||||||
}
|
}
|
||||||
if this.horizontal != nil {
|
if this.horizontal != nil {
|
||||||
this.horizontal.SetBounds(image.Rect (
|
this.horizontal.SetBounds(image.Rect (
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ func NewSeparator () *Separator {
|
|||||||
this := &Separator {
|
this := &Separator {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
tomo.Apply(this, tomo.R("objects", "Separator", ""))
|
this.SetRole(tomo.R("objects", "Separator", ""))
|
||||||
|
tomo.Apply(this)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,11 @@ func newSlider (orient string, value float64) *Slider {
|
|||||||
this.OnMouseUp(this.handleMouseUp)
|
this.OnMouseUp(this.handleMouseUp)
|
||||||
this.OnMouseMove(this.handleMouseMove)
|
this.OnMouseMove(this.handleMouseMove)
|
||||||
this.OnScroll(this.handleScroll)
|
this.OnScroll(this.handleScroll)
|
||||||
tomo.Apply(this.handle, tomo.R("objects", "SliderHandle", orient))
|
|
||||||
tomo.Apply(this, tomo.R("objects", "Slider", orient))
|
this.handle.SetRole(tomo.R("objects", "SliderHandle", orient))
|
||||||
|
tomo.Apply(this.handle)
|
||||||
|
this.SetRole(tomo.R("objects", "Slider", orient))
|
||||||
|
tomo.Apply(this)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ type TextInput struct {
|
|||||||
// NewTextInput creates a new text input containing the specified text.
|
// NewTextInput creates a new text input containing the specified text.
|
||||||
func NewTextInput (text string) *TextInput {
|
func NewTextInput (text string) *TextInput {
|
||||||
this := &TextInput { TextBox: tomo.NewTextBox() }
|
this := &TextInput { TextBox: tomo.NewTextBox() }
|
||||||
tomo.Apply(this, tomo.R("objects", "TextInput", ""))
|
this.SetRole(tomo.R("objects", "TextInput", ""))
|
||||||
|
tomo.Apply(this)
|
||||||
this.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
this.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ type TextView struct {
|
|||||||
// NewTextView creates a new text view.
|
// NewTextView creates a new text view.
|
||||||
func NewTextView (text string) *TextView {
|
func NewTextView (text string) *TextView {
|
||||||
this := &TextView { TextBox: tomo.NewTextBox() }
|
this := &TextView { TextBox: tomo.NewTextBox() }
|
||||||
tomo.Apply(this, tomo.R("objects", "TextView", ""))
|
this.SetRole(tomo.R("objects", "TextView", ""))
|
||||||
|
tomo.Apply(this)
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
this.SetSelectable(true)
|
this.SetSelectable(true)
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
|
|||||||
Reference in New Issue
Block a user