canvas::edit::polyline(3tk)

πŸ“¦
version 0.9 Β· 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

okay so bestie, this is the manual for canvas::edit::polyline(3tk) β€” that's the manual name right there, section 3tk and all β€” and the whole entire point of it is:

  • canvas::edit::polyline β€” Editing a polyline on a canvas πŸ’…

✨ SYNOPSIS ✨

like, here's the shape of the thing:

package require Tcl 8.5

package require Tk 8.5

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

package require canvas::edit::polyline ?0.2?

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

objectName destroy

objectName enable

objectName disable

objectName active

objectName add x y

objectName clear

activeCmd editorObj id

createCmd canvas x y

dataCmd editorObj coordinates

πŸ¦‹ DESCRIPTION πŸ¦‹

So this package hands you a class, and instances of that class are in charge of editing exactly one poly-line (or -gon, iykyk) on a canvas. One line. One editor. Main character energy, no sharing.

You can configure instances for the visual appearance of the little markers that denote the line's vertices ✨ β€” and also whether the line is closed or not, and further whether a closed line has to be convex or not. So many vibes to choose from.

⚠️ but here's the thing: instances do not store the edited polyline themselves. They delegate that to a configurable object. The editor is the editor, not the storage. Periodt.

πŸŽ€ INTERACTION πŸŽ€

ngl the polyline editor is lowkey a glow-up of another package: internally it uses an instance of canvas::edit::points, and it inherits all the options and behaviours from it. The color options get additionally applied to the line element of this editor. So yeah, it's giving "I got it from my mama."

Beyond that, it provides 2 options to configure the editing mode, plus one option to customize the line/polygon item that's used to render the line through the points.

The main editing mode is controlled by the option -closed, which picks line (i.e. open) versus polygon (i.e. closed). The default is line/open mode. 🌸

In polygon/closed mode, the option -convex controls if the editor enforces convexity of the polygon, or not. The default is no enforcement of convexity. So it's chill by default.

The option -line-config enables basic customization of the line/polygon item. 🎨 Note that it cannot override the inherited color options β€” those stay winning.


πŸ‘‘ CLASS API πŸ‘‘

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

This, the class command, creates and configures a new instance of a polyline editor, named objectName. That instance will be connected to the specified canvas widget. 🫢

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

The options accepted here, and their values, are explained in the section Options. (iykyk where to look)


πŸ’€ 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. So like, the editor dips but the art stays. πŸ–ΌοΈ

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 interrogatory method for the current state 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 interrogatory method for the current state 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. So it's not inserting itself politely, it's just going to the back of the line like a good lil queue member. 🧚

This is the method through which 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.


and that's where part 1 wraps β€” more incoming, don't go anywhere bestie πŸ’œ

✨ OPTIONS ✨

The class command accepts the following options, bestie. Read them all, there are a bunch πŸ’…

  • -active-cmd command-prefix β€” this one is a command prefix the editor invokes the moment the mouse enters or leaves the line, or any point managed by the instance. If you don't set it, it defaults to an empty command that literally does nothing. 🌸

The signature of this command prefix is:

activeCmd editorObj id

So like β€” the id tells you which object got entered. An empty id means the last entered object was left. The value line means the line itself was entered. And a numeric value N means the N'th vertex of the line was entered, counting from 0. The result of this method is ignored, so don't stress about returning anything cute. πŸŽ€

  • -add-remove-point eventspec β€” this is an event specification (without bracketing angles, so no < > around it) declaring which event will trigger adding and removing a point. Lowkey important: this option can only be set at construction time. 🫢

The default setup uses different events for adding and removing points β€” ButtonPress-1 and ButtonPress-2 respectively. When you use this option, the same event gets used for both operations. Which is no problem at all because adding is bound as a canvas-global event while removal is bound to the relevant canvas items. Periodt. ✨

  • -closed boolean β€” a boolean flag saying whether the edited polyline is closed (i.e. a loop) or not. NOTE that a proper loop requires at least 3 points. For less than that, an open line is shown, or even just a point. πŸ™ˆ This option can only be set at construction time. If not specified it defaults to false.
  • -color colorspec β€” the fill color for the default item created when adding a point, and no -create-cmd is specified. The default value is SkyBlue2. πŸ’™
  • -convex boolean β€” a boolean flag saying whether the edited polyline is strictly convex or not. This option has meaning if and only if option -closed is configured to be true. This option can only be set at construction time. If not specified it defaults to false.
  • -create-cmd command-prefix β€” a command prefix the editor invokes when it has to create a new vertex. While this option can be set after construction, it is recommended to use this feature only as a means of inserting custom processing to be done at creation time which remembers and calls the previous value of the option. πŸ‘‘

If not specified it defaults to a command which will create 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 here 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 such is taken as a signal that the callback vetoed the creation of the vertex. (Vetoed! Iconic.)

  • -data-cmd command-prefix β€” 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. πŸ¦‹

  • -drag-point eventspec β€” an event specification (again, without bracketing angles) declaring which event will trigger a drag action on points. This option can only be set at construction time. The default specification is ButtonPress-3. πŸ”₯
  • -hilit-color colorspec β€” the highlight color for the default item created when adding a point, and no -highlight-cmd is specified. The default value is red. ❀️
  • -kind name β€” the canvas item type for the default item created when adding a point, and no -create-cmd is specified. Only item types specified through a bounding box are suitable, just so you know. The default value is oval.
  • -line-config list β€” a list of options and their values to be applied to the internal line/polygon item whenever it is regenerated after changes. Note that these options cannot override the principal coloring of the line/polygon as applied by the main options -color and -hilit-color. If not specified it defaults to the empty list.
  • -radius int β€” the radius for the default item created when adding a point, and no -create-cmd is specified. The default value is 3. ⭐
  • -tag string β€” the name of the canvas tag with which 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. πŸŽ€

πŸ› BUGS, IDEAS, FEEDBACK πŸ›

This document, and the package it describes, will undoubtedly contain bugs and other problems. Like, fr fr, nothing is perfect and that's okay bestie 😭. 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. We wanna hear it all πŸ’–


πŸ”‘ KEYWORDS πŸ”‘

canvas, editing, polyline


okay that's the whole page bestie, you ate that πŸ’…βœ¨ this came from the tklib source, version 0.2, and it's the canvas::edit::polyline(3tk) page β€” go forth and edit some polylines, main character πŸ‘‘πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from