8000 getting canvas working by rcoreilly · Pull Request #370 · cogentcore/cogent · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

getting canvas working #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 102 commits into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
25be926
canvas: basic rendering, selection working
rcoreilly May 19, 2025
3641163
canvas: grid rendering
rcoreilly May 19, 2025
72f1da8
canvas: sprites logic updated to new batch-mode; new drag items working
rcoreilly May 19, 2025
52699a3
canvas: updated to math32.Vector2 bboxes in svg, all the basic zoom, …
rcoreilly May 20, 2025
5a10a26
canvas: ZoomAt is now 100% good. it still diverges outside of center…
rcoreilly May 20, 2025
09393a0
canvas: align fixed, and sel points updated in UpdateView
rcoreilly May 20, 2025
8db50ff
canvas: bidirectional PaintSetter updating and setting minimally working
rcoreilly May 20, 2025
ae8131c
canvas: updated to latest color picker behavior and Input vs. Change …
rcoreilly May 20, 2025
57ebc1e
use HandleValueOnInput for color pickers
rcoreilly May 21, 2025
c33ee91
canvas: markers all working
rcoreilly May 21, 2025
be3845c
canvas: dashes working
rcoreilly May 21, 2025
f9170f9
canvas: marker and dash icon styling
rcoreilly May 22, 2025
9bdfccc
better del scaling logic for zoom, pan
rcoreilly May 22, 2025
2621bba
canvas: gradients mostly working - stroke not quite.
rcoreilly May 22, 2025
5a3763f
canvas: gradients all working with updating of stops etc. using new I…
rcoreilly May 22, 2025
61debab
canvas: tree and layer dynamics mostly working
rcoreilly May 22, 2025
3b3e7b6
canvas: svg context menu working
rcoreilly May 22, 2025
00cfaad
canvas: sync to layers updates props too -- layers all good now.
rcoreilly May 22, 2025
e485e26
canvas: layer styling improved
rcoreilly May 22, 2025
7642b20
canvas: set opacity and stroke width updates -- everything working fo…
rcoreilly May 23, 2025
89abdb7
canvas: lots of fixes for gradient, metadata, etc; basic creation, sa…
rcoreilly May 23, 2025
dec973f
canvas: clipboard ops, paint off updating etc fixed: properly setting…
rcoreilly May 23, 2025
94ecb11
canvas: tool selection by key, update modal toolbar
rcoreilly May 23, 2025
4697b7d
canvas: text mostly working
rcoreilly May 24, 2025
3840fea
canvas: text mostly working
rcoreilly May 24, 2025
fa8013e
canvas: svg node tranform logic finally correct. todo: remove the mat…
rcoreilly May 24, 2025
3ab3ef3
canvas: update to new ApplyTransform paradigm in core svg. all good e…
rcoreilly May 26, 2025
79657d6
canvas: minor tweaks. arrows are off on fig_synapse.svg :(
rcoreilly May 26, 2025
7af3c8c
canvas: openfiles logic in NewWindow -- problem is that it will keep …
rcoreilly May 26, 2025
3430d57
canvas: canvas and code now fully support all modalities of os-based …
rcoreilly May 26, 2025
10238e4
canvas: start on new sprites
rcoreilly May 27, 2025
3f3fcdd
canvas: rubber band, sel sprites, etc
rcoreilly May 28, 2025
cfd170f
canvas: align and multi-select updating working -- now just need nodes.
rcoreilly May 28, 2025
93b1053
canvas: path node editing working for node points
rcoreilly May 28, 2025
bffeedf
canvas: quad and cube control point editing working
rcoreilly May 28, 2025
085fd31
canvas: cube goes with correct node
rcoreilly May 28, 2025
5e97cd2
canvas: insert nodes working
rcoreilly May 29, 2025
67919bd
canvas: all the basic path ops working -- just need initial drag logic..
rcoreilly May 29, 2025
a3e7c14
canvas: updates to core and node selection logic mostly working; read…
rcoreilly May 29, 2025
cad4da4
canvas: select box tool (box select without intrusive select on click…
rcoreilly May 30, 2025
82479ee
canvas: fix raise / lower logic
rcoreilly May 30, 2025
8743b45
canvas: ungroup singletons and remove empty groups
rcoreilly May 30, 2025
9aed44c
canvas: basic drawing working
rcoreilly May 30, 2025
3e4dd72
canvas: tool help in status, start on add line sprite
rcoreilly May 30, 2025
55cb6de
canvas: save paths, splits infrastructure
rcoreilly May 30, 2025
22e5bdd
canvas: path closing, keys, line sprite, etc
rcoreilly May 30, 2025
bf30d0e
canvas: better sizing logic
rcoreilly May 30, 2025
f49f661
canvas: update to latest core go mod
rcoreilly May 30, 2025
aebebf4
canvas: update to core xyz text build bug
rcoreilly May 30, 2025
125a77b
canvas: autosave logic in place
rcoreilly May 30, 2025
ded9a10
canvas: go mod update
rcoreilly May 31, 2025
b33af7c
canvas: fix group property inheritance to 8000 ignore root and layers.
rcoreilly May 31, 2025
34b2521
canvas: add cap and join line properties, cleanup some more of the pr…
rcoreilly May 31, 2025
5248c20
canvas: cursor updating but not working..
rcoreilly Jun 1, 2025
15851dc
canvas: major simplifying rename of edit state vars; draw snapping
rcoreilly Jun 1, 2025
364b409
canvas: grid snapping significantly improved, but size is too large
rcoreilly Jun 1, 2025
4281ee6
canvas: align points updates -- needs more work
rcoreilly Jun 2, 2025
15d07d0
canvas: reset sels; need align logic for single points..
rcoreilly Jun 2, 2025
771c130
canvas: fixed selection points
rcoreilly Jun 2, 2025
0d60e14
canvas: snap point working: missing !
rcoreilly Jun 2, 2025
71c7072
canvas: node adjust snap working using original values
rcoreilly Jun 2, 2025
83f6cba
canvas: zero angle restores transform -- ApplyTransform doesn't other…
rcoreilly Jun 2, 2025
09a0e5d
canvas: update go mod -- canvas should finally be done.
rcoreilly Jun 2, 2025
b15ca72
canvas: use viewbox for physical size from SVG, not physical units
rcoreilly Jun 2, 2025
b8a9daf
canvas: use intersect.Contains for path selection -- major improvemen…
rcoreilly Jun 2, 2025
9f022c3
canvas: only render control points for selected nodes in node editor
rcoreilly Jun 2, 2025
4016cc1
canvas: more readme updates, control points only for selected nodes.
rcoreilly Jun 2, 2025
3ae7a6b
canvas: cursors now working with core fix; node select update logic p…
rcoreilly Jun 2, 2025
28d5938
canvas: opacity was actually not being supported at all for paint. ki…
rcoreilly Jun 3, 2025
7290eb1
canvas: general opacity and core mod update
rcoreilly Jun 3, 2025
fec4749
canvas: exclude text from distribute props; update after open files.
rcoreilly Jun 3, 2025
022e4bb
canvas: added fill-rule -- now have all paint properties except miter…
rcoreilly Jun 3, 2025
bd84821
canvas: fixes to layer syncing -- was destructive and buggy..
rcoreilly Jun 3, 2025
3b0f091
canvas: control nodes updated to from-start dv mech; update start at …
rcoreilly Jun 4, 2025
1df0f77
canvas: update to latest core
rcoreilly Jun 4, 2025
9c1d461
canvas: cleanup inkscape text on loading -- so many unnec standard pr…
rcoreilly Jun 6, 2025
8967247
canvas: major speedup for opening a new project in code: do not call …
rcoreilly Jun 10, 2025
5f8c336
clock: animate main page
kkoreilly Jun 10, 2025
3f2a8c8
clock: start on directory reorganization
kkoreilly Jun 10, 2025
2568c16
clock: move logic to clock package
kkoreilly Jun 10, 2025
b035712
clock: start on timer
kkoreilly Jun 10, 2025
70295f9
clock: more timer progress
kkoreilly Jun 10, 2025
107ce9d
clock: implement correct remaining logic based on start
kkoreilly Jun 10, 2025
727fb7f
clock: improve timer styling
kkoreilly Jun 10, 2025
2526235
clock: pause button
kkoreilly Jun 10, 2025
4df1d0e
clock: fix pause logic
kkoreilly Jun 10, 2025
f1d9ff8
clock: improve timer grid styling
kkoreilly Jun 10, 2025
6e978bd
clock: add reset button
kkoreilly Jun 10, 2025
0de93d8
clock: improve pause button done and reset logic
kkoreilly Jun 10, 2025
123c579
clock: add name
kkoreilly Jun 10, 2025
059daf9
canvas: canvas toolbar, duplicate with gradient fixes
rcoreilly Jun 11, 2025
ffee0aa
canvas: update to latest core
rcoreilly Jun 11, 2025
d61f6ac
cavas: rename Locked -> NoLock
rcoreilly Jun 12, 2025
ba616b5
canvas: code sets focused flag on find texteditor -- ensures cursor u…
rcoreilly Jun 12, 2025
343df9c
code: clean up symbolspanel branch styling
kkoreilly Jun 18, 2025
2687ea8
update core
kkoreilly Jun 19, 2025
84ae8d5
canvas: add links to deployed web version in readme
kkoreilly Jun 19, 2025
7fc36af
canvas bugs
rcoreilly Jun 20, 2025
554d47e
canvas: replace rubberband with standard select icon
rcoreilly Jun 20, 2025
d8f972b
canvas: fixes from PR review
rcoreilly Jun 20, 2025
cda0909
canvas: undo uses xml instead of json -- json doesn't save images cor…
rcoreilly Jun 20, 2025
9b4c780
canvas: fix typo in setting stroke-width property
rcoreilly Jun 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 38 additions & 57 deletions canvas/README.md
Original file line number Diff line number Diff line change
@@ -1,100 +1,81 @@
![alt tag](logo/grid-icon.png)
![alt tag](cmd/canvas/icon.svg)

Cogent Canvas is a Cogent Core based SVG vector drawing program, with design based on Inkscape.
[Cogent Canvas](https://cogentcore.org/cogent/canvas) is an SVG-based vector drawing program, with basic capabilities similar to [Inkscape](https://inkscape.org), although it currently lacks many of the more advanced features (see [TODO](#todo) list below for plans). The native file format is SVG, with optional Inkscape-based metadata to encode advanced style properties.

# Behavior
The Canvas interface is designed to make the high-frequency operations obvious and easy to access, and compared to Inkscape or Adobe Illustrator, it should generally be easier to use by a naive user. It also provides a full tree view into the underlying SVG structure, so you can easily directly manipulate it.

* multiple select actions keep doing down even inside groups, so it is easy to operate inside groups but group is the "default"
Because it is written in [Cogent Core](https://cogentcore.org), it also runs on the web and mobile devices.

* Alt on control knobs -> rotate instead of clicking again to get rotation knobs -- this is compatible with above and better :)
## Behavior

# Install
* Multiple select actions keep doing down even inside groups, and you can always perform operations on elements inside groups, so you don't need to ungroup and re-group.

The simple Go install command should work:
* To support the above behavior, you need to hold down the `Alt` key on control knobs to rotate, whereas Inkscape uses further clicking to switch between move and rotate.

## Install

You can use the [deployed web version](https://cogentcore.org/cogent/canvas). You can also use the simple Go install command:

```bash
$ go install cogentcore.org/cogent/canvas/cmd/canvas@main
```

Exporting PNG and PDF depends on https://inkscape.org -- on the Mac you need to make a link to `/usr/local/bin` and likewise for Linux:
Exporting to PDF currently depends on [Inkscape](https://inkscape.org). On the Mac you need to make a link to `/usr/local/bin` and likewise for Linux:

```bash
$ sudo ln -s /Applications/Inkscape.app/Contents/MacOS/inkscape /usr/local/bin/
```

# Design

Similar to inkscape in overall layout, and read / write inkscape compatible SVG files.

* Main horiz toolbar(s) across top -- top one is static, bottom one is dynamic based on selection / tool mode.

* Left vert toolbar with drawing tools

* Left panel with drawing structure. This is just like GiEditor tree -- provides direct access as needed. In particular this provides layer-level organization -- always have a layer group by default, and can drag items into different layers, and also have view and freeze flags on layers. usu only show layer level, and selection there determines which layer things are added to!

* Main middle panel with drawing. Grid underlay is a separate image that is drawn first, updated with any changes.

* Right tab panel with all the controls, just like gide in terms of tab & Inkscape overall. tabs are easier to find vs. inkscape.

* code in main grid package provides all the editors for right tabs.

# Status

Basic functionality now in place:

* create: rect, ellipse, line, text, import image

* full basic paint settings (gradients, markers, etc), and text properties, editing
## Status

* dynamic guide alignment, Align panel
* June, 2025: full basic functionality now in place, including drawing new paths and editing path control points.

* basic node editor -- can move the main points, not the extra control points
## Tips

* full undo / redo for everything.
* Use layers! Incredibly useful for toggling editability and visibility of whole sets of elements. It is best to make the layers at the start and add as you go. Click on the layer to set which layer new elements are made in by default (duplicates always go into the same layer as the original).

* Settings
## TODO

# TODO:
Bugs:

* double-click on text brings up text bar and text panel
* images in svg are not clipping to bounds -- renderer should do this in pimage.

* add more layer logic -- if layers, everything should be in a layer?
* still getting zero slider not sending change in setting a black color

* import svg -- same as marker
### Simpler, near term

* add group / ungroup to context menu (conditional on selection n etc)
* ArcTo support in node editor, and arc tool.

* implement the full transform panel
* Gradient editor edits gradient control points.

* render gradient icons
* Figure out alternatives to modifier keys for for ipad.

* show selected path node in diff color.. red? node sel map
* Transform panel for numerical rotate, scale etc.

* rest of line properties -- easy
* Dropper = grab style from containing node, apply to selection -- don't affect selection!

* dropper = grab style from containsnode, apply to selection -- don't affect selection!
* Convert shape nodes to path: add `svg.Node` ToPath.

* svg.Node ToPath -- convert any node to a path
* node editor -- big job but needed for making basic bezier curves..
* Align panel: add distribute function.

* esc aborts new el drag
* Better ways of managing Text with multiple tspan elements: styles for tspan, generate full Text and spans from a rich text source with line wrapping and HTML markup -- need bidirectional support to / from existing tspans etc. Basic pos movement of sub-tspan would be useful.

* add distribute to Align
* Clip mask in `core.SVG` finally.

* svg.Text align Center, etc affects different tspans within overall text block
* Text edit panel -- finish toolbar
* Import svg -- same as marker (copy/paste is now working across drawings, so that is good).

* cut / paste not updating tree reliably. more tree update debugging fun!
* Path effects menu / chooser and add calls to the various existing ppath `intersect` and `stroke` functions.

* use grid itself to render all new icons!
### Longer term

* figure out mask clipping eventually.
* More natural drawing modes like freehand and calligraphy.

* More advanced path effects.

# LINKS
* More advanced drawing tools like grids, connected diagram elements (key!), etc.

Inkscape special flags
## Links

https://wiki.inkscape.org/wiki/index.php/Inkscape_SVG_vs._plain_SVG
* Inkscape special flags: https://wiki.inkscape.org/wiki/index.php/Inkscape_SVG_vs._plain_SVG


12 changes: 8 additions & 4 deletions canvas/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ const (
BoxSelect
SetStrokeColor
SetFillColor
SetOpacity
NewElement
NewText
NewPath
NodeMove
CtrlMove
)

// ActionHelpMap contains a set of help strings for different actions
// which are the names given e.g., in the ActStart, SaveUndo etc.
// ActionHelpMap contains a set of help strings for different actions.
var ActionHelpMap = map[Actions]string{
Move: "<b>Alt</b> = move without snapping, <b>Ctrl</b> = constrain to axis with smallest delta",
Reshape: "<b>Alt</b> = rotate, <b>Ctrl</b> = constraint to axis with smallest delta",
Move: "<b>Alt</b> = move without snapping, <b>Ctrl</b> = constrain to axis with smallest delta",
Reshape: "<b>Alt</b> = rotate, <b>Ctrl</b> = constrain to axis with smallest delta",
NodeMove: "<b>Alt</b> = only move node, not control points, <b>Ctrl</b> = constrain to axis with smallest delta",
CtrlMove: "<b>Ctrl</b> = constrain to axis with smallest delta",
}
Loading
Loading
0