From c2245ec30413a055b1f2c0ac1b107192f030eb6d Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 12 Sep 2024 02:34:28 -0400 Subject: [PATCH] Fix object code --- dialog.go | 8 +++++--- menu.go | 4 ++-- scrollbar.go | 7 ++++--- scrollcontainer.go | 10 ++++++---- slider.go | 4 ++-- swatch.go | 4 ++-- textinput.go | 20 ++++++++++---------- 7 files changed, 31 insertions(+), 26 deletions(-) diff --git a/dialog.go b/dialog.go index b92329a..d27ca24 100644 --- a/dialog.go +++ b/dialog.go @@ -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...) diff --git a/menu.go b/menu.go index 09957e0..68b24bf 100644 --- a/menu.go +++ b/menu.go @@ -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 } diff --git a/scrollbar.go b/scrollbar.go index 2e6202d..2a7ef02 100644 --- a/scrollbar.go +++ b/scrollbar.go @@ -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 { diff --git a/scrollcontainer.go b/scrollcontainer.go index 376b42e..243679d 100644 --- a/scrollcontainer.go +++ b/scrollcontainer.go @@ -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 } diff --git a/slider.go b/slider.go index 24e15ff..4b41aca 100644 --- a/slider.go +++ b/slider.go @@ -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) diff --git a/swatch.go b/swatch.go index 61a4df6..61d7efb 100644 --- a/swatch.go +++ b/swatch.go @@ -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) diff --git a/textinput.go b/textinput.go index b700789..b471c0a 100644 --- a/textinput.go +++ b/textinput.go @@ -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