mix scenic.setup (scenic_new v0.11.0)

Does much of the work to set up Scenic in an existing project, such as Nerves.

The typical use of this task is to install Scenic into a Nerves project. This assumes that you have already installed Nerves.

You should read use the Nerves Installation Guide.

Create a new project

Then create a new Nerves project and set up Scenic within it

mix nerves.new hello_nerves
cd hello_nerves
mix scenic.setup

This also works to set up Scenic in a blank Elixir project

mix new hello_world
cd hello_world
mix scenic.setup

At this point, the main file structures are set up, but not completely hooked together.

Set up the Scenic dependency

Add the following lines the this list of deps in the project's mix.exs file. Notice that they are usable for all the Nerves targets. (Actually, the local driver doesn't work for bbb yet and is very slow and needs work on rpi4, but the point is that it works across host and the device target...)

{:scenic, "~> 0.11.0-beta.0"},
{:scenic_driver_local, "~> 0.11.0-beta.0"},

Make sure your application is configured to start

This should be in your mix.exs file. If using Nerves, it will start MyApplication.Application

def application do
  [
    mod: {MyApplication, []},
    extra_applications: [:logger, :scenic]
  ]
end

Add Scenic to your app's supervisor

Next, you need to add Scenic to your app's supervisor so that it starts scenic. Something like this should be in your MyApp or MyApp.Application module.

def start(_type, _args) do
  # start the application with the configured viewport
  viewport_config = Application.get_env(:<%= @app %>, :viewport)
  children = [
    {Scenic, [viewport_config]},
    <%= @mod %>.PubSub.Supervisor
  ]
  |> Supervisor.start_link( strategy: :one_for_one )
end

Configure your assets

Add the following to your config.exs file. Change the app name as appropriate. This configuration is usually the same for all targets.

config :scenic, :assets, module: MyApplication.Assets

Configure your ViewPort

Next, you need to configure your ViewPort. This instructs Scenic how to draw to the screen, or window. This is typically different for the various Nerves targets.

The following example would go in the host.exs file. Or, if this is just a regular elixir project running on a Mac/PC/Linux machine, it could go in config.exs

config :my_application, :viewport,
  size: {800, 600},
  theme: :dark,
  default_scene: MyApplication.Scene.Home,
  drivers: [
    [
      module: Scenic.Driver.Local,
      window: [title: "My Application"],
      on_close: :stop_system
    ]
  ]

This configuration could be for a Nerves device. In this case an rpi3, that I've been using, but it could be any device with a fixed screen.

config :my_application, :viewport,
  size: {800, 600},
  theme: :dark,
  default_scene: MyApplication.Scene.Home,
  drivers: [
    [
      module: Scenic.Driver.Local,
      position: [scaled: true, centered: true, orientation: :normal],
    ]
  ]

Scenic.Driver.Local has quite a few options you can set. Please see it's documentation for more.

Get the Dependencies and Run

You should now be ready to fetch the dependencies and run your project. Run these commands from within your project's main directory.

mix deps.get
iex -S mix

The Starter Application

The starter application created by the generator adds a minimal set of Scenic files displays information about the system it is running on.

Next, you should read guides describing the overall Scenic structure. This is in the documentation for Scenic itself

Link to this section Summary

Functions

Callback implementation for Mix.Task.run/1.

Link to this section Functions

Callback implementation for Mix.Task.run/1.