Skip to content

Commit a356cea

Browse files
authored
Merge pull request #271 from axelson/dynamic-viewport
Dynamic viewport example
2 parents 94679b1 + 8c4997a commit a356cea

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/scenic/driver.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,11 @@ defmodule Scenic.Driver do
887887
name: [type: :atom]
888888
]
889889

890-
@doc false
890+
@doc """
891+
Validate driver configuration
892+
893+
Used primarily for dynamic view port creation
894+
"""
891895
def validate([]), do: {:ok, []}
892896

893897
def validate(drivers) do

lib/scenic/view_port.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ defmodule Scenic.ViewPort do
9191
leave the scene that thinks it has "captured" the input in an inconsistent
9292
state, so this is not recommended.
9393
94+
## Dynamically Creating View Ports
95+
96+
Pass in the same set of opts that you would use when starting `Scenic` in your
97+
supervision tree. For example:
98+
99+
# Assuming you use the default view port name from the generator
100+
{:ok, view_port} = Scenic.ViewPort.info(:main_viewport)
101+
102+
opts = [
103+
module: Scenic.Driver.Local,
104+
window: [resizeable: false, title: "My Example Scenic App"],
105+
on_close: :stop_system
106+
]
107+
108+
{:ok, [opts]} = Scenic.Driver.validate([opts])
109+
Scenic.ViewPort.start_driver(view_port, opts)
94110
"""
95111

96112
@type t :: %ViewPort{

0 commit comments

Comments
 (0)