Skip to content

Commit

Permalink
more work on vector toolbars
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Feb 24, 2024
1 parent 6e855d5 commit 804fd0c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 67 deletions.
55 changes: 27 additions & 28 deletions vector/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"cogentcore.org/core/events"
"cogentcore.org/core/gi"
"cogentcore.org/core/giv"
"cogentcore.org/core/ki"
"cogentcore.org/core/mat32"
"cogentcore.org/core/styles"
Expand Down Expand Up @@ -45,35 +46,19 @@ func (gv *VectorView) ConfigSelectToolbar() {

gi.NewSeparator(tb)

gv.NewSelectButton(tb).SetText("Group").
SetIcon("sel-group").SetShortcut("Command+G").
SetTooltip("Group items together").
OnClick(func(e events.Event) {
gv.SelGroup()
})
gv.NewSelectFuncButton(tb, gv.SelGroup).SetText("Group").
SetIcon("sel-group").SetShortcut("Command+G")

gv.NewSelectButton(tb).SetText("Ungroup").
SetIcon("sel-ungroup").SetShortcut("Shift+Command+G").
SetTooltip("Ungroup items").
OnClick(func(e events.Event) {
gv.SelUnGroup()
})
gv.NewSelectFuncButton(tb, gv.SelUnGroup).SetText("Ungroup").
SetIcon("sel-ungroup").SetShortcut("Shift+Command+G")

gi.NewSeparator(tb)

gv.NewSelectButton(tb).SetIcon("sel-rotate-left").
SetShortcut("Command+[").
SetTooltip("Rotate selection 90 degrees counter-clockwise").
OnClick(func(e events.Event) {
gv.SelRotateLeft()
})
gv.NewSelectFuncButton(tb, gv.SelRotateLeft).SetText("").
SetIcon("sel-rotate-left").SetShortcut("Command+[")

gv.NewSelectButton(tb).SetIcon("sel-rotate-right").
SetShortcut("Command+]").
SetTooltip("Rotate selection 90 degrees clockwise").
OnClick(func(e events.Event) {
gv.SelRotateRight()
})
gv.NewSelectFuncButton(tb, gv.SelRotateRight).SetText("").
SetIcon("sel-rotate-right").SetShortcut("Command+]")

gv.NewSelectButton(tb).SetIcon("sel-flip-horiz").
SetTooltip("Flip selection horizontally").
Expand Down Expand Up @@ -150,6 +135,16 @@ func (gv *VectorView) NewSelectButton(par ki.Ki) *gi.Button {
return bt
}

// NewSelectFuncButton returns a new func button that is only enabled when
// there is an item selected.
func (gv *VectorView) NewSelectFuncButton(par ki.Ki, fun any) *giv.FuncButton {
bt := giv.NewFuncButton(par, fun)
bt.StyleFirst(func(s *styles.Style) {
s.SetEnabled(gv.EditState.HasSelected())
})
return bt
}

// UpdateSelectToolbar updates the select toolbar based on current selection
func (gv *VectorView) UpdateSelectToolbar() {
tb := gv.SelectToolbar()
Expand Down Expand Up @@ -339,7 +334,8 @@ func (sv *SVGView) SetRubberBand(cur image.Point) {
///////////////////////////////////////////////////////////////////////
// Actions

func (gv *VectorView) SelGroup() {
// SelGroup groups items together
func (gv *VectorView) SelGroup() { //gti:add
es := &gv.EditState
if !es.HasSelected() {
return
Expand Down Expand Up @@ -369,7 +365,8 @@ func (gv *VectorView) SelGroup() {
gv.ChangeMade()
}

func (gv *VectorView) SelUnGroup() {
// SelUnGroup ungroups items from each other
func (gv *VectorView) SelUnGroup() { //gti:add
es := &gv.EditState
if !es.HasSelected() {
return
Expand Down Expand Up @@ -452,11 +449,13 @@ func (gv *VectorView) SelScale(scx, scy float32) {
gv.ChangeMade()
}

func (gv *VectorView) SelRotateLeft() {
// SelRotateLeft rotates the selection 90 degrees counter-clockwise
func (gv *VectorView) SelRotateLeft() { //gti:add
gv.SelRotate(-90)
}

func (gv *VectorView) SelRotateRight() {
// SelRotateRight rotates the selection 90 degrees clockwise
func (gv *VectorView) SelRotateRight() { //gti:add
gv.SelRotate(90)
}

Expand Down
21 changes: 6 additions & 15 deletions vector/svgview.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,22 +639,13 @@ func (sv *SVGView) MakeNodeContextMenu(m *gi.Scene, kn ki.Ki) {
gi.NewButton(m).SetText("Select in tree").SetIcon(icons.Select).OnClick(func(e events.Event) {
sv.VectorView.SelectNodeInTree(kn, events.SelectOne)
})

gi.NewSeparator(m)
gi.NewButton(m).SetText("Duplicate").SetIcon(icons.Copy).SetKey(keyfun.Duplicate).OnClick(func(e events.Event) {
sv.VectorView.DuplicateSelected()
})
gi.NewButton(m).SetText("Copy").SetIcon(icons.Copy).SetKey(keyfun.Copy).OnClick(func(e events.Event) {
sv.VectorView.CopySelected()
})
gi.NewButton(m).SetText("Cut").SetIcon(icons.Cut).SetKey(keyfun.Cut).OnClick(func(e events.Event) {
sv.VectorView.CutSelected()
})
gi.NewButton(m).SetText("Cut").SetIcon(icons.Cut).SetKey(keyfun.Cut).OnClick(func(e events.Event) {
sv.VectorView.CutSelected()
})
gi.NewButton(m).SetText("Paste").SetIcon(icons.Paste).SetKey(keyfun.Paste).OnClick(func(e events.Event) {
sv.VectorView.PasteClip()
})

giv.NewFuncButton(m, sv.VectorView.DuplicateSelected).SetText("Duplicate").SetIcon(icons.Copy).SetKey(keyfun.Duplicate)
giv.NewFuncButton(m, sv.VectorView.CopySelected).SetText("Copy").SetIcon(icons.Copy).SetKey(keyfun.Copy)
giv.NewFuncButton(m, sv.VectorView.CutSelected).SetText("Cut").SetIcon(icons.Cut).SetKey(keyfun.Cut)
giv.NewFuncButton(m, sv.VectorView.PasteClip).SetText("Paste").SetIcon(icons.Paste).SetKey(keyfun.Paste)
}

// ContextMenuPos returns position to use for context menu, based on input position
Expand Down
8 changes: 4 additions & 4 deletions vector/treeview.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (gv *VectorView) SelectedAsTreeViews() []*giv.TreeView {
}

// DuplicateSelected duplicates selected items in SVG view, using TreeView methods
func (gv *VectorView) DuplicateSelected() {
func (gv *VectorView) DuplicateSelected() { //gti:add
tvl := gv.SelectedAsTreeViews()
if len(tvl) == 0 {
gv.SetStatus("Duplicate: no tree items found")
Expand All @@ -82,7 +82,7 @@ func (gv *VectorView) DuplicateSelected() {
}

// CopySelected copies selected items in SVG view, using TreeView methods
func (gv *VectorView) CopySelected() {
func (gv *VectorView) CopySelected() { //gti:add
tvl := gv.SelectedAsTreeViews()
if len(tvl) == 0 {
gv.SetStatus("Copy: no tree items found")
Expand All @@ -95,7 +95,7 @@ func (gv *VectorView) CopySelected() {
}

// CutSelected cuts selected items in SVG view, using TreeView methods
func (gv *VectorView) CutSelected() {
func (gv *VectorView) CutSelected() { //gti:add
tvl := gv.SelectedAsTreeViews()
if len(tvl) == 0 {
gv.SetStatus("Cut: no tree items found")
Expand All @@ -120,7 +120,7 @@ func (gv *VectorView) CutSelected() {
}

// PasteClip pastes clipboard, using cur layer etc
func (gv *VectorView) PasteClip() {
func (gv *VectorView) PasteClip() { //gti:add
md := goosi.TheApp.Clipboard().Read([]string{fi.DataJson})
if md == nil {
return
Expand Down
26 changes: 6 additions & 20 deletions vector/vectorview.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"cogentcore.org/core/goosi"
"cogentcore.org/core/grr"
"cogentcore.org/core/icons"
"cogentcore.org/core/keyfun"
"cogentcore.org/core/ki"
"cogentcore.org/core/mat32"
"cogentcore.org/core/styles"
Expand Down Expand Up @@ -486,26 +487,11 @@ func (vv *VectorView) ConfigToolbar(tb *gi.Toolbar) {

gi.NewSeparator(tb)

tb.AddAction(gi.ActOpts{Label: "Duplicate", Icon: "documents", Tooltip: "Duplicate current selection -- original items will remain selected", UpdateFunc: vv.SelectedEnableFunc},
vv.This(), func(recv, send ki.Ki, sig int64, data any) {
grr := recv.Embed(KiT_VectorView).(*VectorView)
grr.DuplicateSelected()
})
tb.AddAction(gi.ActOpts{Label: "Copy", Icon: "copy", Tooltip: "Copy current selection to clipboard", UpdateFunc: vv.SelectedEnableFunc},
vv.This(), func(recv, send ki.Ki, sig int64, data any) {
grr := recv.Embed(KiT_VectorView).(*VectorView)
grr.CopySelected()
})
tb.AddAction(gi.ActOpts{Label: "Cut", Icon: "cut", Tooltip: "Cut current selection -- delete and copy to clipboard", UpdateFunc: vv.SelectedEnableFunc},
vv.This(), func(recv, send ki.Ki, sig int64, data any) {
grr := recv.Embed(KiT_VectorView).(*VectorView)
grr.CutSelected()
})
tb.AddAction(gi.ActOpts{Label: "Paste", Icon: "paste", Tooltip: "Paste clipboard contents", UpdateFunc: vv.PasteAvailFunc},
vv.This(), func(recv, send ki.Ki, sig int64, data any) {
grr := recv.Embed(KiT_VectorView).(*VectorView)
grr.PasteClip()
})
giv.NewFuncButton(tb, vv.DuplicateSelected).SetText("Duplicate").SetIcon(icons.Copy).SetKey(keyfun.Duplicate)
giv.NewFuncButton(tb, vv.CopySelected).SetText("Copy").SetIcon(icons.Copy).SetKey(keyfun.Copy)
giv.NewFuncButton(tb, vv.CutSelected).SetText("Cut").SetIcon(icons.Cut).SetKey(keyfun.Cut)
giv.NewFuncButton(tb, vv.PasteClip).SetText("Paste").SetIcon(icons.Paste).SetKey(keyfun.Paste)

gi.NewSeparator(tb, "sep-import")
tb.AddAction(gi.ActOpts{Label: "Add Image...", Icon: "file-image", Tooltip: "add an image from a file"},
vv.This(), func(recv, send ki.Ki, sig int64, data any) {
Expand Down

0 comments on commit 804fd0c

Please sign in to comment.