Skip to content

Commit

Permalink
got vector running without immediately crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Feb 25, 2024
1 parent 626a427 commit 8cbe461
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 69 deletions.
3 changes: 1 addition & 2 deletions vector/align.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,10 @@ func (sv *SVGView) GatherAlignPoints() {
///////////////////////////////////////////////////////////////
// AlignView

func (av *AlignView) Config(vv *VectorView) {
func (av *AlignView) Config() {
if av.HasChildren() {
return
}
av.VectorView = vv
av.Style(func(s *styles.Style) {
s.Direction = styles.Column
})
Expand Down
33 changes: 13 additions & 20 deletions vector/dashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ package vector

import (
"fmt"
"maps"
"math"
"slices"
"strings"

"cogentcore.org/core/gi"
"cogentcore.org/core/icons"
"cogentcore.org/core/mat32"
"cogentcore.org/core/svg"
"cogentcore.org/core/units"
)

// DashMulWidth returns the dash array multiplied by the line width -- what is actually set
Expand Down Expand Up @@ -193,26 +190,22 @@ func DashIconsInit() {
AllDashIconNames[i] = icons.Icon(v)
}

for k, v := range AllDashesMap {
ic := &gi.SVG{}
ic.InitName(ic, k)
ic.SetProp("width", units.Ch(20))
ic.SVG.Root.ViewBox.Size = mat32.V2(1, 1)
p := svg.NewPath(ic, "p", "M 0.05 0.5 .95 0.5 Z")
p.SetProp("stroke-width", units.Pw(2))
p.SetProp("stroke-dasharray", DashString(DashMulWidth(.05, v)))
// svg.CurIconSet[ic.Nm] = ic
}
// for k, v := range AllDashesMap {
// ic := &gi.SVG{}
// ic.InitName(ic, k)
// ic.SetProp("width", units.Ch(20))
// ic.SVG.Root.ViewBox.Size = mat32.V2(1, 1)
// p := svg.NewPath(ic, "p", "M 0.05 0.5 .95 0.5 Z")
// p.SetProp("stroke-width", units.Pw(2))
// p.SetProp("stroke-dasharray", DashString(DashMulWidth(.05, v)))
// // svg.CurIconSet[ic.Nm] = ic
// }
DashIconsInited = true
}

func init() {
AllDashesMap = make(map[string][]float64, len(StdDashesMap))
AllDashNames = make([]string, len(StdDashNames))
for k, v := range StdDashesMap {
AllDashesMap[k] = v
}
for i, v := range StdDashNames {
AllDashNames[i] = v
}
maps.Copy(AllDashesMap, StdDashesMap)
copy(AllDashNames, StdDashNames)
}
87 changes: 42 additions & 45 deletions vector/markers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import (
"maps"
"strings"

"cogentcore.org/core/gi"
"cogentcore.org/core/icons"
"cogentcore.org/core/ki"
"cogentcore.org/core/laser"
"cogentcore.org/core/mat32"
"cogentcore.org/core/svg"
"cogentcore.org/core/units"
)

// MarkerFromNodeProp returns the marker name (canonicalized -- no id)
Expand Down Expand Up @@ -124,7 +121,7 @@ func MarkerDeleteCtxtColors(mk *svg.Marker) {

// NewMarkerFromXML makes a new marker from given XML source.
func NewMarkerFromXML(name, xml string) *svg.Marker {
tmpsvg := &svg.SVG{}
tmpsvg := svg.NewSVG(0, 0)
b := bytes.NewBufferString(xml)
err := tmpsvg.ReadXML(b)
if err != nil && err != io.EOF {
Expand Down Expand Up @@ -284,47 +281,47 @@ func MarkerIconsInit() {

AllMarkersSVGMap = make(map[string]*svg.Marker, len(AllMarkersXMLMap))

for k, v := range AllMarkersXMLMap {
empty := true
if v != "" {
mk := NewMarkerFromXML(k, v)
if mk == nil { // badness
continue
}
empty = false
AllMarkersSVGMap[k] = mk
}
ic := &gi.Icon{}
ic.InitName(ic, "marker-"+k) // keep it distinct with marker- prefix
ic.Styles.Min.X.Ch(6)
ic.Styles.Min.Y.Em(2)
ic.SVG.Root.ViewBox.Size = mat32.V2(1, 1)
var p *svg.Path
lk := strings.ToLower(k)
start := true
switch {
case empty:
p = svg.NewPath(ic, "p", "M 0.1 0.5 0.9 0.5 Z")
case strings.Contains(lk, "end"):
start = false
p = svg.NewPath(ic, "p", "M 0.8 0.5 0.9 0.5 Z")
case strings.Contains(lk, "start"):
p = svg.NewPath(ic, "p", "M 0.1 0.5 0.2 0.5 Z")
default:
p = svg.NewPath(ic, "p", "M 0.4 0.5 0.5 0.5 Z")
}
p.SetProp("stroke-width", units.Pw(5))
if !empty {
mk := NewMarker(&ic.SVG, k, 0)
MarkerDeleteCtxtColors(mk) // get rid of those context-stroke etc
if start {
p.SetProp("marker-start", svg.NameToURL(k))
} else {
p.SetProp("marker-end", svg.NameToURL(k))
}
}
// svg.CurIconSet[ic.Nm] = ic
}
// for k, v := range AllMarkersXMLMap {
// empty := true
// if v != "" {
// mk := NewMarkerFromXML(k, v)
// if mk == nil { // badness
// continue
// }
// empty = false
// AllMarkersSVGMap[k] = mk
// }
// ic := &gi.Icon{}
// ic.InitName(ic, "marker-"+k) // keep it distinct with marker- prefix
// ic.Styles.Min.X.Ch(6)
// ic.Styles.Min.Y.Em(2)
// ic.SVG.Root.ViewBox.Size = mat32.V2(1, 1)
// var p *svg.Path
// lk := strings.ToLower(k)
// start := true
// switch {
// case empty:
// p = svg.NewPath(ic, "p", "M 0.1 0.5 0.9 0.5 Z")
// case strings.Contains(lk, "end"):
// start = false
// p = svg.NewPath(ic, "p", "M 0.8 0.5 0.9 0.5 Z")
// case strings.Contains(lk, "start"):
// p = svg.NewPath(ic, "p", "M 0.1 0.5 0.2 0.5 Z")
// default:
// p = svg.NewPath(ic, "p", "M 0.4 0.5 0.5 0.5 Z")
// }
// p.SetProp("stroke-width", units.Pw(5))
// if !empty {
// mk := NewMarker(&ic.SVG, k, 0)
// MarkerDeleteCtxtColors(mk) // get rid of those context-stroke etc
// if start {
// p.SetProp("marker-start", svg.NameToURL(k))
// } else {
// p.SetProp("marker-end", svg.NameToURL(k))
// }
// }
// // svg.CurIconSet[ic.Nm] = ic
// }
MarkerIconsInited = true
}

Expand Down
4 changes: 2 additions & 2 deletions vector/vectorview.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,9 @@ func (gv *VectorView) Tab(label string) *gi.Frame {

func (vv *VectorView) ConfigTabs() {
pt := vv.RecycleTab("Paint", false)
NewPaintView(pt)
NewPaintView(pt).SetVectorView(vv)
at := vv.RecycleTab("Align", false)
NewAlignView(at)
NewAlignView(at).SetVectorView(vv)
vv.EditState.Text.Defaults()
tt := vv.RecycleTab("Text", false)
giv.NewStructView(tt).SetStruct(&vv.EditState.Text)
Expand Down

0 comments on commit 8cbe461

Please sign in to comment.