Personal website
There a few features from the previous design post that did not make it into the pull request. These include:
Besides the controls for rounded rectangle, all of these use element-specific changes to the context menu. Right now, the context menu options are hard-coded, and only depend on whether or not a Segment was clicked. This needs to be changed before these options can be added.
The clicked
method on Elements was designed when the only Elements were
Paths. It returns if the path was clicked, and the segment that was clicked
(if any). Currently, the other shapes simply return null
for the segment,
but this is mostly incorrect for Polylines, Polygons, and possibly Lines.
The real issue comes when handling right-clicks and bringing up the context
menu. The menu adds items based on if a Segment was clicked and the
Segment’s segment_type
. Among other things, this includes splitting a
segment, which is necessary for making Polylines and Polygons useful.
However, Polylines and Polygons can only have Linear segments, so most of
the existing context menu would be useless. The context menu is also the
best way to change Elements to less restrictive supertypes, but there is
no way to do that with the current setup.
Right now, no new functionality will be added. This will be pure refactoring as much as possible, with the intent to add functionality in future features (still part of this release).
Planned menu options: (These will not all be present after this feature)
As always, this is a preliminary design, and it will likely change before implementation is finished. (This is the second version; the first was much more complicated and involved a new interface.)
The existing Segment
class will be split into three classes: Segment
,
PathSegment
, and LineSegment
. PathSegment
is the same as the current
Segment
class; LineSegment
is a version that can only be linear for
Polylines and Polygons, and Segment
is a base class so both can be used
in the clicked
handler.
Segments
and Elements
will get a new method called options()
. This
will return the options that should appear in the context menu as a list
of ContextOption
s.
ContextOption
This is a representation of options for the context menu. Similar to
PathSegment
, there are multiple constructors for different kinds of
options.
constructor ContextOption.action (string label, ActionCallback callback)
This is used for options that perform an action, similar to “Delete Path”. Options to convert to base path types will use this.
constructor ContextOption.toggle (string label, Undoable obj, string property)
This is used for toggleable option, such as “Enable Transform”. Rounding on rectangles (which I forgot to add earlier) will use this.
constructor ContextOption.options (Undoable obj, string property, List<string, int>)
This is used for switchable items, such as the PathSegment
segment
type selector. I think that is the only thing that will use this.
type delegate void ActionCallback()
This is used for callbacks on options. They should take no arguments and return no values; if external variables are needed (which they probably will), they must be taken by closure.
property ContextOptionType option_type
This holds the type of the option so the menu builder can tell how to load it.
property string label
For options that result in a single row (actions and toggles), this holds the text of the label.
Undoable target
property string prop
For options that apply to an object’s property, these properties store the object and property associated with it.
property Gee.Map<string, int> toggle_options
For toggle options, this stores the labels and values that can be switched between.
property ActionCallback callback
This holds the function to call when an Action option is selected.
ContextOptionType
Similar to the SegmentType enum, this determines what kind of option this is. Each kind has its own constructor, specified above.
ACTION
This is for options that call a function when selected, like
“Delete Path” or “Split Segment”. This uses the callback
property.
PROPERTY_TOGGLE
This is for toggled properties, like “Enable Transform”. This uses
the source_object
and source_property
properties.
PROPERTY_OPTION
This is for properties with multiple options, such as the Segment
Type selection. This uses the source_object
, source_property
, and
toggle_options
properties.
When a right click is detected, the menu will call options
on both the
segment (if present) and element, then parse the results into options to
put in the menu. Toggle options will be set to match the current state of
the associated property, and Options items will select the currently
selected option.