Skip to content

Commit

Permalink
Get live reload to work
Browse files Browse the repository at this point in the history
  • Loading branch information
Ju Liu committed Mar 5, 2019
1 parent e259ba4 commit f6ecdb4
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 11 deletions.
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ config :scenic_escher, :viewport, %{
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "prod.exs"

import_config "#{Mix.env()}.exs"
5 changes: 5 additions & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use Mix.Config

config :exsync,
reload_timeout: 75,
reload_callback: {GenServer, :call, [ScenicEscher.Refresher, :refresh_home]}
1 change: 1 addition & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use Mix.Config
2 changes: 1 addition & 1 deletion lib/fitting.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Fitting do
end

def get_stroke_width(%Box{b: b, c: c}) do
max(Vector.length(b), Vector.length(c)) / 150.0
max(Vector.length(b), Vector.length(c)) / 100.0
end

def create_picture(shapes, options \\ []) do
Expand Down
14 changes: 7 additions & 7 deletions lib/scenes/home.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ defmodule ScenicEscher.Scene.Home do

import Scenic.Primitives

@note """
Hello World!
"""

@graph Graph.build(font: :roboto, font_size: 24, theme: :light)
|> group(
fn g ->
Expand All @@ -20,7 +16,11 @@ defmodule ScenicEscher.Scene.Home do

{width, height} = Box.dimensions(box)

george = Fitting.create_picture(Figure.george())
george =
Fitting.create_picture(
Figure.george(),
debug: true
)

atom =
Picture.above(
Expand Down Expand Up @@ -54,10 +54,9 @@ defmodule ScenicEscher.Scene.Home do
box
|> picture.()
|> Rendering.to_paths({width, height})
|> IO.inspect()

initial = g
# |> text(@note, fill: :black, translate: {20, 40})
# |> text("Hello!", fill: :black, translate: {20, 40})

paths
|> Enum.reduce(initial, fn {elem, options}, acc ->
Expand All @@ -69,6 +68,7 @@ defmodule ScenicEscher.Scene.Home do
)

def init(_, _) do
Process.register(self(), __MODULE__)
push_graph(@graph)
{:ok, @graph}
end
Expand Down
1 change: 1 addition & 0 deletions lib/scenic_escher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule ScenicEscher do

# start the application with the viewport
children = [
ScenicEscher.Refresher,
{Scenic, viewports: [main_viewport_config]}
]

Expand Down
30 changes: 30 additions & 0 deletions lib/scenic_escher/refresher.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule ScenicEscher.Refresher do
use GenServer

def start_link(_) do
GenServer.start_link(__MODULE__, :hello)
end

def init(_) do
Process.register(self(), __MODULE__)
{:ok, :started}
end

def handle_call(:refresh_home, _, state) do
send(self(), :refresh_home)
Process.send_after(self(), :refresh_home, 100)
{:reply, :ok, state}
end

def handle_info(:refresh_home, state) do
case Process.whereis(ScenicEscher.Scene.Home) do
nil ->
:no_op

pid ->
Process.exit(pid, :kill)
end

{:noreply, state}
end
end
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ defmodule ScenicEscher.MixProject do
defp deps do
[
{:scenic, "~> 0.9"},
{:scenic_driver_glfw, "~> 0.9", targets: :host}
{:scenic_driver_glfw, "~> 0.9", targets: :host},
{:exsync, git: "https://github.com/Arkham/exsync", branch: "support-escher", only: :dev}
]
end
end
2 changes: 2 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
%{
"elixir_make": {:hex, :elixir_make, "0.5.2", "96a28c79f5b8d34879cd95ebc04d2a0d678cfbbd3e74c43cb63a76adf0ee8054", [:mix], [], "hexpm"},
"exsync": {:git, "https://github.com/Arkham/exsync", "7d35547a27ada1c0a8bcf679cb9a1ccf42db9c36", [branch: "support-escher"]},
"file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
"scenic": {:hex, :scenic, "0.9.0", "129594f918b4e2dd97465b95b4fb3582294ac6bb3e931f12edd09913743964eb", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
"scenic_driver_glfw": {:hex, :scenic_driver_glfw, "0.9.1", "b64d345929007186c6b2ca603aec21b1fdde758d3eb32f8467a236e58ccd6a19", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:scenic, "~> 0.9", [hex: :scenic, repo: "hexpm", optional: false]}], "hexpm"},
}

0 comments on commit f6ecdb4

Please sign in to comment.