Updated all objects to new API
This commit is contained in:
parent
06d99b2790
commit
6389556199
12
button.go
12
button.go
@ -28,7 +28,7 @@ func NewButton (text string) *Button {
|
|||||||
ContainerBox: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
label: NewLabel(text),
|
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.label.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
|
||||||
box.SetLayout(buttonLayout)
|
box.SetLayout(buttonLayout)
|
||||||
box.SetText(text)
|
box.SetText(text)
|
||||||
@ -48,7 +48,7 @@ func NewButton (text string) *Button {
|
|||||||
func (this *Button) SetText (text string) {
|
func (this *Button) SetText (text string) {
|
||||||
this.label.SetText(text)
|
this.label.SetText(text)
|
||||||
if this.labelActive && text == "" {
|
if this.labelActive && text == "" {
|
||||||
this.Delete(this.label)
|
this.Remove(this.label)
|
||||||
this.labelActive = false
|
this.labelActive = false
|
||||||
}
|
}
|
||||||
if !this.labelActive && text != "" {
|
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
|
// SetIcon sets an icon for this button. Setting the icon to IconUnknown will
|
||||||
// remove it.
|
// remove it.
|
||||||
func (this *Button) SetIcon (id theme.Icon) {
|
func (this *Button) SetIcon (id tomo.Icon) {
|
||||||
if this.icon != nil { this.Delete(this.icon) }
|
if this.icon != nil { this.Remove(this.icon) }
|
||||||
|
|
||||||
var icon *Icon; if id != theme.IconUnknown {
|
var icon *Icon; if id != tomo.IconUnknown {
|
||||||
icon = NewIcon(id, theme.IconSizeSmall)
|
icon = NewIcon(id, tomo.IconSizeSmall)
|
||||||
}
|
}
|
||||||
this.icon = icon
|
this.icon = icon
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ func NewCheckbox (value bool) *Checkbox {
|
|||||||
box := &Checkbox {
|
box := &Checkbox {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
theme.Apply(box, theme.R("objects", "Checkbox", ""))
|
tomo.Apply(box, tomo.R("objects", "Checkbox", ""))
|
||||||
box.SetValue(false)
|
box.SetValue(false)
|
||||||
|
|
||||||
box.OnMouseUp(box.handleMouseUp)
|
box.OnMouseUp(box.handleMouseUp)
|
||||||
@ -31,11 +31,10 @@ func NewCheckbox (value bool) *Checkbox {
|
|||||||
func (this *Checkbox) SetValue (value bool) {
|
func (this *Checkbox) SetValue (value bool) {
|
||||||
this.value = value
|
this.value = value
|
||||||
if this.value {
|
if this.value {
|
||||||
// TODO perhaps have IconStatusOkay/Cancel in actions, and have
|
// FIXME: we need checkbox icons
|
||||||
// a status icon for checked checkboxes.
|
this.SetTextureCenter(tomo.Icon("").Texture(tomo.IconSizeSmall))
|
||||||
this.SetTexture(theme.IconStatusOkay.Texture(theme.IconSizeSmall))
|
|
||||||
} else {
|
} else {
|
||||||
this.SetTexture(nil)
|
this.SetTextureCenter(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ 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...)
|
||||||
theme.Apply(this, theme.R("objects", "Container", "outer"))
|
tomo.Apply(this, tomo.R("objects", "Container", "outer"))
|
||||||
return this
|
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.
|
// 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...)
|
||||||
theme.Apply(this, theme.R("objects", "Container", "sunken"))
|
tomo.Apply(this, tomo.R("objects", "Container", "sunken"))
|
||||||
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...)
|
||||||
theme.Apply(this, theme.R("objects", "Container", "inner"))
|
tomo.Apply(this, tomo.R("objects", "Container", "inner"))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
dialog.go
21
dialog.go
@ -45,15 +45,15 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
|
|||||||
dialog.Window = window
|
dialog.Window = window
|
||||||
}
|
}
|
||||||
|
|
||||||
var iconId theme.Icon
|
var iconId tomo.Icon
|
||||||
switch kind {
|
switch kind {
|
||||||
case DialogInformation: iconId = theme.IconStatusInformation
|
case DialogInformation: iconId = tomo.IconDialogInformation
|
||||||
case DialogQuestion: iconId = theme.IconStatusQuestion
|
case DialogQuestion: iconId = tomo.IconDialogQuestion
|
||||||
case DialogWarning: iconId = theme.IconStatusWarning
|
case DialogWarning: iconId = tomo.IconDialogWarning
|
||||||
case DialogError: iconId = theme.IconStatusError
|
case DialogError: iconId = tomo.IconDialogError
|
||||||
}
|
}
|
||||||
dialog.SetTitle(title)
|
dialog.SetTitle(title)
|
||||||
icon := NewIcon(iconId, theme.IconSizeLarge)
|
icon := NewIcon(iconId, tomo.IconSizeLarge)
|
||||||
messageText := NewLabel(message)
|
messageText := NewLabel(message)
|
||||||
messageText.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
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.
|
// NewDialogOk creates a new dialog window with an OK option.
|
||||||
func NewDialogOk (kind DialogKind, parent tomo.Window, title, message string, onOk func ()) (*Dialog, error) {
|
func NewDialogOk (kind DialogKind, parent tomo.Window, title, message string, onOk func ()) (*Dialog, error) {
|
||||||
okButton := NewButton("OK")
|
okButton := NewButton("OK")
|
||||||
okButton.SetIcon(theme.IconStatusOkay)
|
// FIXME: need dialog accept/reject action icons
|
||||||
|
// okButton.SetIcon(tomo.IconStatusOkay)
|
||||||
okButton.OnClick(func () {
|
okButton.OnClick(func () {
|
||||||
if onOk != nil { onOk() }
|
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.
|
// NewDialogOkCancel creates a new dialog window with OK and Cancel options.
|
||||||
func NewDialogOkCancel (kind DialogKind, parent tomo.Window, title, message string, onOk func ()) (*Dialog, error) {
|
func NewDialogOkCancel (kind DialogKind, parent tomo.Window, title, message string, onOk func ()) (*Dialog, error) {
|
||||||
cancelButton := NewButton("Cancel")
|
cancelButton := NewButton("Cancel")
|
||||||
cancelButton.SetIcon(theme.IconStatusCancel)
|
// FIXME: need dialog accept/reject action icons
|
||||||
|
// cancelButton.SetIcon(tomo.IconStatusCancel)
|
||||||
|
|
||||||
okButton := NewButton("OK")
|
okButton := NewButton("OK")
|
||||||
okButton.SetIcon(theme.IconStatusOkay)
|
// FIXME: need dialog accept/reject action icons
|
||||||
|
// okButton.SetIcon(tomo.IconStatusOkay)
|
||||||
okButton.OnClick(func () {
|
okButton.OnClick(func () {
|
||||||
if onOk != nil { onOk() }
|
if onOk != nil { onOk() }
|
||||||
})
|
})
|
||||||
|
@ -15,7 +15,7 @@ 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() }
|
||||||
theme.Apply(this, theme.R("objects", "Heading", fmt.Sprint(level)))
|
tomo.Apply(this, tomo.R("objects", "Heading", fmt.Sprint(level)))
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
12
icon.go
12
icon.go
@ -11,27 +11,27 @@ type Icon struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewIcon creates a new icon from an icon ID.
|
// 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 {
|
this := &Icon {
|
||||||
Box: tomo.NewBox(),
|
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))
|
this.SetTexture(id.Texture(size))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMimeIcon creates a new icon from a MIME type.
|
// 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 {
|
this := &Icon {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
theme.Apply(this, theme.R("objects", "Icon", size.String()))
|
tomo.Apply(this, tomo.R("objects", "Icon", size.String()))
|
||||||
this.SetTexture(theme.MimeIcon(mime, size))
|
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.SetTexture(texture)
|
this.Box.SetTextureCenter(texture)
|
||||||
if texture == nil {
|
if texture == nil {
|
||||||
this.SetMinimumSize(image.Pt(0, 0))
|
this.SetMinimumSize(image.Pt(0, 0))
|
||||||
} else {
|
} else {
|
||||||
|
2
label.go
2
label.go
@ -10,7 +10,7 @@ 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() }
|
||||||
theme.Apply(this, theme.R("objects", "Label", ""))
|
tomo.Apply(this, tomo.R("objects", "Label", ""))
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
|
|||||||
checkbox: NewCheckbox(value),
|
checkbox: NewCheckbox(value),
|
||||||
label: NewLabel(text),
|
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.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
||||||
box.Add(box.checkbox)
|
box.Add(box.checkbox)
|
||||||
box.Add(box.label)
|
box.Add(box.label)
|
||||||
|
@ -28,13 +28,13 @@ func NewNumberInput (value float64) *NumberInput {
|
|||||||
increment: NewButton(""),
|
increment: NewButton(""),
|
||||||
decrement: NewButton(""),
|
decrement: NewButton(""),
|
||||||
}
|
}
|
||||||
theme.Apply(box, theme.R("objects", "NumberInput", ""))
|
tomo.Apply(box, 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)
|
||||||
box.SetLayout(layouts.NewGrid([]bool { true, false, false }, []bool { true }))
|
box.SetLayout(layouts.NewGrid([]bool { true, false, false }, []bool { true }))
|
||||||
box.increment.SetIcon(theme.IconActionIncrement)
|
box.increment.SetIcon(tomo.IconListAdd) // FIXME: need incr/decrment icons
|
||||||
box.decrement.SetIcon(theme.IconActionDecrement)
|
box.decrement.SetIcon(tomo.IconListRemove)
|
||||||
|
|
||||||
box.SetValue(value)
|
box.SetValue(value)
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ func newScrollbar (orient string) *Scrollbar {
|
|||||||
this.OnMouseUp(this.handleMouseUp)
|
this.OnMouseUp(this.handleMouseUp)
|
||||||
this.OnMouseMove(this.handleMouseMove)
|
this.OnMouseMove(this.handleMouseMove)
|
||||||
this.OnScroll(this.handleScroll)
|
this.OnScroll(this.handleScroll)
|
||||||
theme.Apply(this.handle, theme.R("objects", "SliderHandle", orient))
|
tomo.Apply(this.handle, tomo.R("objects", "SliderHandle", orient))
|
||||||
theme.Apply(this, theme.R("objects", "Slider", orient))
|
tomo.Apply(this, tomo.R("objects", "Slider", orient))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ func (this *Scrollbar) pageSize () int {
|
|||||||
|
|
||||||
func (this *Scrollbar) stepSize () int {
|
func (this *Scrollbar) stepSize () int {
|
||||||
// FIXME: this should not be hardcoded, need to get base font metrics
|
// 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
|
return 16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
|||||||
}
|
}
|
||||||
this.CaptureScroll(true)
|
this.CaptureScroll(true)
|
||||||
this.OnScroll(this.handleScroll)
|
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)
|
this.SetLayout(this.layout)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@ -70,8 +70,8 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
|||||||
// one.
|
// one.
|
||||||
func (this *ScrollContainer) SetRoot (root tomo.ContentBox) {
|
func (this *ScrollContainer) SetRoot (root tomo.ContentBox) {
|
||||||
if this.layout.root != nil {
|
if this.layout.root != nil {
|
||||||
// delete root and close cookies
|
// remove root and close cookies
|
||||||
this.Delete(this.layout.root)
|
this.Remove(this.layout.root)
|
||||||
if this.horizontalCookie != nil {
|
if this.horizontalCookie != nil {
|
||||||
this.horizontalCookie.Close()
|
this.horizontalCookie.Close()
|
||||||
this.horizontalCookie = nil
|
this.horizontalCookie = nil
|
||||||
|
@ -12,6 +12,6 @@ func NewSeparator () *Separator {
|
|||||||
this := &Separator {
|
this := &Separator {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
theme.Apply(this, theme.R("objects", "Separator", ""))
|
tomo.Apply(this, tomo.R("objects", "Separator", ""))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ func newSlider (orient string, value float64) *Slider {
|
|||||||
this.OnMouseUp(this.handleMouseUp)
|
this.OnMouseUp(this.handleMouseUp)
|
||||||
this.OnMouseMove(this.handleMouseMove)
|
this.OnMouseMove(this.handleMouseMove)
|
||||||
this.OnScroll(this.handleScroll)
|
this.OnScroll(this.handleScroll)
|
||||||
theme.Apply(this.handle, theme.R("objects", "SliderHandle", orient))
|
tomo.Apply(this.handle, tomo.R("objects", "SliderHandle", orient))
|
||||||
theme.Apply(this, theme.R("objects", "Slider", orient))
|
tomo.Apply(this, tomo.R("objects", "Slider", orient))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ 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() }
|
||||||
theme.Apply(this, theme.R("objects", "TextInput", ""))
|
tomo.Apply(this, tomo.R("objects", "TextInput", ""))
|
||||||
this.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
this.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
|
@ -11,7 +11,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() }
|
||||||
theme.Apply(this, theme.R("objects", "TextView", ""))
|
tomo.Apply(this, tomo.R("objects", "TextView", ""))
|
||||||
this.SetFocusable(true)
|
this.SetFocusable(true)
|
||||||
this.SetSelectable(true)
|
this.SetSelectable(true)
|
||||||
this.SetText(text)
|
this.SetText(text)
|
||||||
|
Loading…
Reference in New Issue
Block a user