View Source Scenic.Primitive behaviour (Scenic v0.11.2)
Please see Primitives Overview
for a high-level description.
what-is-a-primitive
What is a primitive
A primitive is the simplest thing Scenic knows how to draw on the screen. There is a, fixed set of them, but they can be combined in a graph to draw very complicated images.
In general, each Primitive has a piece of data that it expects to operate on. For example, Primitive.Text requires a bitstring. Primitive.Circle requires a radius. Please see the documentation for each primitive for details.
how-to-use-primitives
How to use primitives
By far, the easiest way to use primitives is to import the helper functions in
Scenic.Primitives
. These helpers can both add primitives to
a scene you are building and modify later as you react to events.
import Scenic.Primitives
@graph Scenic.Graph.build()
|> rect({100, 50}, stroke: {1, :yellow})
|> rectangle({100, 50}, stroke: {1, :yellow})
Once you get a primitive out of a graph via functions such as Graph.modify
, or Graph.get
,
You can use the generic helpers in this module to access or manipulate them.
standard-primitives
Standard Primitives
The set of primitives supported in Scenic is fixed in any given version. They have been chosen to provide the maximum flexibility when combined together, while still requiring the minimal amount of code and maintenance.
See the documentation for each primitive's module for details on it's data type.
Helper | Primitive Module | Description |
---|---|---|
arc/3 | Scenic.Primitive.Arc | Draw an arc around a circle |
circle/3 | Scenic.Primitive.Circle | Draw a full circle |
ellipse/3 | Scenic.Primitive.Ellipse | Draw an ellipse |
group/3 | Scenic.Primitive.Group | Create a group |
line/3 | Scenic.Primitive.Line | Draw a line |
path/3 | Scenic.Primitive.Path | Draw a complicated path |
quad/3 | Scenic.Primitive.Quad | Draw a quad |
rect/3 | Scenic.Primitive.Rectangle | Draw a rectangle |
rrect/3 | Scenic.Primitive.RoundedRectangle | Draw a rounded rectangle |
script/3 | Scenic.Primitive.Script | Run a referenced draw script |
sector/3 | Scenic.Primitive.Sector | A boolean toggle control. |
sprites/3 | Scenic.Primitive.Sprites | Draw a sector |
text/3 | Scenic.Primitive.Text | Draw a string of text |
triangle/3 | Scenic.Primitive.Triangle | Draw a triangle |
Link to this section Summary
Functions
Generic builder to create a new primitive.
Determines if a point is contained within a primitive.
Deletes a specified style from a primitive.
Deletes a specified transform from a primitive.
Get the value of the primitive-specific data.
Get the value of a specific style set on the primitive.
Get the styles map from a primitive.
Get the value of a specific transform set on the primitive.
Get the transforms map from a primitive.
Merge an options-list of styles and transforms onto a primitive.
Put primitive-specific data onto the primitive.
Update the value of a specific style set on the primitive.
Update the styles map in a primitive.
Update the value of a specific transform set on the primitive.
Update the transforms map in a primitive.
Link to this section Types
Link to this section Callbacks
@callback compile(primitive :: t(), styles :: Scenic.Primitive.Style.t()) :: script :: Scenic.Script.t()
@callback valid_styles() :: list()
Link to this section Functions
Generic builder to create a new primitive.
This function is used internally. You should almost always use the helpers in
Scenic.Primitives
instead.
Parameters:
module
- The module of the primitive you are buildingdata
- the primitive-specific data being set into the primitiveopts
- a list of style and transform options to apply to the primitive
Returns the built primitive.
@spec contains_point?(primitive :: t(), point :: Scenic.Math.point()) :: map()
Determines if a point is contained within a primitive.
The supplied point must already be projected into the local coordinate space of the primitive. In other words, this test does NOT take into account any transforms that have been applied to the primitive.
The input mechanism takes care of this for you by projecting incoming points by the inverse-matrix of a primitive before calling this function...
Note that some primitives, such as Group, do not inherently have a notion of containing a point. In those cases, this function will always return false.
Parameters:
primitive
- The primitivepoint
- The point to test
Returns true
or false
.
Deletes a specified style from a primitive.
Does nothing if the style is not set.
Parameters:
primitive
- The primitivetype
- atom representing the style to delete.
Returns the updated primitive.
Deletes a specified transform from a primitive.
Does nothing if the transform is not set.
Parameters:
primitive
- The primitivetype
- atom representing the transform to delete.
Returns the updated primitive.
Get the value of the primitive-specific data.
Parameters:
primitive
- The primitive
Returns the value of the primitive-specific data.
Get the value of a specific style set on the primitive.
If the style is not set, it returns default
Parameters:
primitive
- The primitivetype
- atom representing the style to get.default
- default value to return if the style is not set.
Returns the value of the style.
Get the styles map from a primitive.
Parameters:
primitive
- The primitive
Returns the map of styles set directly onto this primitive. This does not include any inherited styles.
Get the value of a specific transform set on the primitive.
If the transform is not set, it returns default
Parameters:
primitive
- The primitivetype
- atom representing the transform to get.default
- default value to return if the transform is not set.
Returns the value of the transform.
Get the transforms map from a primitive.
Parameters:
primitive
- The primitive
Returns the map of transforms set directly onto this primitive. This does not include any inherited transforms.
Merge an options-list of styles and transforms onto a primitive.
This function might go through a name-change in the future. It is really more of a merge. The supplied list of styles and transforms
Parameters:
primitive
- The primitive
Returns the value of the primitive-specific data.
Put primitive-specific data onto the primitive.
Like many of the functions in the Scenic.Primitive
module, you are usually better
off using the helper functions in Scenic.Primitives
instead.
Parameters:
primitive
- The primitivedata
- The data to setopts
- A list of style/transform options to merge
Returns the updated primitive.
Update the value of a specific style set on the primitive.
Parameters:
primitive
- The primitivetype
- atom representing the style to get.data
- the value to set on the style.
Returns the updated primitive.
Update the styles map in a primitive.
Parameters:
primitive
- The primitivestyles
- The new styles map
Returns the primitive with the updated styles.
Update the value of a specific transform set on the primitive.
Parameters:
primitive
- The primitivetype
- atom representing the transform to get.data
- the value to set on the transform.
Returns the updated primitive.
Update the transforms map in a primitive.
Parameters:
primitive
- The primitivetransforms
- The new transforms map
Returns the primitive with the updated transforms.