Updated all objects to new API

This commit is contained in:
Sasha Koshka 2024-05-26 17:21:58 -04:00
parent 06d99b2790
commit 6389556199
15 changed files with 48 additions and 46 deletions

View File

@ -28,7 +28,7 @@ func NewButton (text string) *Button {
ContainerBox: tomo.NewContainerBox(),
label: NewLabel(text),
}
theme.Apply(box, theme.R("objects", "Button", ""))
tomo.Apply(box, tomo.R("objects", "Button", ""))
box.label.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
box.SetLayout(buttonLayout)
box.SetText(text)
@ -48,7 +48,7 @@ func NewButton (text string) *Button {
func (this *Button) SetText (text string) {
this.label.SetText(text)
if this.labelActive && text == "" {
this.Delete(this.label)
this.Remove(this.label)
this.labelActive = false
}
if !this.labelActive && text != "" {
@ -60,11 +60,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 theme.Icon) {
if this.icon != nil { this.Delete(this.icon) }
func (this *Button) SetIcon (id tomo.Icon) {
if this.icon != nil { this.Remove(this.icon) }
var icon *Icon; if id != theme.IconUnknown {
icon = NewIcon(id, theme.IconSizeSmall)
var icon *Icon; if id != tomo.IconUnknown {
icon = NewIcon(id, tomo.IconSizeSmall)
}
this.icon = icon

View File

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

View File

@ -27,7 +27,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...)
theme.Apply(this, theme.R("objects", "Container", "outer"))
tomo.Apply(this, tomo.R("objects", "Container", "outer"))
return this
}
@ -35,14 +35,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...)
theme.Apply(this, theme.R("objects", "Container", "sunken"))
tomo.Apply(this, tomo.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...)
theme.Apply(this, theme.R("objects", "Container", "inner"))
tomo.Apply(this, tomo.R("objects", "Container", "inner"))
return this
}

View File

@ -45,15 +45,15 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
dialog.Window = window
}
var iconId theme.Icon
var iconId tomo.Icon
switch kind {
case DialogInformation: iconId = theme.IconStatusInformation
case DialogQuestion: iconId = theme.IconStatusQuestion
case DialogWarning: iconId = theme.IconStatusWarning
case DialogError: iconId = theme.IconStatusError
case DialogInformation: iconId = tomo.IconDialogInformation
case DialogQuestion: iconId = tomo.IconDialogQuestion
case DialogWarning: iconId = tomo.IconDialogWarning
case DialogError: iconId = tomo.IconDialogError
}
dialog.SetTitle(title)
icon := NewIcon(iconId, theme.IconSizeLarge)
icon := NewIcon(iconId, tomo.IconSizeLarge)
messageText := NewLabel(message)
messageText.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
@ -75,7 +75,8 @@ 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")
okButton.SetIcon(theme.IconStatusOkay)
// FIXME: need dialog accept/reject action icons
// okButton.SetIcon(tomo.IconStatusOkay)
okButton.OnClick(func () {
if onOk != nil { onOk() }
})
@ -87,10 +88,12 @@ 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")
cancelButton.SetIcon(theme.IconStatusCancel)
// FIXME: need dialog accept/reject action icons
// cancelButton.SetIcon(tomo.IconStatusCancel)
okButton := NewButton("OK")
okButton.SetIcon(theme.IconStatusOkay)
// FIXME: need dialog accept/reject action icons
// okButton.SetIcon(tomo.IconStatusOkay)
okButton.OnClick(func () {
if onOk != nil { onOk() }
})

View File

@ -15,7 +15,7 @@ func NewHeading (level int, text string) *Heading {
if level < 0 { level = 0 }
if level > 2 { level = 2 }
this := &Heading { TextBox: tomo.NewTextBox() }
theme.Apply(this, theme.R("objects", "Heading", fmt.Sprint(level)))
tomo.Apply(this, tomo.R("objects", "Heading", fmt.Sprint(level)))
this.SetText(text)
return this
}

12
icon.go
View File

