From 8cbe461a18f3512369114b08dc42c5eba9db27d7 Mon Sep 17 00:00:00 2001 From: Kai O'Reilly Date: Sat, 24 Feb 2024 22:18:12 -0800 Subject: [PATCH] got vector running without immediately crashing --- vector/align.go | 3 +- vector/dashes.go | 33 +++++++---------- vector/markers.go | 87 +++++++++++++++++++++----------------------- vector/vectorview.go | 4 +- 4 files changed, 58 insertions(+), 69 deletions(-) diff --git a/vector/align.go b/vector/align.go index 54e8f864..4590ddd6 100644 --- a/vector/align.go +++ b/vector/align.go @@ -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 }) diff --git a/vector/dashes.go b/vector/dashes.go index 52dbd34b..d5dd6f27 100644 --- a/vector/dashes.go +++ b/vector/dashes.go @@ -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 @@ -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) } diff --git a/vector/markers.go b/vector/markers.go index 3afbdeb5..195028a4 100644 --- a/vector/markers.go +++ b/vector/markers.go @@ -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) @@ -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 { @@ -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 } diff --git a/vector/vectorview.go b/vector/vectorview.go index b3316d92..d46becd1 100644 --- a/vector/vectorview.go +++ b/vector/vectorview.go @@ -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)