Fix object code

This commit is contained in:
Sasha Koshka 2024-09-12 02:34:28 -04:00
parent dca3880a87
commit c2245ec304
7 changed files with 31 additions and 26 deletions

View File

@ -36,11 +36,11 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
dialog := &Dialog { }
if parent == nil {
window, err := tomo.NewWindow(image.Rectangle { })
window, err := tomo.NewWindow(tomo.WindowKindNormal, image.Rectangle { })
if err != nil { return nil, err }
dialog.Window = window
} else {
window, err := parent.NewModal(image.Rectangle { })
window, err := parent.NewChild(tomo.WindowKindModal, image.Rectangle { })
if err != nil { return nil, err }
dialog.Window = window
}
@ -60,7 +60,9 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
for _, option := range options {
if option, ok := option.(clickable); ok {
option.OnClick(dialog.Close)
option.OnClick(func () {
dialog.Close()
})
}
}
dialog.controlRow = NewInnerContainer(layouts.ContractHorizontal, options...)

View File

@ -40,7 +40,7 @@ func newMenu (parent tomo.Window, bounds image.Rectangle, items ...tomo.Object)
menu := &Menu { }
menu.bounds = bounds
menu.parent = parent
window, err := menu.parent.NewMenu(menu.bounds)
window, err := menu.parent.NewChild(tomo.WindowKindMenu, menu.bounds)
if err != nil { return nil, err }
menu.Window = window
@ -75,7 +75,7 @@ func (this *Menu) TearOff () {
if this.parent == nil { return }
this.torn = true
window, err := this.parent.NewChild(this.bounds)
window, err := this.parent.NewChild(tomo.WindowKindToolbar, this.bounds)
window.SetIcon(tomo.IconListChoose)
if err != nil { return }

View File

@ -172,14 +172,14 @@ func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) bool {
switch key {
case input.KeyUp, input.KeyLeft:
if modifiers.Alt {
if modifiers.Alt() {
this.SetValue(0)
} else {
this.scrollBy(this.StepSize())
}
return true
case input.KeyDown, input.KeyRight:
if modifiers.Alt {
if modifiers.Alt() {
this.SetValue(1)
} else {
this.scrollBy(-this.StepSize())
@ -320,12 +320,13 @@ func (this *Scrollbar) newLinkCookie (subCookies ...event.Cookie) *scrollbarCook
}
}
func (this *scrollbarCookie) Close () {
func (this *scrollbarCookie) Close () error {
for _, cookie := range this.subCookies {
cookie.Close()
}
this.owner.layout.linked = nil
this.owner.box.SetAttr(tomo.ALayout(this.owner.layout))
return nil
}
type scrollbarLayout struct {

View File

@ -202,7 +202,7 @@ func (this *ScrollContainer) handleKeyDown (key input.Key, numpad bool) bool {
vector := image.Point { }
switch key {
case input.KeyPageUp:
if modifiers.Shift {
if modifiers.Shift() {
vector.X -= this.PageSize().X
} else {
vector.Y -= this.PageSize().Y
@ -210,7 +210,7 @@ func (this *ScrollContainer) handleKeyDown (key input.Key, numpad bool) bool {
this.scrollBy(vector)
return true
case input.KeyPageDown:
if modifiers.Shift {
if modifiers.Shift() {
vector.X += this.PageSize().X
} else {
vector.Y += this.PageSize().Y
@ -218,7 +218,7 @@ func (this *ScrollContainer) handleKeyDown (key input.Key, numpad bool) bool {
this.scrollBy(vector)
return true
case input.KeyUp:
if modifiers.Shift {
if modifiers.Shift() {
vector.X -= this.StepSize().X
} else {
vector.Y -= this.StepSize().Y
@ -226,7 +226,7 @@ func (this *ScrollContainer) handleKeyDown (key input.Key, numpad bool) bool {
this.scrollBy(vector)
return true
case input.KeyDown:
if modifiers.Shift {
if modifiers.Shift() {
vector.X += this.StepSize().X
} else {
vector.Y += this.StepSize().Y
@ -241,6 +241,8 @@ func (this *ScrollContainer) handleKeyUp (key input.Key, numpad bool) bool {
switch key {
case input.KeyPageUp: return true
case input.KeyPageDown: return true
case input.KeyUp: return true
case input.KeyDown: return true
}
return false
}

View File

@ -127,7 +127,7 @@ func (this *Slider) handleKeyDown (key input.Key, numpad bool) bool {
switch key {
case input.KeyUp, input.KeyLeft:
if this.box.Window().Modifiers().Alt {
if this.box.Window().Modifiers().Alt() {
this.SetValue(0)
} else {
this.SetValue(this.Value() - increment)
@ -135,7 +135,7 @@ func (this *Slider) handleKeyDown (key input.Key, numpad bool) bool {
this.on.valueChange.Broadcast()
return true
case input.KeyDown, input.KeyRight:
if this.box.Window().Modifiers().Alt {
if this.box.Window().Modifiers().Alt() {
this.SetValue(1)
} else {
this.SetValue(this.Value() + increment)

View File

@ -90,9 +90,9 @@ func (this *Swatch) Choose () {
var err error
var window tomo.Window
if parent := this.box.Window(); parent != nil {
window, err = parent.NewChild(image.Rectangle { })
window, err = parent.NewChild(tomo.WindowKindNormal, image.Rectangle { })
} else {
window, err = tomo.NewWindow(image.Rectangle { })
window, err = tomo.NewWindow(tomo.WindowKindNormal, image.Rectangle { })
}
if err != nil {
log.Println("objects: could not create swatch modal:", err)

View File

@ -205,7 +205,7 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
dot := this.Dot()
txt := this.text
modifiers := this.box.Window().Modifiers()
word := modifiers.Control
word := modifiers.Control()
changed := false
defer func () {
@ -225,7 +225,7 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
changed = true
}
if this.multiline && !modifiers.Control {
if this.multiline && !modifiers.Control() {
switch {
case key == '\n', key == '\t':
typeRune()
@ -245,17 +245,17 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
txt, dot = text.Delete(txt, dot, word)
changed = true
return true
case key.Printable() && !modifiers.Control:
case key.Printable() && !modifiers.Control():
typeRune()
return true
case key == 'z' || key == 'Z' && modifiers.Control:
if modifiers.Shift {
case key == 'z' || key == 'Z' && modifiers.Control():
if modifiers.Shift() {
this.Redo()
} else {
this.Undo()
}
return true
case key == 'y' && modifiers.Control:
case key == 'y' && modifiers.Control():
this.Redo()
return true
default:
@ -266,7 +266,7 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
func (this *TextInput) handleKeyUp (key input.Key, numpad bool) bool {
modifiers := this.box.Window().Modifiers()
if this.multiline && !modifiers.Control {
if this.multiline && !modifiers.Control() {
switch {
case key == '\n', key == '\t':
return true
@ -280,11 +280,11 @@ func (this *TextInput) handleKeyUp (key input.Key, numpad bool) bool {
return true
case key == input.KeyDelete:
return true
case key.Printable() && !modifiers.Control:
case key.Printable() && !modifiers.Control():
return true
case key == 'z' && modifiers.Control:
case key == 'z' && modifiers.Control():
return true
case key == 'y' && modifiers.Control:
case key == 'y' && modifiers.Control():
return true
default:
return false