@ -11,27 +11,27 @@ type Icon struct {
}
// NewIcon creates a new icon from an icon ID.
func NewIcon (id theme.Icon, size theme.IconSize) *Icon {
func NewIcon (id tomo.Icon, size tomo.IconSize) *Icon {
this := &Icon {
Box: tomo.NewBox(),
}
theme.Apply(this, theme.R("objects", "Icon", size.String()))
tomo.Apply(this, tomo.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 theme.IconSize) *Icon {
func NewMimeIcon (mime data.Mime, size tomo.IconSize) *Icon {
this := &Icon {
Box: tomo.NewBox(),
}
theme.Apply(this, theme.R("objects", "Icon", size.String()))
this.SetTexture(theme.MimeIcon(mime, size))
tomo.Apply(this, tomo.R("objects", "Icon", size.String()))
this.SetTexture(tomo.MimeIcon(mime, size))
return this
}
func (this *Icon) SetTexture (texture canvas.Texture) {
this.Box.SetTexture(texture)
this.Box.SetTextureCenter(texture)
if texture == nil {
this.SetMinimumSize(image.Pt(0, 0))
} else {

View File

@ -10,7 +10,7 @@ type Label struct {
// NewLabel creates a new text label.
func NewLabel (text string) *Label {
this := &Label { TextBox: tomo.NewTextBox() }
theme.Apply(this, theme.R("objects", "Label", ""))
tomo.Apply(this, tomo.R("objects", "Label", ""))
this.SetText(text)
return this
}

View File

@ -20,7 +20,7 @@ func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
checkbox: NewCheckbox(value),
label: NewLabel(text),
}
theme.Apply(box, theme.R("objects", "LabelCheckbox", ""))
tomo.Apply(box, tomo.R("objects", "LabelCheckbox", ""))
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
box.Add(box.checkbox)
box.Add(box.label)

View File

@ -28,13 +28,13 @@ func NewNumberInput (value float64) *NumberInput {
increment: NewButton(""),
decrement: NewButton(""),
}
theme.Apply(box, theme.R("objects", "NumberInput", ""))
tomo.Apply(box, tomo.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(theme.IconActionIncrement)
box.decrement.SetIcon(theme.IconActionDecrement)
box.increment.SetIcon(tomo.IconListAdd) // FIXME: need incr/decrment icons
box.decrement.SetIcon(tomo.IconListRemove)
box.SetValue(value)

View File

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

View File

@ -60,7 +60,7 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
}
this.CaptureScroll(true)
this.OnScroll(this.handleScroll)
theme.Apply(this, theme.R("objects", "ScrollContainer", sides.String()))
tomo.Apply(this, tomo.R("objects", "ScrollContainer", sides.String()))
this.SetLayout(this.layout)
return this
}
@ -70,8 +70,8 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
// one.
func (this *ScrollContainer) SetRoot (root tomo.ContentBox) {
if this.layout.root != nil {
// delete root and close cookies
this.Delete(this.layout.root)
// remove root and close cookies
this.Remove(this.layout.root)
if this.horizontalCookie != nil {
this.horizontalCookie.Close()
this.horizontalCookie = nil

View File

@ -12,6 +12,6 @@ func NewSeparator () *Separator {
this := &Separator {
Box: tomo.NewBox(),
}
theme.Apply(this, theme.R("objects", "Separator", ""))
tomo.Apply(this, tomo.R("objects", "Separator", ""))
return this
}

View File

@ -51,8 +51,8 @@ func newSlider (orient string, value float64) *Slider {
this.OnMouseUp(this.handleMouseUp)
this.OnMouseMove(this.handleMouseMove)
this.OnScroll(this.handleScroll)
theme.Apply(this.handle, theme.R("objects", "SliderHandle", orient))
theme.Apply(this, theme.R("objects", "Slider", orient))
tomo.Apply(this.handle, tomo.R("objects", "SliderHandle", orient))
tomo.Apply(this, tomo.R("objects", "Slider", orient))
return this
}

View File

@ -19,7 +19,7 @@ type TextInput struct {
// NewTextInput creates a new text input containing the specified text.
func NewTextInput (text string) *TextInput {
this := &TextInput { TextBox: tomo.NewTextBox() }
theme.Apply(this, theme.R("objects", "TextInput", ""))
tomo.Apply(this, tomo.R("objects", "TextInput", ""))
this.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
this.SetText(text)
this.SetFocusable(true)

View File

@ -11,7 +11,7 @@ type TextView struct {
// NewTextView creates a new text view.
func NewTextView (text string) *TextView {
this := &TextView { TextBox: tomo.NewTextBox() }
theme.Apply(this, theme.R("objects", "TextView", ""))
tomo.Apply(this, tomo.R("objects", "TextView", ""))
this.SetFocusable(true)
this.SetSelectable(true)
this.SetText(text)