Skip to content

Commit 6043ad1

Browse files
committed
reorganizing guides
1 parent a933aeb commit 6043ad1

File tree

7 files changed

+90
-10
lines changed

7 files changed

+90
-10
lines changed

guides/getting_started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,6 @@ Scenic.SensorPubSub service.
198198

199199
## What to read next?
200200

201-
Next, you should read about the [structure of a scene](scene_structure.html).
201+
Next, you should read about the [structure of a scene](overview_scene.html).
202202
This will explain the parts of a scene, how to send and receive messages and how
203203
to push the graph to the ViewPort.

guides/overview_graph.md

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,86 @@ screen, it pushes it to the Viewport.
88
Graphs are made out of a handful of primitives, each of which knows how to draw
99
one thing. When multiple primitives are put together, almost any standard UI can be drawn.
1010

11-
For example, the graph below
11+
For example, the graph below shows the words "Hello World" around them.
1212

13+
@graph Graph.build(font: :roboto, font_size: 24)
14+
|> text("Hello World", text_align: center, translate: {300, 300})
15+
|> circle(100, stroke: {2, :green} translate: {300, 300})
16+
17+
In the example above, the first line creates a new graph and assigns two font styles to its root. The next two lines form a pipeline that adds primitives to the root
18+
node of the new graph. Each of these primitives also assigns styles.
1319

1420
## Primitives
1521

