Scenic.Primitive.Style behaviour (Scenic v0.11.0-beta.0) View Source

Modify the look of a primitive by applying a Style.

Styles are optional modifiers that you can put on any primitive. Each style does a specific thing and some only affect certain primitives.

Graph.build()
  |> rect( {100, 50}, fill: blue, stroke: {2, :yellow} )

The above example draws a rectangle, that is filled with blue and outlined in yellow. The primitive is Scenic.Primitive.Rectangle and the styles are :fill and :stroke.

Inheritance

Styles are inherited by primitives that are placed in a group. This allows you to set styles that will be used by many primitives. Those primitives can override the style set on the group by setting it again.

Example:

Graph.build( font: :roboto, font_size: 24 )
  |> text( "Some text drawn using roboto" )
  |> text( "Text using roboto_mono", font: :roboto_mono )
  |> text( "back to drawing in roboto" )

In the above example, the text primitives inherit the fonts set on the root group when the Graph is created. The middle text primitive overrides the :font style, but keeps using the :font_size set on the group.

Components

In general, styles are NOT inherited across a component boundary unless they are explicitly set on the component itself. This allows components to manage their own consistent look and feel.

The exception to this rule is the :theme style. This IS inherited across groups and into components. This allows you to set an overall color scheme such as :light or :dark that makes sense with the components.

Link to this section Summary

Functions

The default styles if none are set.

List of the valid style types

Link to this section Types

Specs

t() :: %{
  required([
    :cap
    | :fill
    | :font
    | :font_size
    | :hidden
    | :input
    | :join
    | :line_height
    | :miter_limit
    | :scissor
    | :stroke
    | :text_align
    | :text_base
    | :theme
  ]) => any()
}

Link to this section Callbacks

Specs

validate(data :: any()) :: {:ok, data :: any()} | {:error, String.t()}

Link to this section Functions

The default styles if none are set.

%{font: :roboto, font_size: 24, line_height: 1.2, text_align: :left, text_base: :alphabetic}

List of the valid style types