Update code for layouts, objects
This commit is contained in:
parent
9077015db6
commit
6ca6771fc6
24
button.go
24
button.go
@ -28,17 +28,16 @@ func NewButton (text string) *Button {
|
|||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
label: NewLabel(text),
|
label: NewLabel(text),
|
||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "Button", ""))
|
box.SetRole(tomo.R("objects", "Button"))
|
||||||
box.label.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
|
box.label.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle))
|
||||||
box.SetLayout(buttonLayout)
|
box.SetLayout(buttonLayout)
|
||||||
box.SetText(text)
|
box.SetText(text)
|
||||||
|
|
||||||
box.CaptureDND(true)
|
box.CatchDND(true)
|
||||||
box.CaptureMouse(true)
|
box.CatchMouse(true)
|
||||||
box.CaptureScroll(true)
|
|
||||||
box.CaptureKeyboard(true)
|
|
||||||
|
|
||||||
box.OnMouseUp(box.handleMouseUp)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
box.OnKeyUp(box.handleKeyUp)
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
box.SetFocusable(true)
|
box.SetFocusable(true)
|
||||||
return box
|
return box
|
||||||
@ -89,14 +88,19 @@ func (this *Button) applyLayout () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Button) handleKeyUp (key input.Key, numberPad bool) {
|
func (this *Button) handleKeyUp (catch func (), key input.Key, numberPad bool) {
|
||||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||||
this.on.click.Broadcast()
|
this.on.click.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Button) handleMouseUp (button input.Button) {
|
func (this *Button) handleButtonDown (catch func (), button input.Button) {
|
||||||
|
catch()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Button) handleButtonUp (catch func (), button input.Button) {
|
||||||
|
catch()
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
if this.MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.on.click.Broadcast()
|
this.on.click.Broadcast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
calendar.go
20
calendar.go
@ -26,7 +26,7 @@ func NewCalendar (tm time.Time) *Calendar {
|
|||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
time: tm,
|
time: tm,
|
||||||
}
|
}
|
||||||
calendar.SetRole(tomo.R("objects", "Calendar", ""))
|
calendar.SetRole(tomo.R("objects", "Calendar"))
|
||||||
calendar.SetLayout(layouts.ContractVertical)
|
calendar.SetLayout(layouts.ContractVertical)
|
||||||
|
|
||||||
prevButton := NewButton("")
|
prevButton := NewButton("")
|
||||||
@ -42,10 +42,10 @@ func NewCalendar (tm time.Time) *Calendar {
|
|||||||
calendar.on.valueChange.Broadcast()
|
calendar.on.valueChange.Broadcast()
|
||||||
})
|
})
|
||||||
calendar.monthLabel = NewLabel("")
|
calendar.monthLabel = NewLabel("")
|
||||||
calendar.monthLabel.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
|
calendar.monthLabel.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle))
|
||||||
|
|
||||||
calendar.grid = tomo.NewContainerBox()
|
calendar.grid = tomo.NewContainerBox()
|
||||||
calendar.grid.SetRole(tomo.R("objects", "CalendarGrid", ""))
|
calendar.grid.SetRole(tomo.R("objects", "CalendarGrid"))
|
||||||
calendar.grid.SetLayout(layouts.NewGrid (
|
calendar.grid.SetLayout(layouts.NewGrid (
|
||||||
true, true, true, true, true, true, true)())
|
true, true, true, true, true, true, true)())
|
||||||
calendar.Add(NewInnerContainer (
|
calendar.Add(NewInnerContainer (
|
||||||
@ -54,7 +54,6 @@ func NewCalendar (tm time.Time) *Calendar {
|
|||||||
calendar.Add(calendar.grid)
|
calendar.Add(calendar.grid)
|
||||||
|
|
||||||
calendar.OnScroll(calendar.handleScroll)
|
calendar.OnScroll(calendar.handleScroll)
|
||||||
calendar.CaptureScroll(true)
|
|
||||||
|
|
||||||
calendar.refresh()
|
calendar.refresh()
|
||||||
return calendar
|
return calendar
|
||||||
@ -98,9 +97,9 @@ func (this *Calendar) refresh () {
|
|||||||
this.grid.Clear()
|
this.grid.Clear()
|
||||||
for _, day := range weekdayAbbreviations {
|
for _, day := range weekdayAbbreviations {
|
||||||
dayLabel := tomo.NewTextBox()
|
dayLabel := tomo.NewTextBox()
|
||||||
dayLabel.SetRole(tomo.R("objects", "CalendarWeekdayHeader", ""))
|
dayLabel.SetRole(tomo.R("objects", "CalendarWeekdayHeader"))
|
||||||
dayLabel.SetText(day)
|
dayLabel.SetText(day)
|
||||||
dayLabel.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
|
dayLabel.SetAttr(tomo.AAlign(tomo.AlignMiddle, tomo.AlignMiddle))
|
||||||
this.grid.Add(dayLabel)
|
this.grid.Add(dayLabel)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,9 +115,11 @@ func (this *Calendar) refresh () {
|
|||||||
day := tomo.NewTextBox()
|
day := tomo.NewTextBox()
|
||||||
day.SetText(fmt.Sprint(dayIter))
|
day.SetText(fmt.Sprint(dayIter))
|
||||||
if weekday == 1 || weekday == 0 {
|
if weekday == 1 || weekday == 0 {
|
||||||
day.SetRole(tomo.R("objects", "CalendarDay", "weekend"))
|
day.SetRole(tomo.R("objects", "CalendarDay"))
|
||||||
|
day.SetTag("weekend", true)
|
||||||
} else {
|
} else {
|
||||||
day.SetRole(tomo.R("objects", "CalendarDay", "weekday"))
|
day.SetRole(tomo.R("objects", "CalendarDay"))
|
||||||
|
day.SetTag("weekday", true)
|
||||||
}
|
}
|
||||||
this.grid.Add(day)
|
this.grid.Add(day)
|
||||||
} else {
|
} else {
|
||||||
@ -127,7 +128,8 @@ func (this *Calendar) refresh () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Calendar) handleScroll (x, y float64) {
|
func (this *Calendar) handleScroll (catch func (), x, y float64) {
|
||||||
|
catch()
|
||||||
if y < 0 {
|
if y < 0 {
|
||||||
this.prevMonth()
|
this.prevMonth()
|
||||||
} else {
|
} else {
|
||||||
|
24
checkbox.go
24
checkbox.go
@ -18,10 +18,11 @@ func NewCheckbox (value bool) *Checkbox {
|
|||||||
box := &Checkbox {
|
box := &Checkbox {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "Checkbox", ""))
|
box.SetRole(tomo.R("objects", "Checkbox"))
|
||||||
box.SetValue(value)
|
box.SetValue(value)
|
||||||
|
|
||||||
box.OnMouseUp(box.handleMouseUp)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
box.OnKeyUp(box.handleKeyUp)
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
box.SetFocusable(true)
|
box.SetFocusable(true)
|
||||||
return box
|
return box
|
||||||
@ -35,11 +36,9 @@ func (this *Checkbox) Value () bool {
|
|||||||
// SetValue sets the value of the checkbox.
|
// SetValue sets the value of the checkbox.
|
||||||
func (this *Checkbox) SetValue (value bool) {
|
func (this *Checkbox) SetValue (value bool) {
|
||||||
this.value = value
|
this.value = value
|
||||||
if this.value {
|
// the theme shall decide what checked and unchecked states look like
|
||||||
this.SetTextureCenter(tomo.IconCheckboxChecked.Texture(tomo.IconSizeSmall))
|
this.SetTag("checked", value)
|
||||||
} else {
|
this.SetTag("unchecked", !value)
|
||||||
this.SetTextureCenter(tomo.IconCheckboxUnchecked.Texture(tomo.IconSizeSmall))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle toggles the value of the checkbox between true and false.
|
// Toggle toggles the value of the checkbox between true and false.
|
||||||
@ -53,14 +52,19 @@ func (this *Checkbox) OnValueChange (callback func ()) event.Cookie {
|
|||||||
return this.on.valueChange.Connect(callback)
|
return this.on.valueChange.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Checkbox) handleKeyUp (key input.Key, numberPad bool) {
|
func (this *Checkbox) handleKeyUp (catch func (), key input.Key, numberPad bool) {
|
||||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||||
this.Toggle()
|
this.Toggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Checkbox) handleMouseUp (button input.Button) {
|
func (this *Checkbox) handleButtonDown (catch func (), button input.Button) {
|
||||||
|
catch()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Checkbox) handleButtonUp (catch func (), button input.Button) {
|
||||||
|
catch()
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
if this.MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.Toggle()
|
this.Toggle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ func NewColorPicker (value color.Color) *ColorPicker {
|
|||||||
picker := &ColorPicker {
|
picker := &ColorPicker {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
}
|
}
|
||||||
picker.SetRole(tomo.R("objects", "ColorPicker", ""))
|
picker.SetRole(tomo.R("objects", "ColorPicker"))
|
||||||
picker.SetLayout(layouts.Row { true, false, false })
|
picker.SetLayout(layouts.Row { true, false, false })
|
||||||
picker.pickerMap = newColorPickerMap(picker)
|
picker.pickerMap = newColorPickerMap(picker)
|
||||||
picker.Add(picker.pickerMap)
|
picker.Add(picker.pickerMap)
|
||||||
@ -90,20 +90,20 @@ func newColorPickerMap (parent *ColorPicker) *colorPickerMap {
|
|||||||
parent: parent,
|
parent: parent,
|
||||||
}
|
}
|
||||||
picker.SetDrawer(picker)
|
picker.SetDrawer(picker)
|
||||||
picker.SetRole(tomo.R("objects", "ColorPickerMap", ""))
|
picker.SetRole(tomo.R("objects", "ColorPickerMap"))
|
||||||
picker.OnMouseUp(picker.handleMouseUp)
|
picker.OnButtonUp(picker.handleButtonUp)
|
||||||
picker.OnMouseDown(picker.handleMouseDown)
|
picker.OnButtonDown(picker.handleButtonDown)
|
||||||
picker.OnMouseMove(picker.handleMouseMove)
|
picker.OnMouseMove(picker.handleMouseMove)
|
||||||
return picker
|
return picker
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) handleMouseDown (button input.Button) {
|
func (this *colorPickerMap) handleButtonDown (catch func (), button input.Button) {
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
this.dragging = true
|
this.dragging = true
|
||||||
this.drag()
|
this.drag()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) handleMouseUp (button input.Button) {
|
func (this *colorPickerMap) handleButtonUp (catch func (), button input.Button) {
|
||||||
if button != input.ButtonLeft || !this.dragging { return }
|
if button != input.ButtonLeft || !this.dragging { return }
|
||||||
this.dragging = false
|
this.dragging = false
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ func (this *colorPickerMap) handleMouseMove () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *colorPickerMap) drag () {
|
func (this *colorPickerMap) drag () {
|
||||||
pointer := this.MousePosition()
|
pointer := this.Window().MousePosition()
|
||||||
bounds := this.InnerBounds()
|
bounds := this.InnerBounds()
|
||||||
this.parent.value.S = float64(pointer.X - bounds.Min.X) / float64(bounds.Dx())
|
this.parent.value.S = float64(pointer.X - bounds.Min.X) / float64(bounds.Dx())
|
||||||
this.parent.value.V = 1 - float64(pointer.Y - bounds.Min.Y) / float64(bounds.Dy())
|
this.parent.value.V = 1 - float64(pointer.Y - bounds.Min.Y) / float64(bounds.Dy())
|
||||||
|
@ -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...)
|
||||||
this.SetRole(tomo.R("objects", "Container", "outer"))
|
this.SetRole(tomo.R("objects", "Container"))
|
||||||
|
this.SetTag("outer", true)
|
||||||
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...)
|
||||||
this.SetRole(tomo.R("objects", "Container", "sunken"))
|
this.SetRole(tomo.R("objects", "Container"))
|
||||||
|
this.SetTag("sunken", true)
|
||||||
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...)
|
||||||
this.SetRole(tomo.R("objects", "Container", "inner"))
|
this.SetRole(tomo.R("objects", "Container"))
|
||||||
|
this.SetTag("inner", true)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
|
|||||||
dialog.SetTitle(title)
|
dialog.SetTitle(title)
|
||||||
icon := NewIcon(iconId, tomo.IconSizeLarge)
|
icon := NewIcon(iconId, tomo.IconSizeLarge)
|
||||||
messageText := NewLabel(message)
|
messageText := NewLabel(message)
|
||||||
messageText.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
messageText.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
if option, ok := option.(clickable); ok {
|
if option, ok := option.(clickable); ok {
|
||||||
@ -63,7 +63,7 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dialog.controlRow = NewInnerContainer(layouts.ContractHorizontal, options...)
|
dialog.controlRow = NewInnerContainer(layouts.ContractHorizontal, options...)
|
||||||
dialog.controlRow.SetAlign(tomo.AlignEnd, tomo.AlignEnd)
|
messageText.SetAttr(tomo.AAlign(tomo.AlignEnd, tomo.AlignEnd))
|
||||||
|
|
||||||
dialog.SetRoot(NewOuterContainer (
|
dialog.SetRoot(NewOuterContainer (
|
||||||
layouts.Column { true, false },
|
layouts.Column { true, false },
|
||||||
|
@ -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() }
|
||||||
this.SetRole(tomo.R("objects", "Heading", fmt.Sprint(level)))
|
this.SetRole(tomo.R("objects", "Heading"))
|
||||||
|
this.SetTag(fmt.Sprint(level), true)
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
29
icon.go
29
icon.go
@ -1,6 +1,5 @@
|
|||||||
package objects
|
package objects
|
||||||
|
|
||||||
import "image"
|
|
||||||
import "git.tebibyte.media/tomo/tomo"
|
import "git.tebibyte.media/tomo/tomo"
|
||||||
import "git.tebibyte.media/tomo/tomo/data"
|
import "git.tebibyte.media/tomo/tomo/data"
|
||||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||||
@ -10,13 +9,22 @@ type Icon struct {
|
|||||||
tomo.Box
|
tomo.Box
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func iconSizeString (size tomo.IconSize) string {
|
||||||
|
switch size {
|
||||||
|
case tomo.IconSizeLarge: return "large"
|
||||||
|
case tomo.IconSizeMedium: return "medium"
|
||||||
|
default: return "small"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewIcon creates a new icon from an icon ID.
|
// NewIcon creates a new icon from an icon ID.
|
||||||
func NewIcon (id tomo.Icon, size tomo.IconSize) *Icon {
|
func NewIcon (id tomo.Icon, size tomo.IconSize) *Icon {
|
||||||
this := &Icon {
|
this := &Icon {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
this.SetRole(tomo.R("objects", "Icon", size.String()))
|
this.SetRole(tomo.R("objects", "Icon"))
|
||||||
this.SetTexture(id.Texture(size))
|
this.SetTag(iconSizeString(size), true)
|
||||||
|
this.setTexture(id.Texture(size))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,17 +33,20 @@ func NewMimeIcon (mime data.Mime, size tomo.IconSize) *Icon {
|
|||||||
this := &Icon {
|
this := &Icon {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
this.SetRole(tomo.R("objects", "Icon", size.String()))
|
this.SetRole(tomo.R("objects", "Icon"))
|
||||||
this.SetTexture(tomo.MimeIcon(mime, size))
|
this.SetTag(iconSizeString(size), true)
|
||||||
|
this.setTexture(tomo.MimeIcon(mime, size))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Icon) SetTexture (texture canvas.Texture) {
|
func (this *Icon) setTexture (texture canvas.Texture) {
|
||||||
this.Box.SetTextureCenter(texture)
|
|
||||||
|
this.SetAttr(tomo.ATexture(texture))
|
||||||
|
this.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter))
|
||||||
if texture == nil {
|
if texture == nil {
|
||||||
this.SetMinimumSize(image.Pt(0, 0))
|
this.SetAttr(tomo.AMinimumSize(0, 0))
|
||||||
} else {
|
} else {
|
||||||
bounds := texture.Bounds()
|
bounds := texture.Bounds()
|
||||||
this.SetMinimumSize(bounds.Max.Sub(bounds.Min))
|
this.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
label.go
4
label.go
@ -10,8 +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() }
|
||||||
this.SetRole(tomo.R("objects", "Label", ""))
|
this.SetRole(tomo.R("objects", "Label"))
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
this.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
this.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,14 @@ func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
|
|||||||
checkbox: NewCheckbox(value),
|
checkbox: NewCheckbox(value),
|
||||||
label: NewLabel(text),
|
label: NewLabel(text),
|
||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "LabelCheckbox", ""))
|
box.SetRole(tomo.R("objects", "LabelCheckbox"))
|
||||||
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
box.Add(box.checkbox)
|
box.Add(box.checkbox)
|
||||||
box.Add(box.label)
|
box.Add(box.label)
|
||||||
box.SetLayout(layouts.Row { false, true })
|
box.SetLayout(layouts.Row { false, true })
|
||||||
|
|
||||||
box.OnMouseUp(box.handleMouseUp)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
box.label.OnMouseUp(box.handleMouseUp)
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
return box
|
return box
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,9 +52,14 @@ func (this *LabelCheckbox) OnValueChange (callback func ()) event.Cookie {
|
|||||||
return this.checkbox.OnValueChange(callback)
|
return this.checkbox.OnValueChange(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *LabelCheckbox) handleMouseUp (button input.Button) {
|
func (this *LabelCheckbox) handleButtonDown (capture func (), button input.Button) {
|
||||||
|
capture()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *LabelCheckbox) handleButtonUp (capture func (), button input.Button) {
|
||||||
|
capture()
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
if this.MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.checkbox.SetFocused(true)
|
this.checkbox.SetFocused(true)
|
||||||
this.checkbox.Toggle()
|
this.checkbox.Toggle()
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,15 @@ func NewLabelSwatch (value color.Color, text string) *LabelSwatch {
|
|||||||
swatch: NewSwatch(value),
|
swatch: NewSwatch(value),
|
||||||
label: NewLabel(text),
|
label: NewLabel(text),
|
||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "LabelSwatch", ""))
|
box.SetRole(tomo.R("objects", "LabelSwatch"))
|
||||||
box.swatch.label = text
|
box.swatch.label = text
|
||||||
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
box.Add(box.swatch)
|
box.Add(box.swatch)
|
||||||
box.Add(box.label)
|
box.Add(box.label)
|
||||||
box.SetLayout(layouts.Row { false, true })
|
box.SetLayout(layouts.Row { false, true })
|
||||||
|
|
||||||
box.OnMouseUp(box.handleMouseUp)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
box.label.OnMouseUp(box.handleMouseUp)
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
return box
|
return box
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,9 +60,14 @@ func (this *LabelSwatch) OnConfirm (callback func ()) event.Cookie {
|
|||||||
return this.swatch.OnConfirm(callback)
|
return this.swatch.OnConfirm(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *LabelSwatch) handleMouseUp (button input.Button) {
|
func (this *LabelSwatch) handleButtonDown (catch func (), button input.Button) {
|
||||||
|
catch()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *LabelSwatch) handleButtonUp (catch func (), button input.Button) {
|
||||||
|
catch()
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
if this.MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.swatch.SetFocused(true)
|
this.swatch.SetFocused(true)
|
||||||
this.swatch.Choose()
|
this.swatch.Choose()
|
||||||
}
|
}
|
||||||
|
@ -15,19 +15,19 @@ const ContractVertical Contract = true
|
|||||||
// ContractHorizontal is a horizontal contracted layout.
|
// ContractHorizontal is a horizontal contracted layout.
|
||||||
const ContractHorizontal Contract = false
|
const ContractHorizontal Contract = false
|
||||||
|
|
||||||
func (contract Contract) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
func (contract Contract) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
|
||||||
return contract.fallback().MinimumSize(hints, boxes)
|
return contract.fallback().MinimumSize(hints, boxes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (contract Contract) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
func (contract Contract) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||||
contract.fallback().Arrange(hints, boxes)
|
contract.fallback().Arrange(hints, boxes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (contract Contract) RecommendedHeight (hints tomo.LayoutHints, boxes []tomo.Box, width int) int {
|
func (contract Contract) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
|
||||||
return contract.fallback().RecommendedHeight(hints, boxes, width)
|
return contract.fallback().RecommendedHeight(hints, boxes, width)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (contract Contract) RecommendedWidth (hints tomo.LayoutHints, boxes []tomo.Box, height int) int {
|
func (contract Contract) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
|
||||||
return contract.fallback().RecommendedWidth(hints, boxes, height)
|
return contract.fallback().RecommendedWidth(hints, boxes, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,21 +17,21 @@ const FlowVertical Flow = true
|
|||||||
// FlowHorizontal is a horizontal flow layout.
|
// FlowHorizontal is a horizontal flow layout.
|
||||||
const FlowHorizontal Flow = false
|
const FlowHorizontal Flow = false
|
||||||
|
|
||||||
func (flow Flow) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
func (flow Flow) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
|
||||||
// TODO: write down somewhere that layout minimums aren't taken into
|
// TODO: write down somewhere that layout minimums aren't taken into
|
||||||
// account when the respective direction is overflowed
|
// account when the respective direction is overflowed
|
||||||
return flow.fallback().MinimumSize(hints, boxes)
|
return flow.fallback().MinimumSize(hints, boxes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow Flow) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
func (flow Flow) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||||
if flow.v() && !hints.OverflowY || flow.h() && !hints.OverflowX {
|
if flow.v() && !hints.OverflowY || flow.h() && !hints.OverflowX {
|
||||||
flow.fallback().Arrange(hints, boxes)
|
flow.fallback().Arrange(hints, boxes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// find a minor size value that will fit all boxes
|
// find a minor size value that will fit all boxes
|
||||||
minorSize := 0
|
minorSize := 0
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
boxSize := flow.minor(box.MinimumSize())
|
boxSize := flow.minor(boxes.MinimumSize(index))
|
||||||
if boxSize > minorSize { minorSize = boxSize }
|
if boxSize > minorSize { minorSize = boxSize }
|
||||||
}
|
}
|
||||||
if minorSize == 0 { return }
|
if minorSize == 0 { return }
|
||||||
@ -43,17 +43,16 @@ func (flow Flow) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
// arrange
|
// arrange
|
||||||
point := hints.Bounds.Min
|
point := hints.Bounds.Min
|
||||||
index := 0
|
index := 0
|
||||||
for index < len(boxes) {
|
for index < boxes.Len() {
|
||||||
// get a slice of boxes for this major step
|
// get a slice of boxes for this major step
|
||||||
stepIndexEnd := index + minorSteps
|
stepIndexEnd := index + minorSteps
|
||||||
if stepIndexEnd > len(boxes) { stepIndexEnd = len(boxes) }
|
if stepIndexEnd > boxes.Len() { stepIndexEnd = boxes.Len() }
|
||||||
step := boxes[index:stepIndexEnd]
|
|
||||||
index += minorSteps
|
index += minorSteps
|
||||||
|
|
||||||
// find a major size that will fit all boxes on this major step
|
// find a major size that will fit all boxes on this major step
|
||||||
majorSize := 0
|
majorSize := 0
|
||||||
for _, box := range step {
|
for index := index; index < stepIndexEnd; index ++ {
|
||||||
boxSize := flow.major(box.MinimumSize())
|
boxSize := flow.major(boxes.MinimumSize(index))
|
||||||
if boxSize > majorSize { majorSize = boxSize }
|
if boxSize > majorSize { majorSize = boxSize }
|
||||||
}
|
}
|
||||||
if majorSize == 0 { continue }
|
if majorSize == 0 { continue }
|
||||||
@ -62,9 +61,9 @@ func (flow Flow) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
var size image.Point
|
var size image.Point
|
||||||
size = flow.incrMajor(size, majorSize)
|
size = flow.incrMajor(size, majorSize)
|
||||||
size = flow.incrMinor(size, minorSize)
|
size = flow.incrMinor(size, minorSize)
|
||||||
for _, box := range step {
|
for index := index; index < stepIndexEnd; index ++ {
|
||||||
bounds := image.Rectangle { Min: point, Max: point.Add(size) }
|
bounds := image.Rectangle { Min: point, Max: point.Add(size) }
|
||||||
box.SetBounds(bounds)
|
boxes.SetBounds(index, bounds)
|
||||||
|
|
||||||
point = flow.incrMinor(point, minorSize + flow.minor(hints.Gap))
|
point = flow.incrMinor(point, minorSize + flow.minor(hints.Gap))
|
||||||
}
|
}
|
||||||
@ -125,12 +124,12 @@ func (flow Flow) fallback () tomo.Layout {
|
|||||||
return Contract(flow)
|
return Contract(flow)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow Flow) RecommendedHeight (hints tomo.LayoutHints, boxes []tomo.Box, width int) int {
|
func (flow Flow) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
|
||||||
// TODO
|
// TODO
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow Flow) RecommendedWidth (hints tomo.LayoutHints, boxes []tomo.Box, height int) int {
|
func (flow Flow) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
|
||||||
// TODO
|
// TODO
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func NewGrid (columns ...bool) func (rows ...bool) *Grid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Grid) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
func (this *Grid) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
|
||||||
cols, rows := this.minimums(boxes)
|
cols, rows := this.minimums(boxes)
|
||||||
size := image.Pt (
|
size := image.Pt (
|
||||||
(len(cols) - 1) * hints.Gap.X,
|
(len(cols) - 1) * hints.Gap.X,
|
||||||
@ -42,7 +42,7 @@ func (this *Grid) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.P
|
|||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Grid) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
func (this *Grid) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||||
xExpand := func (index int) bool {
|
xExpand := func (index int) bool {
|
||||||
return this.xExpand[index]
|
return this.xExpand[index]
|
||||||
}
|
}
|
||||||
@ -56,9 +56,9 @@ func (this *Grid) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
expand(hints, rows, hints.Bounds.Dy(), yExpand)
|
expand(hints, rows, hints.Bounds.Dy(), yExpand)
|
||||||
|
|
||||||
position := hints.Bounds.Min
|
position := hints.Bounds.Min
|
||||||
for index, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
col, row := index % len(cols), index / len(cols)
|
col, row := index % len(cols), index / len(cols)
|
||||||
box.SetBounds(image.Rectangle {
|
boxes.SetBounds(index, image.Rectangle {
|
||||||
Min: position,
|
Min: position,
|
||||||
Max: position.Add(image.Pt(cols[col], rows[row])),
|
Max: position.Add(image.Pt(cols[col], rows[row])),
|
||||||
})
|
})
|
||||||
@ -71,13 +71,13 @@ func (this *Grid) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Grid) minimums (boxes []tomo.Box) ([]int, []int) {
|
func (this *Grid) minimums (boxes tomo.BoxQuerier) ([]int, []int) {
|
||||||
nCols, nRows := this.dimensions(boxes)
|
nCols, nRows := this.dimensions(boxes)
|
||||||
cols, rows := make([]int, nCols), make([]int, nRows)
|
cols, rows := make([]int, nCols), make([]int, nRows)
|
||||||
|
|
||||||
for index, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
col, row := index % len(cols), index / len(cols)
|
col, row := index % len(cols), index / len(cols)
|
||||||
minimum := box.MinimumSize()
|
minimum := boxes.MinimumSize(index)
|
||||||
if cols[col] < minimum.X {
|
if cols[col] < minimum.X {
|
||||||
cols[col] = minimum.X
|
cols[col] = minimum.X
|
||||||
}
|
}
|
||||||
@ -89,8 +89,8 @@ func (this *Grid) minimums (boxes []tomo.Box) ([]int, []int) {
|
|||||||
return cols, rows
|
return cols, rows
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Grid) dimensions (boxes []tomo.Box) (int, int) {
|
func (this *Grid) dimensions (boxes tomo.BoxQuerier) (int, int) {
|
||||||
return len(this.xExpand), ceilDiv(len(boxes), len(this.xExpand))
|
return len(this.xExpand), ceilDiv(boxes.Len(), len(this.xExpand))
|
||||||
}
|
}
|
||||||
|
|
||||||
func expand (hints tomo.LayoutHints, sizes []int, space int, expands func (int) bool) {
|
func expand (hints tomo.LayoutHints, sizes []int, space int, expands func (int) bool) {
|
||||||
@ -116,10 +116,10 @@ func ceilDiv (x, y int) int {
|
|||||||
return int(math.Ceil(float64(x) / float64(y)))
|
return int(math.Ceil(float64(x) / float64(y)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Grid) RecommendedHeight (hints tomo.LayoutHints, boxes []tomo.Box, width int) int {
|
func (this *Grid) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
|
||||||
return this.MinimumSize(hints, boxes).Y
|
return this.MinimumSize(hints, boxes).Y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Grid) RecommendedWidth (hints tomo.LayoutHints, boxes []tomo.Box, height int) int {
|
func (this *Grid) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
|
||||||
return this.MinimumSize(hints, boxes).X
|
return this.MinimumSize(hints, boxes).X
|
||||||
}
|
}
|
||||||
|
@ -13,33 +13,33 @@ type Row []bool
|
|||||||
// value will expand, and others will contract.
|
// value will expand, and others will contract.
|
||||||
type Column []bool
|
type Column []bool
|
||||||
|
|
||||||
func (column Column) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
func (column Column) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
|
||||||
dot := image.Point { }
|
dot := image.Point { }
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
minimum := box.MinimumSize()
|
minimum := boxes.MinimumSize(index)
|
||||||
dot.Y += minimum.Y
|
dot.Y += minimum.Y
|
||||||
if dot.X < minimum.X {
|
if dot.X < minimum.X {
|
||||||
dot.X = minimum.X
|
dot.X = minimum.X
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dot.Y += hints.Gap.Y * (len(boxes) - 1)
|
dot.Y += hints.Gap.Y * (boxes.Len() - 1)
|
||||||
return dot
|
return dot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (row Row) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
func (row Row) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
|
||||||
dot := image.Point { }
|
dot := image.Point { }
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
minimum := box.MinimumSize()
|
minimum := boxes.MinimumSize(index)
|
||||||
dot.X += minimum.X
|
dot.X += minimum.X
|
||||||
if dot.Y < minimum.Y {
|
if dot.Y < minimum.Y {
|
||||||
dot.Y = minimum.Y
|
dot.Y = minimum.Y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dot.X += hints.Gap.X * (len(boxes) - 1)
|
dot.X += hints.Gap.X * (boxes.Len() - 1)
|
||||||
return dot
|
return dot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (column Column) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
func (column Column) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||||
expands := func (index int) bool {
|
expands := func (index int) bool {
|
||||||
if index >= len(column) { return false }
|
if index >= len(column) { return false }
|
||||||
return column[index]
|
return column[index]
|
||||||
@ -48,13 +48,14 @@ func (column Column) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
// determine expanding box size
|
// determine expanding box size
|
||||||
expandingSize := 0.0
|
expandingSize := 0.0
|
||||||
if !hints.OverflowY {
|
if !hints.OverflowY {
|
||||||
gaps := len(boxes) - 1
|
gaps := boxes.Len() - 1
|
||||||
freeSpace := float64(hints.Bounds.Dy() - hints.Gap.Y * gaps)
|
freeSpace := float64(hints.Bounds.Dy() - hints.Gap.Y * gaps)
|
||||||
nExpanding := 0; for index, box := range boxes {
|
nExpanding := 0;
|
||||||
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
if expands(index) {
|
if expands(index) {
|
||||||
nExpanding ++
|
nExpanding ++
|
||||||
} else {
|
} else {
|
||||||
freeSpace -= float64(box.MinimumSize().Y)
|
freeSpace -= float64(boxes.MinimumSize(index).Y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expandingSize = freeSpace / float64(nExpanding)
|
expandingSize = freeSpace / float64(nExpanding)
|
||||||
@ -63,8 +64,8 @@ func (column Column) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
// determine width
|
// determine width
|
||||||
width := 0
|
width := 0
|
||||||
if hints.OverflowX {
|
if hints.OverflowX {
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
minimum := box.MinimumSize()
|
minimum := boxes.MinimumSize(index)
|
||||||
if width < minimum.X { width = minimum.X }
|
if width < minimum.X { width = minimum.X }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -73,44 +74,43 @@ func (column Column) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
|
|
||||||
// arrange
|
// arrange
|
||||||
dot := hints.Bounds.Min
|
dot := hints.Bounds.Min
|
||||||
for index, box := range boxes {
|
bounds := make([]image.Rectangle, boxes.Len())
|
||||||
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
if index > 0 { dot.Y += hints.Gap.Y }
|
if index > 0 { dot.Y += hints.Gap.Y }
|
||||||
|
|
||||||
// determine height
|
// determine height
|
||||||
height := box.MinimumSize().Y
|
height := boxes.MinimumSize(index).Y
|
||||||
if hints.OverflowY {
|
if hints.OverflowY {
|
||||||
if box, ok := box.(tomo.ContentBox); ok {
|
height = boxes.RecommendedHeight(index, width)
|
||||||
height = box.RecommendedHeight(width)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if expands(index) {
|
if expands(index) {
|
||||||
height = int(expandingSize)
|
height = int(expandingSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set bounds
|
// store bounds of this box
|
||||||
box.SetBounds(image.Rectangle {
|
bounds[index] = image.Rectangle {
|
||||||
Min: dot,
|
Min: dot,
|
||||||
Max: dot.Add(image.Pt(width, height)),
|
Max: dot.Add(image.Pt(width, height)),
|
||||||
})
|
}
|
||||||
dot.Y += height
|
dot.Y += height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// align
|
||||||
height := dot.Y - hints.Bounds.Min.Y
|
height := dot.Y - hints.Bounds.Min.Y
|
||||||
offset := 0
|
offset := 0
|
||||||
|
|
||||||
switch hints.AlignY {
|
switch hints.AlignY {
|
||||||
case tomo.AlignMiddle:
|
case tomo.AlignMiddle:
|
||||||
offset = (hints.Bounds.Dy() - height) / 2
|
offset = (hints.Bounds.Dy() - height) / 2
|
||||||
case tomo.AlignEnd:
|
case tomo.AlignEnd:
|
||||||
offset = hints.Bounds.Dy() - height
|
offset = hints.Bounds.Dy() - height
|
||||||
}
|
}
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
box.SetBounds(box.Bounds().Add(image.Pt(0, offset)))
|
boxes.SetBounds(index, bounds[index].Add(image.Pt(0, offset)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (row Row) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
func (row Row) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||||
expands := func (index int) bool {
|
expands := func (index int) bool {
|
||||||
if index >= len(row) { return false }
|
if index >= len(row) { return false }
|
||||||
return row[index]
|
return row[index]
|
||||||
@ -119,13 +119,14 @@ func (row Row) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
// determine expanding box size
|
// determine expanding box size
|
||||||
expandingSize := 0.0
|
expandingSize := 0.0
|
||||||
if !hints.OverflowY {
|
if !hints.OverflowY {
|
||||||
gaps := len(boxes) - 1
|
gaps := boxes.Len() - 1
|
||||||
freeSpace := float64(hints.Bounds.Dx() - hints.Gap.X * gaps)
|
freeSpace := float64(hints.Bounds.Dx() - hints.Gap.X * gaps)
|
||||||
nExpanding := 0; for index, box := range boxes {
|
nExpanding := 0;
|
||||||
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
if expands(index) {
|
if expands(index) {
|
||||||
nExpanding ++
|
nExpanding ++
|
||||||
} else {
|
} else {
|
||||||
freeSpace -= float64(box.MinimumSize().X)
|
freeSpace -= float64(boxes.MinimumSize(index).X)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expandingSize = freeSpace / float64(nExpanding)
|
expandingSize = freeSpace / float64(nExpanding)
|
||||||
@ -134,8 +135,8 @@ func (row Row) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
// determine height
|
// determine height
|
||||||
height := 0
|
height := 0
|
||||||
if hints.OverflowY {
|
if hints.OverflowY {
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
minimum := box.MinimumSize()
|
minimum := boxes.MinimumSize(index)
|
||||||
if height < minimum.Y { height = minimum.Y }
|
if height < minimum.Y { height = minimum.Y }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -144,95 +145,76 @@ func (row Row) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
|
|
||||||
// arrange
|
// arrange
|
||||||
dot := hints.Bounds.Min
|
dot := hints.Bounds.Min
|
||||||
for index, box := range boxes {
|
bounds := make([]image.Rectangle, boxes.Len())
|
||||||
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
if index > 0 { dot.X += hints.Gap.X }
|
if index > 0 { dot.X += hints.Gap.X }
|
||||||
|
|
||||||
// determine width
|
// determine width
|
||||||
width := box.MinimumSize().X
|
width := boxes.MinimumSize(index).X
|
||||||
if hints.OverflowY {
|
if hints.OverflowY {
|
||||||
if box, ok := box.(tomo.ContentBox); ok {
|
width = boxes.RecommendedHeight(index, height)
|
||||||
width = box.RecommendedHeight(height)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if expands(index) {
|
if expands(index) {
|
||||||
width = int(expandingSize)
|
width = int(expandingSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set bounds
|
// store bounds
|
||||||
box.SetBounds(image.Rectangle {
|
bounds[index] = image.Rectangle {
|
||||||
Min: dot,
|
Min: dot,
|
||||||
Max: dot.Add(image.Pt(width, height)),
|
Max: dot.Add(image.Pt(width, height)),
|
||||||
})
|
}
|
||||||
dot.X += width
|
dot.X += width
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// align
|
||||||
width := dot.X - hints.Bounds.Min.X
|
width := dot.X - hints.Bounds.Min.X
|
||||||
offset := 0
|
offset := 0
|
||||||
|
|
||||||
switch hints.AlignX {
|
switch hints.AlignX {
|
||||||
case tomo.AlignMiddle:
|
case tomo.AlignMiddle:
|
||||||
offset = (hints.Bounds.Dx() - width) / 2
|
offset = (hints.Bounds.Dx() - width) / 2
|
||||||
case tomo.AlignEnd:
|
case tomo.AlignEnd:
|
||||||
offset = hints.Bounds.Dx() - width
|
offset = hints.Bounds.Dx() - width
|
||||||
}
|
}
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
box.SetBounds(box.Bounds().Add(image.Pt(offset, 0)))
|
boxes.SetBounds(index, bounds[index].Add(image.Pt(offset, 0)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (column Column) RecommendedHeight (hints tomo.LayoutHints, boxes []tomo.Box, width int) int {
|
func (column Column) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
|
||||||
height := 0
|
height := 0
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
if box, ok := box.(tomo.ContentBox); ok {
|
height += boxes.RecommendedHeight(index, width)
|
||||||
height += box.RecommendedHeight(width)
|
|
||||||
} else {
|
|
||||||
height += box.MinimumSize().Y
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
height += hints.Gap.Y * (len(boxes) - 1)
|
height += hints.Gap.Y * (boxes.Len() - 1)
|
||||||
return height
|
return height
|
||||||
}
|
}
|
||||||
|
|
||||||
func (row Row) RecommendedHeight (hints tomo.LayoutHints, boxes []tomo.Box, width int) int {
|
func (row Row) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
|
||||||
height := 0
|
height := 0
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
minimum := box.MinimumSize()
|
minimum := boxes.MinimumSize(index)
|
||||||
boxHeight := 0
|
boxHeight := boxes.RecommendedHeight(index, minimum.X)
|
||||||
if box, ok := box.(tomo.ContentBox); ok {
|
|
||||||
boxHeight = box.RecommendedHeight(minimum.X)
|
|
||||||
} else {
|
|
||||||
boxHeight = minimum.Y
|
|
||||||
}
|
|
||||||
if boxHeight > height { height = boxHeight }
|
if boxHeight > height { height = boxHeight }
|
||||||
}
|
}
|
||||||
return height
|
return height
|
||||||
}
|
}
|
||||||
|
|
||||||
func (column Column) RecommendedWidth (hints tomo.LayoutHints, boxes []tomo.Box, height int) int {
|
func (column Column) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
|
||||||
width := 0
|
width := 0
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
minimum := box.MinimumSize()
|
minimum := boxes.MinimumSize(index)
|
||||||
boxWidth := 0
|
boxWidth := boxes.RecommendedWidth(index, minimum.Y)
|
||||||
if box, ok := box.(tomo.ContentBox); ok {
|
|
||||||
boxWidth = box.RecommendedHeight(minimum.Y)
|
|
||||||
} else {
|
|
||||||
boxWidth = minimum.X
|
|
||||||
}
|
|
||||||
if boxWidth > width { width = boxWidth }
|
if boxWidth > width { width = boxWidth }
|
||||||
}
|
}
|
||||||
return width
|
return width
|
||||||
}
|
}
|
||||||
|
|
||||||
func (row Row) RecommendedWidth (hints tomo.LayoutHints, boxes []tomo.Box, height int) int {
|
func (row Row) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
|
||||||
width := 0
|
width := 0
|
||||||
for _, box := range boxes {
|
for index := 0; index < boxes.Len(); index ++ {
|
||||||
if box, ok := box.(tomo.ContentBox); ok {
|
width += boxes.RecommendedWidth(index, height)
|
||||||
width += box.RecommendedWidth(height)
|
|
||||||
} else {
|
|
||||||
width += box.MinimumSize().X
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
width += hints.Gap.X * (len(boxes) - 1)
|
width += hints.Gap.X * (boxes.Len() - 1)
|
||||||
return width
|
return width
|
||||||
}
|
}
|
||||||
|
11
menu.go
11
menu.go
@ -40,15 +40,15 @@ func NewMenu (anchor tomo.Object, items ...tomo.Object) (*Menu, error) {
|
|||||||
|
|
||||||
if !menu.torn {
|
if !menu.torn {
|
||||||
menu.tearLine = tomo.NewBox()
|
menu.tearLine = tomo.NewBox()
|
||||||
menu.tearLine.SetRole(tomo.R("objects", "TearLine", ""))
|
menu.tearLine.SetRole(tomo.R("objects", "TearLine"))
|
||||||
menu.tearLine.SetFocusable(true)
|
menu.tearLine.SetFocusable(true)
|
||||||
menu.tearLine.OnKeyUp(func (key input.Key, numberPad bool) {
|
menu.tearLine.OnKeyUp(func (catch func (), key input.Key, numberPad bool) {
|
||||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||||
menu.TearOff()
|
menu.TearOff()
|
||||||
})
|
})
|
||||||
menu.tearLine.OnMouseUp(func (button input.Button) {
|
menu.tearLine.OnButtonUp(func (catch func (), button input.Button) {
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
if menu.tearLine.MousePosition().In(menu.tearLine.Bounds()) {
|
if menu.tearLine.Window().MousePosition().In(menu.tearLine.Bounds()) {
|
||||||
menu.TearOff()
|
menu.TearOff()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -65,7 +65,8 @@ func NewMenu (anchor tomo.Object, items ...tomo.Object) (*Menu, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu.rootContainer.SetRole(tomo.R("objects", "Container", "menu"))
|
menu.rootContainer.SetRole(tomo.R("objects", "Container"))
|
||||||
|
menu.rootContainer.SetTag("menu", true)
|
||||||
|
|
||||||
menu.Window.SetRoot(menu.rootContainer)
|
menu.Window.SetRoot(menu.rootContainer)
|
||||||
return menu, nil
|
return menu, nil
|
||||||
|
24
menuitem.go
24
menuitem.go
@ -25,19 +25,18 @@ func NewMenuItem (text string) *MenuItem {
|
|||||||
label: NewLabel(text),
|
label: NewLabel(text),
|
||||||
icon: NewIcon("", tomo.IconSizeSmall),
|
icon: NewIcon("", tomo.IconSizeSmall),
|
||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "MenuItem", ""))
|
box.SetRole(tomo.R("objects", "MenuItem"))
|
||||||
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
box.SetLayout(layouts.Row { false, true })
|
box.SetLayout(layouts.Row { false, true })
|
||||||
|
|
||||||
box.Add(box.icon)
|
box.Add(box.icon)
|
||||||
box.Add(box.label)
|
box.Add(box.label)
|
||||||
|
|
||||||
box.CaptureDND(true)
|
box.CatchDND(true)
|
||||||
box.CaptureMouse(true)
|
box.CatchMouse(true)
|
||||||
box.CaptureScroll(true)
|
|
||||||
box.CaptureKeyboard(true)
|
|
||||||
|
|
||||||
box.OnMouseUp(box.handleMouseUp)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
box.OnKeyUp(box.handleKeyUp)
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
box.SetFocusable(true)
|
box.SetFocusable(true)
|
||||||
return box
|
return box
|
||||||
@ -60,14 +59,19 @@ func (this *MenuItem) OnClick (callback func ()) event.Cookie {
|
|||||||
return this.on.click.Connect(callback)
|
return this.on.click.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MenuItem) handleKeyUp (key input.Key, numberPad bool) {
|
func (this *MenuItem) handleKeyUp (catch func(), key input.Key, numberPad bool) {
|
||||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||||
this.on.click.Broadcast()
|
this.on.click.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MenuItem) handleMouseUp (button input.Button) {
|
func (this *MenuItem) handleButtonDown (catch func(), button input.Button) {
|
||||||
|
catch()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MenuItem) handleButtonUp (catch func(), button input.Button) {
|
||||||
|
catch()
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
if this.MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.on.click.Broadcast()
|
this.on.click.Broadcast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ func NewNumberInput (value float64) *NumberInput {
|
|||||||
increment: NewButton(""),
|
increment: NewButton(""),
|
||||||
decrement: NewButton(""),
|
decrement: NewButton(""),
|
||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "NumberInput", ""))
|
box.SetRole(tomo.R("objects", "NumberInput"))
|
||||||
box.Add(box.input)
|
box.Add(box.input)
|
||||||
box.Add(box.decrement)
|
box.Add(box.decrement)
|
||||||
box.Add(box.increment)
|
box.Add(box.increment)
|
||||||
@ -38,10 +38,8 @@ func NewNumberInput (value float64) *NumberInput {
|
|||||||
|
|
||||||
box.SetValue(value)
|
box.SetValue(value)
|
||||||
|
|
||||||
box.CaptureScroll(true)
|
|
||||||
box.CaptureKeyboard(true)
|
|
||||||
|
|
||||||
box.OnScroll(box.handleScroll)
|
box.OnScroll(box.handleScroll)
|
||||||
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
box.OnKeyDown(box.handleKeyDown)
|
box.OnKeyDown(box.handleKeyDown)
|
||||||
box.input.OnConfirm(box.handleConfirm)
|
box.input.OnConfirm(box.handleConfirm)
|
||||||
box.input.OnValueChange(box.on.valueChange.Broadcast)
|
box.input.OnValueChange(box.on.valueChange.Broadcast)
|
||||||
@ -78,19 +76,28 @@ func (this *NumberInput) shift (by int) {
|
|||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NumberInput) handleKeyDown (key input.Key, numpad bool) {
|
func (this *NumberInput) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
||||||
switch key {
|
switch key {
|
||||||
case input.KeyUp: this.shift(1)
|
case input.KeyUp:
|
||||||
case input.KeyDown: this.shift(-1)
|
this.shift(1)
|
||||||
default: this.input.handleKeyDown(key, numpad)
|
catch()
|
||||||
|
case input.KeyDown:
|
||||||
|
this.shift(-1)
|
||||||
|
catch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NumberInput) handleScroll (x, y float64) {
|
func (this *NumberInput) handleKeyUp (catch func (), key input.Key, numpad bool) {
|
||||||
|
switch key {
|
||||||
|
case input.KeyUp: catch()
|
||||||
|
case input.KeyDown: catch()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NumberInput) handleScroll (catch func (), x, y float64) {
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
|
catch()
|
||||||
this.shift(-int(math.Round(y)))
|
this.shift(-int(math.Round(y)))
|
||||||
} else {
|
|
||||||
this.input.handleScroll(x, y)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
107
scrollbar.go
107
scrollbar.go
@ -35,19 +35,20 @@ func newScrollbar (orient string) *Scrollbar {
|
|||||||
this.Add(this.handle)
|
this.Add(this.handle)
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
|
|
||||||
this.CaptureDND(true)
|
this.CatchDND(true)
|
||||||
this.CaptureMouse(true)
|
this.CatchMouse(true)
|
||||||
this.CaptureScroll(true)
|
|
||||||
this.CaptureKeyboard(true)
|
|
||||||
|
|
||||||
|
this.OnKeyUp(this.handleKeyUp)
|
||||||
this.OnKeyDown(this.handleKeyDown)
|
this.OnKeyDown(this.handleKeyDown)
|
||||||
this.OnMouseDown(this.handleMouseDown)
|
this.OnButtonDown(this.handleButtonDown)
|
||||||
this.OnMouseUp(this.handleMouseUp)
|
this.OnButtonUp(this.handleButtonUp)
|
||||||
this.OnMouseMove(this.handleMouseMove)
|
this.OnMouseMove(this.handleMouseMove)
|
||||||
this.OnScroll(this.handleScroll)
|
this.OnScroll(this.handleScroll)
|
||||||
|
|
||||||
this.handle.SetRole(tomo.R("objects", "SliderHandle", orient))
|
this.handle.SetRole(tomo.R("objects", "SliderHandle"))
|
||||||
this.SetRole(tomo.R("objects", "Slider", orient))
|
this.handle.SetTag(orient, true)
|
||||||
|
this.SetRole(tomo.R("objects", "Slider"))
|
||||||
|
this.SetTag(orient, true)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,22 +121,48 @@ func (this *Scrollbar) OnValueChange (callback func ()) event.Cookie {
|
|||||||
return this.on.valueChange.Connect(callback)
|
return this.on.valueChange.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) {
|
// PageSize returns the scroll distance of a page.
|
||||||
|
func (this *Scrollbar) PageSize () int {
|
||||||
|
if this.layout.linked == nil { return 0 }
|
||||||
|
viewport := this.layout.linked.GetBox().InnerBounds()
|
||||||
|
if this.layout.vertical {
|
||||||
|
return viewport.Dy()
|
||||||
|
} else {
|
||||||
|
return viewport.Dx()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// StepSize returns the scroll distance of a step.
|
||||||
|
func (this *Scrollbar) StepSize () int {
|
||||||
|
// FIXME: this should not be hardcoded, need to get base font metrics
|
||||||
|
// from tomo somehow. should be (emspace, lineheight)
|
||||||
|
return 16
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Scrollbar) handleKeyUp (catch func (), key input.Key, numpad bool) {
|
||||||
|
catch()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Scrollbar) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
||||||
|
catch()
|
||||||
|
|
||||||
var increment float64; if this.layout.vertical {
|
var increment float64; if this.layout.vertical {
|
||||||
increment = -0.05
|
increment = -0.05
|
||||||
} else {
|
} else {
|
||||||
increment = 0.05
|
increment = 0.05
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modifiers := this.Window().Modifiers()
|
||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case input.KeyUp, input.KeyLeft:
|
case input.KeyUp, input.KeyLeft:
|
||||||
if this.Modifiers().Alt {
|
if modifiers.Alt {
|
||||||
this.SetValue(0)
|
this.SetValue(0)
|
||||||
} else {
|
} else {
|
||||||
this.SetValue(this.Value() - increment)
|
this.SetValue(this.Value() - increment)
|
||||||
}
|
}
|
||||||
case input.KeyDown, input.KeyRight:
|
case input.KeyDown, input.KeyRight:
|
||||||
if this.Modifiers().Alt {
|
if modifiers.Alt {
|
||||||
this.SetValue(1)
|
this.SetValue(1)
|
||||||
} else {
|
} else {
|
||||||
this.SetValue(this.Value() + increment)
|
this.SetValue(this.Value() + increment)
|
||||||
@ -147,8 +174,10 @@ func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleMouseDown (button input.Button) {
|
func (this *Scrollbar) handleButtonDown (catch func (), button input.Button) {
|
||||||
pointer := this.MousePosition()
|
catch()
|
||||||
|
|
||||||
|
pointer := this.Window().MousePosition()
|
||||||
handle := this.handle.Bounds()
|
handle := this.handle.Bounds()
|
||||||
|
|
||||||
within := pointer.In(handle)
|
within := pointer.In(handle)
|
||||||
@ -173,20 +202,21 @@ func (this *Scrollbar) handleMouseDown (button input.Button) {
|
|||||||
}
|
}
|
||||||
case input.ButtonMiddle:
|
case input.ButtonMiddle:
|
||||||
if above {
|
if above {
|
||||||
this.scrollBy(this.pageSize())
|
this.scrollBy(this.PageSize())
|
||||||
} else {
|
} else {
|
||||||
this.scrollBy(-this.pageSize())
|
this.scrollBy(-this.PageSize())
|
||||||
}
|
}
|
||||||
case input.ButtonRight:
|
case input.ButtonRight:
|
||||||
if above {
|
if above {
|
||||||
this.scrollBy(this.stepSize())
|
this.scrollBy(this.StepSize())
|
||||||
} else {
|
} else {
|
||||||
this.scrollBy(-this.stepSize())
|
this.scrollBy(-this.StepSize())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleMouseUp (button input.Button) {
|
func (this *Scrollbar) handleButtonUp (catch func (), button input.Button) {
|
||||||
|
catch()
|
||||||
if button != input.ButtonLeft || !this.dragging { return }
|
if button != input.ButtonLeft || !this.dragging { return }
|
||||||
this.dragging = false
|
this.dragging = false
|
||||||
}
|
}
|
||||||
@ -196,7 +226,8 @@ func (this *Scrollbar) handleMouseMove () {
|
|||||||
this.drag()
|
this.drag()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleScroll (x, y float64) {
|
func (this *Scrollbar) handleScroll (catch func(), x, y float64) {
|
||||||
|
catch()
|
||||||
if this.layout.linked == nil { return }
|
if this.layout.linked == nil { return }
|
||||||
this.layout.linked.ScrollTo (
|
this.layout.linked.ScrollTo (
|
||||||
this.layout.linked.ContentBounds().Min.
|
this.layout.linked.ContentBounds().Min.
|
||||||
@ -204,7 +235,7 @@ func (this *Scrollbar) handleScroll (x, y float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) drag () {
|
func (this *Scrollbar) drag () {
|
||||||
pointer := this.MousePosition().Sub(this.dragOffset)
|
pointer := this.Window().MousePosition().Sub(this.dragOffset)
|
||||||
gutter := this.InnerBounds()
|
gutter := this.InnerBounds()
|
||||||
handle := this.handle.Bounds()
|
handle := this.handle.Bounds()
|
||||||
|
|
||||||
@ -229,22 +260,6 @@ func (this *Scrollbar) fallbackDragOffset () image.Point {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) pageSize () int {
|
|
||||||
if this.layout.linked == nil { return 0 }
|
|
||||||
viewport := this.layout.linked.GetBox().InnerBounds()
|
|
||||||
if this.layout.vertical {
|
|
||||||
return viewport.Dy()
|
|
||||||
} else {
|
|
||||||
return viewport.Dx()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Scrollbar) stepSize () int {
|
|
||||||
// FIXME: this should not be hardcoded, need to get base font metrics
|
|
||||||
// from tomo.somehow. should be (emspace, lineheight)
|
|
||||||
return 16
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Scrollbar) scrollBy (distance int) {
|
func (this *Scrollbar) scrollBy (distance int) {
|
||||||
if this.layout.linked == nil { return }
|
if this.layout.linked == nil { return }
|
||||||
var vector image.Point; if this.layout.vertical {
|
var vector image.Point; if this.layout.vertical {
|
||||||
@ -283,14 +298,14 @@ type scrollbarLayout struct {
|
|||||||
linked tomo.ContentObject
|
linked tomo.ContentObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scrollbarLayout) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
func (scrollbarLayout) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
|
||||||
if len(boxes) != 1 { return image.Pt(0, 0) }
|
if boxes.Len() != 1 { return image.Pt(0, 0) }
|
||||||
return boxes[0].MinimumSize()
|
return boxes.MinimumSize(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||||
if len(boxes) != 1 { return }
|
if boxes.Len() != 1 { return }
|
||||||
handle := image.Rectangle { Max: boxes[0].MinimumSize() }
|
handle := image.Rectangle { Max: boxes.MinimumSize(0) }
|
||||||
gutter := hints.Bounds
|
gutter := hints.Bounds
|
||||||
|
|
||||||
var gutterLength float64;
|
var gutterLength float64;
|
||||||
@ -311,7 +326,7 @@ func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
// and we shouldn't be adding and removing boxes, so this is
|
// and we shouldn't be adding and removing boxes, so this is
|
||||||
// really the only good way to hide things.
|
// really the only good way to hide things.
|
||||||
// TODO perhaps have a "Hidden" rectangle in the Tomo API?
|
// TODO perhaps have a "Hidden" rectangle in the Tomo API?
|
||||||
boxes[0].SetBounds(image.Rect(-16, -16, 0, 0))
|
boxes.SetBounds(0, image.Rect(-32, -32, -16, -16))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if this.vertical {
|
if this.vertical {
|
||||||
@ -331,15 +346,15 @@ func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
handle = handle.Sub(handleOffset).Add(gutter.Min)
|
handle = handle.Sub(handleOffset).Add(gutter.Min)
|
||||||
|
|
||||||
// place handle
|
// place handle
|
||||||
boxes[0].SetBounds(handle)
|
boxes.SetBounds(0, handle)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this scrollbarLayout) RecommendedHeight (hints tomo.LayoutHints, boxes []tomo.Box, width int) int {
|
func (this scrollbarLayout) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
|
||||||
return this.MinimumSize(hints, boxes).X
|
return this.MinimumSize(hints, boxes).X
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this scrollbarLayout) RecommendedWidth (hints tomo.LayoutHints, boxes []tomo.Box, height int) int {
|
func (this scrollbarLayout) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
|
||||||
return this.MinimumSize(hints, boxes).Y
|
return this.MinimumSize(hints, boxes).Y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@ package objects
|
|||||||
|
|
||||||
import "image"
|
import "image"
|
||||||
import "git.tebibyte.media/tomo/tomo"
|
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/tomo/event"
|
||||||
|
import "git.tebibyte.media/tomo/objects/layouts"
|
||||||
|
|
||||||
// ScrollSide determines which Scrollbars are active in a ScrollContainer.
|
// ScrollSide determines which Scrollbars are active in a ScrollContainer.
|
||||||
type ScrollSide int; const (
|
type ScrollSide int; const (
|
||||||
@ -38,7 +40,10 @@ func (sides ScrollSide) String () string {
|
|||||||
// ScrollContainer couples a ContentBox with one or two Scrollbars.
|
// ScrollContainer couples a ContentBox with one or two Scrollbars.
|
||||||
type ScrollContainer struct {
|
type ScrollContainer struct {
|
||||||
tomo.ContainerBox
|
tomo.ContainerBox
|
||||||
layout *scrollContainerLayout
|
|
||||||
|
root tomo.ContentObject
|
||||||
|
horizontal *Scrollbar
|
||||||
|
vertical *Scrollbar
|
||||||
|
|
||||||
horizontalCookie event.Cookie
|
horizontalCookie event.Cookie
|
||||||
verticalCookie event.Cookie
|
verticalCookie event.Cookie
|
||||||
@ -52,22 +57,23 @@ type ScrollContainer struct {
|
|||||||
func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
||||||
this := &ScrollContainer {
|
this := &ScrollContainer {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
layout: &scrollContainerLayout { },
|
|
||||||
}
|
}
|
||||||
if sides.Vertical() {
|
if sides.Vertical() {
|
||||||
this.layout.vertical = NewVerticalScrollbar()
|
this.vertical = NewVerticalScrollbar()
|
||||||
this.layout.vertical.OnValueChange(this.handleValueChange)
|
this.vertical.OnValueChange(this.handleValueChange)
|
||||||
this.Add(this.layout.vertical)
|
this.Add(this.vertical)
|
||||||
}
|
}
|
||||||
if sides.Horizontal() {
|
if sides.Horizontal() {
|
||||||
this.layout.horizontal = NewHorizontalScrollbar()
|
this.horizontal = NewHorizontalScrollbar()
|
||||||
this.layout.horizontal.OnValueChange(this.handleValueChange)
|
this.horizontal.OnValueChange(this.handleValueChange)
|
||||||
this.Add(this.layout.horizontal)
|
this.Add(this.horizontal)
|
||||||
}
|
}
|
||||||
this.CaptureScroll(true)
|
|
||||||
this.OnScroll(this.handleScroll)
|
this.OnScroll(this.handleScroll)
|
||||||
this.SetRole(tomo.R("objects", "ScrollContainer", sides.String()))
|
this.OnKeyDown(this.handleKeyDown)
|
||||||
this.SetLayout(this.layout)
|
this.OnKeyUp(this.handleKeyUp)
|
||||||
|
this.SetRole(tomo.R("objects", "ScrollContainer"))
|
||||||
|
this.SetTag(sides.String(), true)
|
||||||
|
this.SetLayout(layouts.NewGrid(true, false)(true, false))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,9 +81,9 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
|||||||
// 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.ContentObject) {
|
func (this *ScrollContainer) SetRoot (root tomo.ContentObject) {
|
||||||
if this.layout.root != nil {
|
if this.root != nil {
|
||||||
// remove root and close cookies
|
// remove root and close cookies
|
||||||
this.Remove(this.layout.root)
|
this.Remove(this.root)
|
||||||
if this.horizontalCookie != nil {
|
if this.horizontalCookie != nil {
|
||||||
this.horizontalCookie.Close()
|
this.horizontalCookie.Close()
|
||||||
this.horizontalCookie = nil
|
this.horizontalCookie = nil
|
||||||
@ -87,24 +93,24 @@ func (this *ScrollContainer) SetRoot (root tomo.ContentObject) {
|
|||||||
this.verticalCookie = nil
|
this.verticalCookie = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.layout.root = root
|
this.root = root
|
||||||
if root != nil {
|
if root != nil {
|
||||||
// insert root at the beginning (for keynav)
|
// insert root at the beginning (for keynav)
|
||||||
switch {
|
switch {
|
||||||
case this.layout.vertical != nil:
|
case this.vertical != nil:
|
||||||
this.Insert(root, this.layout.vertical)
|
this.Insert(root, this.vertical)
|
||||||
case this.layout.horizontal != nil:
|
case this.horizontal != nil:
|
||||||
this.Insert(root, this.layout.horizontal)
|
this.Insert(root, this.horizontal)
|
||||||
default:
|
default:
|
||||||
this.Add(root)
|
this.Add(root)
|
||||||
}
|
}
|
||||||
|
|
||||||
// link root and remember cookies
|
// link root and remember cookies
|
||||||
if this.layout.horizontal != nil {
|
if this.horizontal != nil {
|
||||||
this.horizontalCookie = this.layout.horizontal.Link(root)
|
this.horizontalCookie = this.horizontal.Link(root)
|
||||||
}
|
}
|
||||||
if this.layout.vertical != nil {
|
if this.vertical != nil {
|
||||||
this.verticalCookie = this.layout.vertical.Link(root)
|
this.verticalCookie = this.vertical.Link(root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,11 +118,11 @@ func (this *ScrollContainer) SetRoot (root tomo.ContentObject) {
|
|||||||
// Value returns the horizontal and vertical scrollbar values where 0 is all the
|
// Value returns the horizontal and vertical scrollbar values where 0 is all the
|
||||||
// way to the left/top, and 1 is all the way to the right/bottom.
|
// way to the left/top, and 1 is all the way to the right/bottom.
|
||||||
func (this *ScrollContainer) Value () (x, y float64) {
|
func (this *ScrollContainer) Value () (x, y float64) {
|
||||||
if this.layout.horizontal != nil {
|
if this.horizontal != nil {
|
||||||
x = this.layout.horizontal.Value()
|
x = this.horizontal.Value()
|
||||||
}
|
}
|
||||||
if this.layout.vertical != nil {
|
if this.vertical != nil {
|
||||||
y = this.layout.vertical.Value()
|
y = this.vertical.Value()
|
||||||
}
|
}
|
||||||
return x, y
|
return x, y
|
||||||
}
|
}
|
||||||
@ -124,11 +130,11 @@ func (this *ScrollContainer) Value () (x, y float64) {
|
|||||||
// SetValue sets the horizontal and vertical scrollbar values where 0 is all the
|
// SetValue sets the horizontal and vertical scrollbar values where 0 is all the
|
||||||
// way to the left/top, and 1 is all the way to the right/bottom.
|
// way to the left/top, and 1 is all the way to the right/bottom.
|
||||||
func (this *ScrollContainer) SetValue (x, y float64) {
|
func (this *ScrollContainer) SetValue (x, y float64) {
|
||||||
if this.layout.horizontal != nil {
|
if this.horizontal != nil {
|
||||||
this.layout.horizontal.SetValue(x)
|
this.horizontal.SetValue(x)
|
||||||
}
|
}
|
||||||
if this.layout.vertical != nil {
|
if this.vertical != nil {
|
||||||
this.layout.vertical.SetValue(y)
|
this.vertical.SetValue(y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,77 +144,74 @@ func (this *ScrollContainer) OnValueChange (callback func ()) event.Cookie {
|
|||||||
return this.on.valueChange.Connect(callback)
|
return this.on.valueChange.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PageSize returns the scroll distance of a page.
|
||||||
|
func (this *ScrollContainer) PageSize () image.Point {
|
||||||
|
page := image.Point { }
|
||||||
|
if this.horizontal != nil {
|
||||||
|
page.X = this.horizontal.PageSize()
|
||||||
|
}
|
||||||
|
if this.vertical != nil {
|
||||||
|
page.Y = this.vertical.PageSize()
|
||||||
|
}
|
||||||
|
return page
|
||||||
|
}
|
||||||
|
|
||||||
|
// StepSize returns the scroll distance of a step.
|
||||||
|
func (this *ScrollContainer) StepSize () image.Point {
|
||||||
|
page := image.Point { }
|
||||||
|
if this.horizontal != nil {
|
||||||
|
page.X = this.horizontal.StepSize()
|
||||||
|
}
|
||||||
|
if this.vertical != nil {
|
||||||
|
page.Y = this.vertical.StepSize()
|
||||||
|
}
|
||||||
|
return page
|
||||||
|
}
|
||||||
|
|
||||||
func (this *ScrollContainer) handleValueChange () {
|
func (this *ScrollContainer) handleValueChange () {
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ScrollContainer) handleScroll (x, y float64) {
|
func (this *ScrollContainer) handleScroll (catch func (), x, y float64) {
|
||||||
if this.layout.root == nil { return }
|
catch()
|
||||||
this.layout.root.ScrollTo (
|
if this.root == nil { return }
|
||||||
this.layout.root.ContentBounds().Min.
|
this.scrollBy(image.Pt(int(x), int(y)))
|
||||||
Sub(image.Pt(int(x), int(y))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove this and replace it with something from the layouts package
|
func (this *ScrollContainer) scrollBy (vector image.Point) {
|
||||||
type scrollContainerLayout struct {
|
if this.root == nil { return }
|
||||||
root tomo.ContentObject
|
this.root.ScrollTo (
|
||||||
horizontal *Scrollbar
|
this.root.ContentBounds().Min.
|
||||||
vertical *Scrollbar
|
Sub(vector))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *scrollContainerLayout) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
func (this *ScrollContainer) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
||||||
var minimum image.Point; if this.root != nil {
|
modifiers := this.Window().Modifiers()
|
||||||
minimum = this.root.GetBox().MinimumSize()
|
vector := image.Point { }
|
||||||
|
switch key {
|
||||||
|
case input.KeyPageUp:
|
||||||
|
catch()
|
||||||
|
if modifiers.Shift {
|
||||||
|
vector.X -= this.PageSize().X
|
||||||
|
} else {
|
||||||
|
vector.Y -= this.PageSize().Y
|
||||||
|
}
|
||||||
|
case input.KeyPageDown:
|
||||||
|
catch()
|
||||||
|
if modifiers.Shift {
|
||||||
|
vector.X += this.PageSize().X
|
||||||
|
} else {
|
||||||
|
vector.Y += this.PageSize().Y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if this.horizontal != nil {
|
if vector != (image.Point { }) {
|
||||||
minimum.Y += this.horizontal.MinimumSize().Y
|
this.scrollBy(vector)
|
||||||
}
|
|
||||||
if this.vertical != nil {
|
|
||||||
minimum.X += this.vertical.MinimumSize().X
|
|
||||||
minimum.Y = max(minimum.Y, this.vertical.MinimumSize().Y)
|
|
||||||
}
|
|
||||||
if this.horizontal != nil {
|
|
||||||
minimum.X = max(minimum.X, this.horizontal.MinimumSize().X)
|
|
||||||
}
|
|
||||||
return minimum
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *scrollContainerLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|
||||||
rootBounds := hints.Bounds
|
|
||||||
if this.horizontal != nil {
|
|
||||||
rootBounds.Max.Y -= this.horizontal.MinimumSize().Y
|
|
||||||
}
|
|
||||||
if this.vertical != nil {
|
|
||||||
rootBounds.Max.X -= this.vertical.MinimumSize().X
|
|
||||||
}
|
|
||||||
if this.root != nil {
|
|
||||||
this.root.GetBox().SetBounds(rootBounds)
|
|
||||||
}
|
|
||||||
if this.horizontal != nil {
|
|
||||||
this.horizontal.SetBounds(image.Rect (
|
|
||||||
hints.Bounds.Min.X,
|
|
||||||
rootBounds.Max.Y,
|
|
||||||
rootBounds.Max.X,
|
|
||||||
hints.Bounds.Max.Y))
|
|
||||||
}
|
|
||||||
if this.vertical != nil {
|
|
||||||
this.vertical.SetBounds(image.Rect (
|
|
||||||
rootBounds.Max.X,
|
|
||||||
hints.Bounds.Min.Y,
|
|
||||||
hints.Bounds.Max.X,
|
|
||||||
rootBounds.Max.Y))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *scrollContainerLayout) RecommendedHeight (hints tomo.LayoutHints, boxes []tomo.Box, width int) int {
|
func (this *ScrollContainer) handleKeyUp (catch func (), key input.Key, numpad bool) {
|
||||||
return this.MinimumSize(hints, boxes).X
|
switch key {
|
||||||
}
|
case input.KeyPageUp: catch()
|
||||||
|
case input.KeyPageDown: catch()
|
||||||
func (this *scrollContainerLayout) RecommendedWidth (hints tomo.LayoutHints, boxes []tomo.Box, height int) int {
|
}
|
||||||
return this.MinimumSize(hints, boxes).Y
|
|
||||||
}
|
|
||||||
|
|
||||||
func max (x, y int) int {
|
|
||||||
if x > y { return x }
|
|
||||||
return y
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,6 @@ func NewSeparator () *Separator {
|
|||||||
this := &Separator {
|
this := &Separator {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
this.SetRole(tomo.R("objects", "Separator", ""))
|
this.SetRole(tomo.R("objects", "Separator"))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
76
slider.go
76
slider.go
@ -43,20 +43,21 @@ func newSlider (orient string, value float64) *Slider {
|
|||||||
this.Add(this.handle)
|
this.Add(this.handle)
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
|
|
||||||
this.CaptureDND(true)
|
this.CatchDND(true)
|
||||||
this.CaptureMouse(true)
|
this.CatchMouse(true)
|
||||||
this.CaptureScroll(true)
|
|
||||||
this.CaptureKeyboard(true)
|
|
||||||
|
|
||||||
this.SetValue(value)
|
this.SetValue(value)
|
||||||
|
this.OnKeyUp(this.handleKeyUp)
|
||||||
this.OnKeyDown(this.handleKeyDown)
|
this.OnKeyDown(this.handleKeyDown)
|
||||||
this.OnMouseDown(this.handleMouseDown)
|
this.OnButtonDown(this.handleButtonDown)
|
||||||
this.OnMouseUp(this.handleMouseUp)
|
this.OnButtonUp(this.handleButtonUp)
|
||||||
this.OnMouseMove(this.handleMouseMove)
|
this.OnMouseMove(this.handleMouseMove)
|
||||||
this.OnScroll(this.handleScroll)
|
this.OnScroll(this.handleScroll)
|
||||||
|
|
||||||
this.handle.SetRole(tomo.R("objects", "SliderHandle", orient))
|
this.handle.SetRole(tomo.R("objects", "SliderHandle"))
|
||||||
this.SetRole(tomo.R("objects", "Slider", orient))
|
this.handle.SetTag(orient, true)
|
||||||
|
this.SetRole(tomo.R("objects", "Slider"))
|
||||||
|
this.SetTag(orient, true)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +97,9 @@ func (this *Slider) OnConfirm (callback func ()) event.Cookie {
|
|||||||
return this.on.confirm.Connect(callback)
|
return this.on.confirm.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleKeyDown (key input.Key, numpad bool) {
|
func (this *Slider) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
||||||
|
catch()
|
||||||
|
|
||||||
var increment float64; if this.layout.vertical {
|
var increment float64; if this.layout.vertical {
|
||||||
increment = -0.05
|
increment = -0.05
|
||||||
} else {
|
} else {
|
||||||
@ -105,14 +108,14 @@ func (this *Slider) handleKeyDown (key input.Key, numpad bool) {
|
|||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case input.KeyUp, input.KeyLeft:
|
case input.KeyUp, input.KeyLeft:
|
||||||
if this.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)
|
||||||
}
|
}
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
case input.KeyDown, input.KeyRight:
|
case input.KeyDown, input.KeyRight:
|
||||||
if this.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)
|
||||||
@ -127,8 +130,14 @@ func (this *Slider) handleKeyDown (key input.Key, numpad bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleMouseDown (button input.Button) {
|
func (this *Slider) handleKeyUp (catch func (), key input.Key, numpad bool) {
|
||||||
pointer := this.MousePosition()
|
catch()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Slider) handleButtonDown (catch func (), button input.Button) {
|
||||||
|
catch()
|
||||||
|
|
||||||
|
pointer := this.Window().MousePosition()
|
||||||
handle := this.handle.Bounds()
|
handle := this.handle.Bounds()
|
||||||
|
|
||||||
within := pointer.In(handle)
|
within := pointer.In(handle)
|
||||||
@ -174,7 +183,8 @@ func (this *Slider) handleMouseDown (button input.Button) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleMouseUp (button input.Button) {
|
func (this *Slider) handleButtonUp (catch func (), button input.Button) {
|
||||||
|
catch()
|
||||||
if button != input.ButtonLeft || !this.dragging { return }
|
if button != input.ButtonLeft || !this.dragging { return }
|
||||||
this.dragging = false
|
this.dragging = false
|
||||||
this.on.confirm.Broadcast()
|
this.on.confirm.Broadcast()
|
||||||
@ -185,7 +195,7 @@ func (this *Slider) handleMouseMove () {
|
|||||||
this.drag()
|
this.drag()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleScroll (x, y float64) {
|
func (this *Slider) handleScroll (catch func (), x, y float64) {
|
||||||
delta := (x + y) * 0.005
|
delta := (x + y) * 0.005
|
||||||
this.SetValue(this.Value() + delta)
|
this.SetValue(this.Value() + delta)
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
@ -193,7 +203,7 @@ func (this *Slider) handleScroll (x, y float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) drag () {
|
func (this *Slider) drag () {
|
||||||
pointer := this.MousePosition().Sub(this.dragOffset)
|
pointer := this.Window().MousePosition().Sub(this.dragOffset)
|
||||||
gutter := this.InnerBounds()
|
gutter := this.InnerBounds()
|
||||||
handle := this.handle.Bounds()
|
handle := this.handle.Bounds()
|
||||||
|
|
||||||
@ -225,39 +235,37 @@ type sliderLayout struct {
|
|||||||
value float64
|
value float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sliderLayout) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
func (sliderLayout) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
|
||||||
if len(boxes) != 1 { return image.Pt(0, 0) }
|
if boxes.Len() != 1 { return image.Pt(0, 0) }
|
||||||
return boxes[0].MinimumSize()
|
return boxes.MinimumSize(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this sliderLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
func (this sliderLayout) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||||
if len(boxes) != 1 { return }
|
if boxes.Len() != 1 { return }
|
||||||
handle := image.Rectangle { Max: boxes[0].MinimumSize() }
|
handle := image.Rectangle { Max: boxes.MinimumSize(0) }
|
||||||
gutter := hints.Bounds
|
gutter := hints.Bounds
|
||||||
|
|
||||||
if this.vertical {
|
if this.vertical {
|
||||||
height := gutter.Dy() - handle.Dy()
|
height := gutter.Dy() - handle.Dy()
|
||||||
offset := int(float64(height) * (1 - this.value))
|
offset := int(float64(height) * (1 - this.value))
|
||||||
handle.Max.X = gutter.Dx()
|
handle.Max.X = gutter.Dx()
|
||||||
boxes[0].SetBounds (
|
boxes.SetBounds (
|
||||||
handle.
|
0,
|
||||||
Add(image.Pt(0, offset)).
|
handle.Add(image.Pt(0, offset)).Add(gutter.Min))
|
||||||
Add(gutter.Min))
|
|
||||||
} else {
|
} else {
|
||||||
width := gutter.Dx() - handle.Dx()
|
width := gutter.Dx() - handle.Dx()
|
||||||
offset := int(float64(width) * this.value)
|
offset := int(float64(width) * this.value)
|
||||||
handle.Max.Y = gutter.Dy()
|
handle.Max.Y = gutter.Dy()
|
||||||
boxes[0].SetBounds (
|
boxes.SetBounds (
|
||||||
handle.
|
0,
|
||||||
Add(image.Pt(offset, 0)).
|
handle.Add(image.Pt(offset, 0)).Add(gutter.Min))
|
||||||
Add(gutter.Min))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this sliderLayout) RecommendedHeight (tomo.LayoutHints, []tomo.Box, int) int {
|
func (this sliderLayout) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
|
||||||
return 0
|
return this.MinimumSize(hints, boxes).X
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this sliderLayout) RecommendedWidth (tomo.LayoutHints, []tomo.Box, int) int {
|
func (this sliderLayout) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
|
||||||
return 0
|
return this.MinimumSize(hints, boxes).Y
|
||||||
}
|
}
|
||||||
|
12
swatch.go
12
swatch.go
@ -26,11 +26,11 @@ func NewSwatch (value color.Color) *Swatch {
|
|||||||
swatch := &Swatch {
|
swatch := &Swatch {
|
||||||
CanvasBox: tomo.NewCanvasBox(),
|
CanvasBox: tomo.NewCanvasBox(),
|
||||||
}
|
}
|
||||||
swatch.SetRole(tomo.R("objects", "Swatch", ""))
|
swatch.SetRole(tomo.R("objects", "Swatch"))
|
||||||
swatch.SetDrawer(swatch)
|
swatch.SetDrawer(swatch)
|
||||||
swatch.SetValue(value)
|
swatch.SetValue(value)
|
||||||
|
|
||||||
swatch.OnMouseUp(swatch.handleMouseUp)
|
swatch.OnButtonUp(swatch.handleButtonUp)
|
||||||
swatch.OnKeyUp(swatch.handleKeyUp)
|
swatch.OnKeyUp(swatch.handleKeyUp)
|
||||||
swatch.SetFocusable(true)
|
swatch.SetFocusable(true)
|
||||||
return swatch
|
return swatch
|
||||||
@ -114,7 +114,7 @@ func (this *Swatch) Choose () {
|
|||||||
layouts.ContractHorizontal,
|
layouts.ContractHorizontal,
|
||||||
cancelButton,
|
cancelButton,
|
||||||
okButton)
|
okButton)
|
||||||
controlRow.SetAlign(tomo.AlignEnd, tomo.AlignMiddle)
|
controlRow.SetAttr(tomo.AAlign(tomo.AlignEnd, tomo.AlignMiddle))
|
||||||
window.SetRoot(NewOuterContainer (
|
window.SetRoot(NewOuterContainer (
|
||||||
layouts.Column { true, false },
|
layouts.Column { true, false },
|
||||||
colorPicker,
|
colorPicker,
|
||||||
@ -155,14 +155,14 @@ func (this *Swatch) userSetValue (value color.Color) {
|
|||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Swatch) handleKeyUp (key input.Key, numberPad bool) {
|
func (this *Swatch) handleKeyUp (catch func (), key input.Key, numberPad bool) {
|
||||||
if key != input.KeyEnter && key != input.Key(' ') { return }
|
if key != input.KeyEnter && key != input.Key(' ') { return }
|
||||||
this.Choose()
|
this.Choose()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Swatch) handleMouseUp (button input.Button) {
|
func (this *Swatch) handleButtonUp (catch func (), button input.Button) {
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
if this.MousePosition().In(this.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.Choose()
|
this.Choose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,19 @@ func NewTabbedContainer () *TabbedContainer {
|
|||||||
container := &TabbedContainer {
|
container := &TabbedContainer {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
}
|
}
|
||||||
container.SetRole(tomo.R("objects", "TabbedContainer", ""))
|
container.SetRole(tomo.R("objects", "TabbedContainer"))
|
||||||
container.SetLayout(layouts.Column { false, true } )
|
container.SetLayout(layouts.Column { false, true } )
|
||||||
|
|
||||||
container.tabsRow = tomo.NewContainerBox()
|
container.tabsRow = tomo.NewContainerBox()
|
||||||
container.tabsRow.SetRole(tomo.R("objects", "TabRow", ""))
|
container.tabsRow.SetRole(tomo.R("objects", "TabRow"))
|
||||||
container.Add(container.tabsRow)
|
container.Add(container.tabsRow)
|
||||||
|
|
||||||
container.leftSpacer = tomo.NewBox()
|
container.leftSpacer = tomo.NewBox()
|
||||||
container.leftSpacer.SetRole(tomo.R("objects", "TabSpacer", "left"))
|
container.leftSpacer.SetRole(tomo.R("objects", "TabSpacer"))
|
||||||
|
container.leftSpacer.SetTag("left", true)
|
||||||
container.rightSpacer = tomo.NewBox()
|
container.rightSpacer = tomo.NewBox()
|
||||||
container.rightSpacer.SetRole(tomo.R("objects", "TabSpacer", "right"))
|
container.rightSpacer.SetRole(tomo.R("objects", "TabSpacer"))
|
||||||
|
container.rightSpacer.SetTag("left", true)
|
||||||
|
|
||||||
container.ClearTabs()
|
container.ClearTabs()
|
||||||
container.setTabRowLayout()
|
container.setTabRowLayout()
|
||||||
@ -55,9 +57,9 @@ func (this *TabbedContainer) AddTab (name string, root tomo.Object) {
|
|||||||
name: name,
|
name: name,
|
||||||
root: root,
|
root: root,
|
||||||
}
|
}
|
||||||
tab.SetRole(tomo.R("objects", "Tab", ""))
|
tab.SetRole(tomo.R("objects", "Tab"))
|
||||||
tab.SetText(name)
|
tab.SetText(name)
|
||||||
tab.OnMouseDown(func (button input.Button) {
|
tab.OnButtonDown(func (catch func (), button input.Button) {
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
this.Activate(name)
|
this.Activate(name)
|
||||||
})
|
})
|
||||||
@ -118,9 +120,11 @@ type tab struct {
|
|||||||
|
|
||||||
func (this *tab) setActive (active bool) {
|
func (this *tab) setActive (active bool) {
|
||||||
if active {
|
if active {
|
||||||
this.SetRole(tomo.R("objects", "Tab", "active"))
|
this.SetRole(tomo.R("objects", "Tab"))
|
||||||
|
this.SetTag("active", false)
|
||||||
} else {
|
} else {
|
||||||
this.SetRole(tomo.R("objects", "Tab", ""))
|
this.SetRole(tomo.R("objects", "Tab"))
|
||||||
|
this.SetTag("active", true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
textinput.go
10
textinput.go
@ -19,8 +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() }
|
||||||
this.SetRole(tomo.R("objects", "TextInput", ""))
|
this.SetRole(tomo.R("objects", "TextInput"))
|
||||||
this.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
this.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
this.SetSelectable(true)
|
this.SetSelectable(true)
|
||||||
@ -53,9 +53,9 @@ func (this *TextInput) OnValueChange (callback func ()) event.Cookie {
|
|||||||
return this.on.valueChange.Connect(callback)
|
return this.on.valueChange.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
|
func (this *TextInput) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
||||||
dot := this.Dot()
|
dot := this.Dot()
|
||||||
modifiers := this.Modifiers()
|
modifiers := this.Window().Modifiers()
|
||||||
word := modifiers.Control
|
word := modifiers.Control
|
||||||
sel := modifiers.Shift
|
sel := modifiers.Shift
|
||||||
changed := false
|
changed := false
|
||||||
@ -113,6 +113,6 @@ func (this *TextInput) Type (char rune) {
|
|||||||
this.SetText(string(this.text))
|
this.SetText(string(this.text))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *TextInput) handleScroll (x, y float64) {
|
func (this *TextInput) handleScroll (catch func (), x, y float64) {
|
||||||
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
|
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ 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() }
|
||||||
this.SetRole(tomo.R("objects", "TextView", ""))
|
this.SetRole(tomo.R("objects", "TextView"))
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
this.SetSelectable(true)
|
this.SetSelectable(true)
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
@ -21,6 +21,6 @@ func NewTextView (text string) *TextView {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *TextView) handleScroll (x, y float64) {
|
func (this *TextView) handleScroll (catch func (), x, y float64) {
|
||||||
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
|
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user