-
Notifications
You must be signed in to change notification settings - Fork 55
/
scenic.exs
76 lines (60 loc) · 1.75 KB
/
scenic.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Based on scenic_new
# See: https://github.com/boydm/scenic_new#install-prerequisites
Mix.install([
{:scenic, "~> 0.10"},
{:scenic_driver_glfw, "~> 0.10", targets: :host}
])
defmodule Main do
def main do
main_viewport_config = %{
name: :main_viewport,
size: {700, 600},
default_scene: {Example.Scene.Home, nil},
drivers: [
%{
module: Scenic.Driver.Glfw,
name: :glfw,
opts: [resizeable: false, title: "example"]
}
]
}
children = [
{Scenic, viewports: [main_viewport_config]}
]
{:ok, _} = Supervisor.start_link(children, strategy: :one_for_one)
# unless running from IEx, sleep idenfinitely so the GUI keeps running
unless IEx.started?() do
Process.sleep(:infinity)
end
end
end
defmodule Example.Scene.Home do
use Scenic.Scene
require Logger
alias Scenic.Graph
alias Scenic.ViewPort
import Scenic.Primitives
@note """
This is a very simple starter application.
"""
@text_size 24
def init(_, opts) do
{:ok, %ViewPort.Status{size: {width, height}}} = ViewPort.info(opts[:viewport])
scenic_ver = Application.spec(:scenic, :vsn) |> to_string()
glfw_ver = Application.spec(:scenic_driver_glfw, :vsn) |> to_string()
graph =
Graph.build(font: :roboto, font_size: @text_size)
|> add_specs_to_graph([
text_spec("scenic: v" <> scenic_ver, translate: {20, 40}),
text_spec("glfw: v" <> glfw_ver, translate: {20, 40 + @text_size}),
text_spec(@note, translate: {20, 120}),
rect_spec({width, height})
])
{:ok, graph, push: graph}
end
def handle_input(event, _context, state) do
Logger.info("Received event: #{inspect(event)}")
{:noreply, state}
end
end
Main.main()