Compare commits

..

No commits in common. "638955619942105c40a3befcd1dc79b1281c96d4" and "6497da69ed438bac577351f4ecf25d747603d6e1" have entirely different histories.

17 changed files with 66 additions and 61 deletions

View File

@ -1,6 +1,7 @@
package objects
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/tomo/objects/layouts"
@ -28,7 +29,7 @@ func NewButton (text string) *Button {
ContainerBox: tomo.NewContainerBox(),
label: NewLabel(text),
}
tomo.Apply(box, tomo.R("objects", "Button", ""))
theme.Apply(box, theme.R("objects", "Button", ""))
box.label.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
box.SetLayout(buttonLayout)
box.SetText(text)
@ -48,7 +49,7 @@ func NewButton (text string) *Button {
func (this *Button) SetText (text string) {
this.label.SetText(text)
if this.labelActive && text == "" {
this.Remove(this.label)
this.Delete(this.label)
this.labelActive = false
}
if !this.labelActive && text != "" {
@ -60,11 +61,11 @@ func (this *Button) SetText (text string) {
// SetIcon sets an icon for this button. Setting the icon to IconUnknown will
// remove it.
func (this *Button) SetIcon (id tomo.Icon) {
if this.icon != nil { this.Remove(this.icon) }
func (this *Button) SetIcon (id theme.Icon) {
if this.icon != nil { this.Delete(this.icon) }
var icon *Icon; if id != tomo.IconUnknown {
icon = NewIcon(id, tomo.IconSizeSmall)
var icon *Icon; if id != theme.IconUnknown {
icon = NewIcon(id, theme.IconSizeSmall)
}
this.icon = icon

View File

@ -1,6 +1,7 @@
package objects
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/event"
@ -18,7 +19,7 @@ func NewCheckbox (value bool) *Checkbox {
box := &Checkbox {
Box: tomo.NewBox(),
}
tomo.Apply(box, tomo.R("objects", "Checkbox", ""))
theme.Apply(box, theme.R("objects", "Checkbox", ""))
box.SetValue(false)
box.OnMouseUp(box.handleMouseUp)
@ -31,10 +32,11 @@ func NewCheckbox (value bool) *Checkbox {
func (this *Checkbox) SetValue (value bool) {
this.value = value
if this.value {
// FIXME: we need checkbox icons
this.SetTextureCenter(tomo.Icon("").Texture(tomo.IconSizeSmall))
// TODO perhaps have IconStatusOkay/Cancel in actions, and have
// a status icon for checked checkboxes.
this.SetTexture(theme.IconStatusOkay.Texture(theme.IconSizeSmall))
} else {
this.SetTextureCenter(nil)
this.SetTexture(nil)
}
}

View File

@ -1,6 +1,7 @@
package objects
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
// Container is an object that can contain other objects. It can be used as a
// primitive for building more complex layouts. It has two variants: an outer
@ -27,7 +28,7 @@ func newContainer (layout tomo.Layout, children ...tomo.Object) *Container {
// window, tab pane, etc.
func NewOuterContainer (layout tomo.Layout, children ...tomo.Object) *Container {
this := newContainer(layout, children...)
tomo.Apply(this, tomo.R("objects", "Container", "outer"))
theme.Apply(this, theme.R("objects", "Container", "outer"))
return this
}
@ -35,14 +36,14 @@ func NewOuterContainer (layout tomo.Layout, children ...tomo.Object) *Container
// around it. It is meant to be used as a root container for a ScrollContainer.
func NewSunkenContainer (layout tomo.Layout, children ...tomo.Object) *Container {
this := newContainer(layout, children...)
tomo.Apply(this, tomo.R("objects", "Container", "sunken"))
theme.Apply(this, theme.R("objects", "Container", "sunken"))
return this
}
// NewInnerContainer creates a new container that has no padding around it.
func NewInnerContainer (layout tomo.Layout, children ...tomo.Object) *Container {
this := newContainer(layout, children...)
tomo.Apply(this, tomo.R("objects", "Container", "inner"))
theme.Apply(this, theme.R("objects", "Container", "inner"))
return this
}

View File

@ -3,6 +3,7 @@ package objects
import "image"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/objects/layouts"
// DialogKind defines the semantic role of a dialog window.
@ -45,15 +46,15 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
dialog.Window = window
}
var iconId tomo.Icon
var iconId theme.Icon
switch kind {
case DialogInformation: iconId = tomo.IconDialogInformation
case DialogQuestion: iconId = tomo.IconDialogQuestion
case DialogWarning: iconId = tomo.IconDialogWarning
case DialogError: iconId = tomo.IconDialogError
case DialogInformation: iconId = theme.IconStatusInformation
case DialogQuestion: iconId = theme.IconStatusQuestion
case DialogWarning: iconId = theme.IconStatusWarning
case DialogError: iconId = theme.IconStatusError
}
dialog.SetTitle(title)
icon := NewIcon(iconId, tomo.IconSizeLarge)
icon := NewIcon(iconId, theme.IconSizeLarge)
messageText := NewLabel(message)
messageText.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
@ -75,8 +76,7 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
// NewDialogOk creates a new dialog window with an OK option.
func NewDialogOk (kind DialogKind, parent tomo.Window, title, message string, onOk func ()) (*Dialog, error) {
okButton := NewButton("OK")
// FIXME: need dialog accept/reject action icons
// okButton.SetIcon(tomo.IconStatusOkay)
okButton.SetIcon(theme.IconStatusOkay)
okButton.OnClick(func () {
if onOk != nil { onOk() }
})
@ -88,12 +88,10 @@ func NewDialogOk (kind DialogKind, parent tomo.Window, title, message string, on
// 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) {
cancelButton := NewButton("Cancel")
// FIXME: need dialog accept/reject action icons
// cancelButton.SetIcon(tomo.IconStatusCancel)
cancelButton.SetIcon(theme.IconStatusCancel)
okButton := NewButton("OK")
// FIXME: need dialog accept/reject action icons
// okButton.SetIcon(tomo.IconStatusOkay)
okButton.SetIcon(theme.IconStatusOkay)
okButton.OnClick(func () {
if onOk != nil { onOk() }
})

2
go.mod
View File

@ -2,6 +2,6 @@ module git.tebibyte.media/tomo/objects
go 1.20
require git.tebibyte.media/tomo/tomo v0.33.0
require git.tebibyte.media/tomo/tomo v0.31.0
require golang.org/x/image v0.11.0 // indirect

4
go.sum
View File

@ -1,5 +1,5 @@
git.tebibyte.media/tomo/tomo v0.33.0 h1:BBm1oRsogBLeqVKeevNqG9RPCOdmbGeiQM/9hd2GHE8=
git.tebibyte.media/tomo/tomo v0.33.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
git.tebibyte.media/tomo/tomo v0.31.0 h1:LHPpj3AWycochnC8F441aaRNS6Tq6w6WnBrp/LGjyhM=
git.tebibyte.media/tomo/tomo v0.31.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
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-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=

View File

@ -2,6 +2,7 @@ package objects
import "fmt"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
// Heading is a label that denotes the start of some section of content. It can
// have a level from 0 to 2, with 0 being the most prominent and 2 being the
@ -15,7 +16,7 @@ func NewHeading (level int, text string) *Heading {
if level < 0 { level = 0 }
if level > 2 { level = 2 }
this := &Heading { TextBox: tomo.NewTextBox() }
tomo.Apply(this, tomo.R("objects", "Heading", fmt.Sprint(level)))
theme.Apply(this, theme.R("objects", "Heading", fmt.Sprint(level)))
this.SetText(text)
return this
}

13
icon.go
View File

@ -3,6 +3,7 @@ package objects
import "image"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/canvas"
// Icon displays a single icon.
@ -11,27 +12,27 @@ type Icon struct {
}
// NewIcon creates a new icon from an icon ID.
func NewIcon (id tomo.Icon, size tomo.IconSize) *Icon {
func NewIcon (id theme.Icon, size theme.IconSize) *Icon {
this := &Icon {
Box: tomo.NewBox(),
}
tomo.Apply(this, tomo.R("objects", "Icon", size.String()))
theme.Apply(this, theme.R("objects", "Icon", size.String()))
this.SetTexture(id.Texture(size))
return this
}
// NewMimeIcon creates a new icon from a MIME type.
func NewMimeIcon (mime data.Mime, size tomo.IconSize) *Icon {
func NewMimeIcon (mime data.Mime, size theme.IconSize) *Icon {
this := &Icon {
Box: tomo.NewBox(),
}
tomo.Apply(this, tomo.R("objects", "Icon", size.String()))
this.SetTexture(tomo.MimeIcon(mime, size))
theme.Apply(this, theme.R("objects", "Icon", size.String()))
this.SetTexture(theme.MimeIcon(mime, size))
return this
}
func (this *Icon) SetTexture (texture canvas.Texture) {
this.Box.SetTextureCenter(texture)
this.Box.SetTexture(texture)
if texture == nil {
this.SetMinimumSize(image.Pt(0, 0))
} else {

View File

@ -3,6 +3,7 @@ package objects
import "image"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/text"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/event"
@ -19,7 +20,7 @@ type TextInput struct {
// NewTextInput creates a new text input containing the specified text.
func NewTextInput (text string) *TextInput {
this := &TextInput { TextBox: tomo.NewTextBox() }
tomo.Apply(this, tomo.R("objects", "TextInput", ""))
theme.Apply(this, theme.R("objects", "TextInput", ""))
this.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
this.SetText(text)
this.SetFocusable(true)
@ -59,8 +60,8 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
sel := modifiers.Shift
changed := false
// TODO all dot control (movement, selection, etc) should be done in the
// backend. (editing should be done here, though)
// TODO all this (except editing stuff) really should be moved into the
// backend
switch {
case key == input.KeyEnter:
@ -104,14 +105,6 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
}
}
// Type types a character at the current dot position.
func (this *TextInput) Type (char rune) {
dot := this.Dot()
this.text, dot = text.Type(this.text, dot, rune(char))
this.Select(dot)
this.SetText(string(this.text))
}
func (this *TextInput) handleScroll (x, y float64) {
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
}

View File

@ -1,6 +1,7 @@
package objects
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
// Label is a simple text label.
type Label struct {
@ -10,7 +11,7 @@ type Label struct {
// NewLabel creates a new text label.
func NewLabel (text string) *Label {
this := &Label { TextBox: tomo.NewTextBox() }
tomo.Apply(this, tomo.R("objects", "Label", ""))
theme.Apply(this, theme.R("objects", "Label", ""))
this.SetText(text)
return this
}

View File

@ -1,6 +1,7 @@
package objects
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/tomo/objects/layouts"
@ -20,7 +21,7 @@ func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
checkbox: NewCheckbox(value),
label: NewLabel(text),
}
tomo.Apply(box, tomo.R("objects", "LabelCheckbox", ""))
theme.Apply(box, theme.R("objects", "LabelCheckbox", ""))
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
box.Add(box.checkbox)
box.Add(box.label)

View File

@ -3,6 +3,7 @@ package objects
import "math"
import "strconv"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/tomo/objects/layouts"
@ -28,13 +29,13 @@ func NewNumberInput (value float64) *NumberInput {
increment: NewButton(""),
decrement: NewButton(""),
}
tomo.Apply(box, tomo.R("objects", "NumberInput", ""))
theme.Apply(box, theme.R("objects", "NumberInput", ""))
box.Add(box.input)
box.Add(box.decrement)
box.Add(box.increment)
box.SetLayout(layouts.NewGrid([]bool { true, false, false }, []bool { true }))
box.increment.SetIcon(tomo.IconListAdd) // FIXME: need incr/decrment icons
box.decrement.SetIcon(tomo.IconListRemove)
box.increment.SetIcon(theme.IconActionIncrement)
box.decrement.SetIcon(theme.IconActionDecrement)
box.SetValue(value)

View File

@ -2,6 +2,7 @@ package objects
import "image"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/event"
@ -45,8 +46,8 @@ func newScrollbar (orient string) *Scrollbar {
this.OnMouseUp(this.handleMouseUp)
this.OnMouseMove(this.handleMouseMove)
this.OnScroll(this.handleScroll)
tomo.Apply(this.handle, tomo.R("objects", "SliderHandle", orient))
tomo.Apply(this, tomo.R("objects", "Slider", orient))
theme.Apply(this.handle, theme.R("objects", "SliderHandle", orient))
theme.Apply(this, theme.R("objects", "Slider", orient))
return this
}
@ -240,7 +241,7 @@ func (this *Scrollbar) pageSize () int {
func (this *Scrollbar) stepSize () int {
// FIXME: this should not be hardcoded, need to get base font metrics
// from tomo.somehow. should be (emspace, lineheight)
// from theme somehow. should be (emspace, lineheight)
return 16
}

View File

@ -3,6 +3,7 @@ package objects
import "image"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/tomo/tomo/theme"
// ScrollSide determines which Scrollbars are active in a ScrollContainer.
type ScrollSide int; const (
@ -60,7 +61,7 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
}
this.CaptureScroll(true)
this.OnScroll(this.handleScroll)
tomo.Apply(this, tomo.R("objects", "ScrollContainer", sides.String()))
theme.Apply(this, theme.R("objects", "ScrollContainer", sides.String()))
this.SetLayout(this.layout)
return this
}
@ -70,8 +71,8 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
// one.
func (this *ScrollContainer) SetRoot (root tomo.ContentBox) {
if this.layout.root != nil {
// remove root and close cookies
this.Remove(this.layout.root)
// delete root and close cookies
this.Delete(this.layout.root)
if this.horizontalCookie != nil {
this.horizontalCookie.Close()
this.horizontalCookie = nil

View File

@ -1,6 +1,7 @@
package objects
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
// Separator is a line for visually separating elements.
type Separator struct {
@ -12,6 +13,6 @@ func NewSeparator () *Separator {
this := &Separator {
Box: tomo.NewBox(),
}
tomo.Apply(this, tomo.R("objects", "Separator", ""))
theme.Apply(this, theme.R("objects", "Separator", ""))
return this
}

View File

@ -2,6 +2,7 @@ package objects
import "image"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/event"
@ -51,8 +52,8 @@ func newSlider (orient string, value float64) *Slider {
this.OnMouseUp(this.handleMouseUp)
this.OnMouseMove(this.handleMouseMove)
this.OnScroll(this.handleScroll)
tomo.Apply(this.handle, tomo.R("objects", "SliderHandle", orient))
tomo.Apply(this, tomo.R("objects", "Slider", orient))
theme.Apply(this.handle, theme.R("objects", "SliderHandle", orient))
theme.Apply(this, theme.R("objects", "Slider", orient))
return this
}

View File

@ -2,6 +2,7 @@ package objects
import "image"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/theme"
// TextView is an area for displaying a large amount of multi-line text.
type TextView struct {
@ -11,7 +12,7 @@ type TextView struct {
// NewTextView creates a new text view.
func NewTextView (text string) *TextView {
this := &TextView { TextBox: tomo.NewTextBox() }
tomo.Apply(this, tomo.R("objects", "TextView", ""))
theme.Apply(this, theme.R("objects", "TextView", ""))
this.SetFocusable(true)
this.SetSelectable(true)
this.SetText(text)