-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmultiple_views.exs
60 lines (52 loc) · 1.33 KB
/
multiple_views.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# An example of how to implement navigation between multiple views.
#
# Run this example with:
#
# mix run examples/multiple_views.exs
defmodule MultipleViewsDemo do
@behaviour Ratatouille.App
import Ratatouille.View
def init(_context) do
%{selected_tab: 1}
end
def update(model, message) do
case message do
{:event, %{ch: ?1}} -> %{model | selected_tab: 1}
{:event, %{ch: ?2}} -> %{model | selected_tab: 2}
{:event, %{ch: ?3}} -> %{model | selected_tab: 3}
_ -> model
end
end
def render(model) do
view top_bar: title_bar(), bottom_bar: status_bar(model.selected_tab) do
case model.selected_tab do
1 -> panel(title: "View 1", height: :fill)
2 -> panel(title: "View 2", height: :fill)
3 -> panel(title: "View 3", height: :fill)
end
end
end
def title_bar do
bar do
label(content: "Multiple Views Demo (Press 1, 2 or 3, or q to quit)")
end
end
def status_bar(selected) do
bar do
label do
for item <- 1..3 do
if item == selected do
text(
background: :white,
color: :black,
content: " View #{item} "
)
else
text(content: " View #{item} ")
end
end
end
end
end
end
Ratatouille.run(MultipleViewsDemo)