canvas::edit::polyline(n)

πŸ“¦ version 0.7, in alpine 3.24

🌸 NAME 🌸

okay bestie, welcome to canvas::edit::polyline(n) πŸ’– β€” this is the manual page for editing a polyline on a canvas. Lowkey iconic behavior.


✨ SYNOPSIS ✨

package require Tcl  8.5

package require Tk  8.5

package require canvas::edit::points  ?0.1?

package require canvas::edit::polyline  ?0.1?

::canvas::edit polyline objectName canvas options...

objectName destroy

objectName enable

objectName disable

objectName active

objectName add x y

objectName clear

createCmd canvas x y

highlightCmd on canvas item

highlightCmd off canvas state

dataCmd editorObj coordinates

πŸ¦‹ DESCRIPTION πŸ¦‹

This package gives you a class whose instances handle editing a single poly-line on a canvas. Instances can be configured for how the markers around the line's vertices look β€” both the regular look and the highlighted look ✨.

Important vibe check: instances do not store the edited polyline themselves. They delegate that whole storage situation to a configurable object. So the editor is the main character, but the storage object is holding the actual coordinates backstage πŸ’….


πŸ‘‘ CLASS API πŸ‘‘

::canvas::edit polyline objectName canvas options...

This is the class command, and it creates and configures a new instance of a polyline editor named objectName πŸ’–. The instance gets connected to the specified canvas widget.

The result of the command is the fully qualified name of the instance command. Slay.

The options accepted here, and their values, are explained in the Options section.


🧚 INSTANCE API 🧚

Instances of the polyline editors provide the following API:

objectName destroy

This method destroys the polyline editor and releases all its internal resources.

Note that this operation does not destroy the items the editor managed on the attached canvas, nor the canvas itself. It's giving "clean up your own room, not the whole house" πŸ’€.

The result of the method is an empty string.

objectName enable

This method activates editing of the polyline on the canvas. This is the default after instance creation. A call is ignored if the editor is already active.

The result of the method is an empty string.

The complementary method is disable. The state-checking method is active.

objectName disable

This method disables editing of the polyline on the canvas. A call is ignored if the editor is already disabled.

The result of the method is an empty string.

The complementary method is enable. The state-checking method is active.

objectName active

This method queries the editor state.

The result of the method is a boolean value: true if the editor is active, and false otherwise, i.e. disabled.

The methods to change the state are enable and disable.

objectName add x y

This method programmatically adds a vertex at the specified location to the line.

The result of the method is an empty string.

Note that this method goes through the whole set of callbacks invoked when the user interactively creates a vertex, i.e. -create-cmd, and, more importantly, -data-cmd.

One important difference however: the new vertex is always added at the end of the line, whereas interactive creation uses heuristics to splice it into the line at a suitable location.

This is the method you use to load the vertices of a pre-existing line into an editor instance 🫢.

objectName clear

This method programmatically removes all vertices from the editor, essentially removing the whole line.

The result of the method is an empty string.

Note that this method goes through the same callbacks invoked when the user interactively removes a vertex, i.e. -data-cmd.


🌈 OPTIONS 🌈

The class command accepts the following options:

  • -tag string β€” the value is the name of the canvas tag used to identify all items of all vertices managed by the editor.

This option can only be set at construction time.

If not specified, it defaults to POLYLINE.

  • -create-cmd command-prefix β€” the value is a command prefix the editor invokes when it has to create a new vertex.

This option can only be set at construction time.

If not specified, it defaults to a command which creates a black-bordered blue circle of radius 3 centered on the location of the new point.

The signature of this command prefix is:

createCmd canvas x y

The result of the command prefix must be a list of the canvas items it created to represent the marker. Note that the visual representation of a "vertex" may consist of multiple canvas items in an arbitrary shape πŸ‘€.

The returned list of items is allowed to be empty, and that is taken as a signal that the callback vetoed the creation of the vertex.

  • -highlight-cmd command-prefix β€” the value is a command prefix the editor invokes when it has to (un)highlight a vertex.

This option can only be set at construction time.

If not specified, it defaults to a command which re-colors the item to highlight in red (and restores the color for unhighlighting).

The two signatures of this command prefix are:

highlightCmd on canvas item

This method of the command prefix has to perform whatever is needed to highlight the vertex the item is a part of β€” remember the note above about points being allowed to be constructed from multiple canvas items πŸŽ€.

The result of the command can be anything and will be passed as-is as the argument state to the off method.

highlightCmd off canvas state

This method is invoked to unhighlight a vertex described by state, which is the unchanged result of the on method of the command prefix. The result of this method is ignored.

Note that any interaction between dragging and highlighting of vertices is handled within the editor, and the callback bears no responsibility for doing such. The editor said "I got this," and honestly? It does πŸ’….
  • -data-cmd command-prefix β€” the value is a command prefix the editor invokes when the line was edited in some way (vertex added, removed, moved). This is how the editor delegates the actual storage of the line information to an outside object.

This option can only be set at construction time.

If not specified, it defaults to an empty string and is ignored by the editor, i.e. not invoked.

The signature of this command prefix is:

dataCmd editorObj coordinates

This callback is invoked when the line was changed either interactively, or programmatically. See instance method add for the latter.

The editorObj identifies the instance invoking the callback, whereas coordinates is a list of vertex locations, with each location a pair of x- and y-coordinates.

The result of this method is ignored.


πŸ’€ BUGS, IDEAS, FEEDBACK πŸ’€

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category canvas of the Tklib Trackers http://core.tcl.tk/tklib/reportlist. Please also report any ideas for enhancements you may have for either package and/or documentation. No gatekeeping, bestie β€” feedback is a love language πŸ’œ.


⭐ KEYWORDS ⭐

canvas, editing, polyline


πŸ’– cute little sign-off: this page comes from tklib, version 0.1, and its manual name is canvas::edit::polyline(n). The footer doesn't show a separate date, so no fake date is being invented here β€” periodt πŸŽ€βœ¨

πŸ“¦ where this page comes from