16-
## The Group
22+
There is a fixed set of primitives that Scenic knows how to draw. These form the base set of things that you can do. While they seem simple, when combined you draw pretty much any 2D UI that you need.
23+
24+
[Read more about the primitives here.](overview_primitives.html)
25+
26+
In general, each primitive renders one thing to the screen. The Group primitive is
27+
sort of like a `<div>` tag in html in that it creates a new node in the graph hierarchy that more primitives can be organized beneath.
28+
29+
Each primitive can also be assigned styles and transforms, which affect how (or whether) they are drawn and where.
30+
31+
## Styles
32+
33+
In addition to the fixed set of primitives, there is also a fixed set of primitive styles. (Some components support more styles, but they really get boiled down to the primitive styles when it is time to render)
34+
35+
[Read more about the styles here.](overview_styles.html)
36+
37+
Styles are inherited down the graph hierarchy. This means that if you set a style on the root of a graph, or in a group, then any primitives below that node inherit those styles without needing to explicitly set them on every single primitive.
38+
39+
For example, in the following graph, the font and font_size styles are set at the root. Both text primitives inherit those values, although the second one overrides the size with something bigger.
40+
41+
@graph Graph.build(font: :roboto, font_size: 24)
42+
|> text("Hello World", translate: {300, 300})
43+
|> text("Bigger Hello", font_size: 40, translate: {400, 300})
44+
45+
46+
## Transforms
47+
48+
The final type of primitive control is transforms. Unlike html, which uses auto-layout to position items on the screen, Scenic moves primitives around using matrix based transforms. This is common in video games and provides powerful control of your primitives.
49+
50+
A [matrix](https://en.wikipedia.org/wiki/Matrix_(mathematics)) is an array of numbers that can be used to change the positions, rotations, scale and more of locations.
51+
52+
In Scenic, you will only rarely create matrices on your own (you can if you know what you are doing!), and will instead use the very easy transform helpers.
53+
54+
[You can read about the transform types here.](overview_transforms.html)
55+
56+
Transforms are inherited down the graph hierarchy. This means that if you place a rotation transform at the root of a graph, then all the primitives will be rotated around a common point.
57+
58+
If you want to zoom in, scroll, or rotate a UI, or just pieces of the UI, you can do that very easily by applying transforms.
59+
60+
In the example below, the first text line is translated, and the second is scaled bigger, and the whole graph rotated 0.4 radians.
61+
62+
@graph Graph.build(font: :roboto, font_size: 24, rotate: 0.4)
63+
|> text("Hello World", translate: {300, 300})
64+
|> text("Bigger Hello", font_size: 40, scale: 1.5)
1765

18-
## Position, rotation, scale and more
1966

2067
## Modifying a graph
2168

69+
Scenic was written specifically for Erlang/Elixir, which is a functional programming model with immutable data.
70+
71+
As such, once you make a graph, it stays in memory unchanged - until you change it via `Graph.modify/3`. Technically you never change it (that's the immutable part), instead Graph.modify returns a new graph with different data in it.
72+
73+
[Graph.modify/3](Scenic.Graph.html#modify/3) is the single Graph function that you will use the most.
74+
75+
For example, lets go back to our graph with the two text items in it.
76+
77+
@graph Graph.build(font: :roboto, font_size: 24, rotate: 0.4)
78+
|> text("Hello World", translate: {300, 300}, id: :small_text)
79+
|> text("Bigger Hello", font_size: 40, scale: 1.5, id: :big_text)
80+
81+
This time, we've assigned ids to both of the text primitives. This makes it easy to find and modify that primitive in the graph.
82+
83+
graph =
84+
@graph
85+
|> Graph.modify( :small_text, &text(&1, "Smaller Hello", font_size: 16))
86+
|> Graph.modify( :big_text, &text(&1, "Bigger Hello", font_size: 60))
87+
88+
Notice that the graph is modified multiple times in a pipeline.
89+
90+
2291
## Graph Internals
2392

2493

guides/overview_primitives.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
# Styles Overview
22

3-
Coming soon
3+
* [Arc](Scenic.Primitive.Arc)
4+
* [Circle](Scenic.Primitive.Circle)
5+
* [Ellipse](Scenic.Primitive.Ellipse)
6+
* [Group](Scenic.Primitive.Group)
7+
* [Line](Scenic.Primitive.Line)
8+
* [Path](Scenic.Primitive.Path)
9+
* [Quad](Scenic.Primitive.Quad)
10+
* [Rectangle](Scenic.Primitive.Rectangle)
11+
* [RoundedRectangle](Scenic.Primitive.RoundedRectangle)
12+
* [Scene Ref](Scenic.Primitive.SceneRef)
13+
* [Sector](Scenic.Primitive.Sector)
14+
* [Text](Scenic.Primitive.Text)
15+
* [Triangle](Scenic.Primitive.Triangle)

guides/scene_structure.md renamed to guides/overview_scene.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Structure of a Scene
22

3-
A `Scenic.Scene` is a `GenServer` process. They create the Graphs that get drawn
4-
to the screen and respond to user input and other events.
3+
A `Scenic.Scene` is a `GenServer` process which creates and manages a [Graph](overview_graph.html) that gets drawn to the screen. Scenes also respondss to user input and other events.
54

65
Scenes can reference each other, creating a logical hierarchy that lives above
76
the Graphs themselves. This allows scenes to be reusable, small, and simple. A

guides/welcome.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If you are new to Scenic, then you should read the following list in order.
1414

1515
* [General Overview](overview_general.html)
1616
* [Getting Started](getting_started.html)
17-
* [Structure of a Scene](scene_structure.html)
17+
* [Structure of a Scene](overview_scene.html)
1818
* [Contributing](contributing.html)
1919
* [Code of Conduct](code_of_conduct.html)
2020

lib/mix/tasks/hash.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule Mix.Tasks.Scenic.Hash do
3535
>> guides/overview_general.md -> "UNcd84guRIEBK5a0tWdp5MYmJpI"
3636
>> guides/overview_driver.md -> "zsTJ_xDQGrXLBtQk80hSUt-wZYE"
3737
>> guides/scene_lifecycle.md -> "jNcP7dPNXon0zEMtyCqL2z-A7FY"
38-
>> guides/scene_structure.md -> "apxgZRkCBHZeNNzCMpxgQRytHLA"
38+
>> guides/overview_scene.md -> "apxgZRkCBHZeNNzCMpxgQRytHLA"
3939
>> guides/getting_started.md -> "v1So-K14iPs_mGQZqr237TPah8I"
4040
>> guides/overview_viewport.md -> "3TpXIFxcwG54N2bb0O-86aznSS4"
4141
>> guides/mix_tasks.md -> "CWp9l8tDfHf5czjJqpbKtPqaqlc"

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ defmodule Scenic.Mixfile do
110110
"guides/overview_general.md",
111111
"guides/getting_started.md",
112112
"guides/getting_started_nerves.md",
113-
"guides/scene_structure.md",
113+
"guides/overview_scene.md",
114114
"guides/scene_lifecycle.md",
115115
"guides/overview_graph.md",
116116
"guides/overview_viewport.md",

0 commit comments

Comments
 (0)