gooey/presentation/
mod.rs1use crate::{Application, Interface, Tree};
18use crate::tree::NodeId;
19use crate::interface::{view, Element, View};
20
21pub mod headless;
22pub use headless::Headless;
23
24#[cfg(feature="curses")]
27#[cfg_attr(docsrs, doc(cfg(feature="curses")))]
28pub mod curses;
29#[cfg(feature="curses")]
30#[cfg_attr(docsrs, doc(cfg(feature="curses")))]
31pub use self::curses::Curses;
32#[cfg(feature="opengl")]
33#[cfg_attr(docsrs, doc(cfg(feature="opengl")))]
34pub mod opengl;
35#[cfg(feature="opengl")]
36#[cfg_attr(docsrs, doc(cfg(feature="opengl")))]
37pub use self::opengl::Opengl;
38#[cfg(feature="fmod")]
40#[cfg_attr(docsrs, doc(cfg(feature="fmod")))]
41pub mod fmod;
42#[cfg(feature="fmod")]
43#[cfg_attr(docsrs, doc(cfg(feature="fmod")))]
44pub use self::fmod::Fmod;
45
46pub trait Presentation {
48 fn with_root (root : View, id : NodeId) -> Self;
49 fn make_interface <A : Application> () -> Interface <A, Self>
53 where Self : Sized
54 {
55 Interface::with_root (Element::default())
56 }
57 fn get_input (&mut self, input_buffer : &mut Vec <view::Input>);
58 fn display_view <V : AsRef <View>> (&mut self,
59 view_tree : &Tree <V>,
60 display_values : std::vec::Drain <(NodeId, view::Display)>);
61}
62
63pub trait Graphics : Presentation { }
65pub trait Audio : Presentation { }
67pub trait HasGraphics <G : Graphics> {
69 fn graphics (&mut self) -> &mut G;
70}
71#[derive(Debug)]
74pub struct Composite <G : Graphics, A : Audio> {
75 pub graphics : G,
76 pub audio : A,
77 display_buffers : (
78 Vec <(NodeId, view::Display)>, Vec <(NodeId, view::Display)> )
79}
80impl <G, A> Presentation for Composite <G, A> where
81 G : Graphics,
82 A : Audio
83{
84 fn with_root (root : View, id : NodeId) -> Self {
85 let graphics = G::with_root (root.clone(), id.clone());
86 let audio = A::with_root (root, id);
87 let display_buffers = (vec![], vec![]);
88 Composite { graphics, audio, display_buffers }
89 }
90 fn make_interface <APP : Application> () -> Interface <APP, Self>
92 where Self : Sized
93 {
94 let graphical = G::make_interface();
95 let root = graphical.root_node().data().view.clone();
96 let root_id = graphical.root_id().clone();
97 graphical.swap_presentation (|graphics| {
98 let audio = A::with_root (root, root_id);
99 let display_buffers = (vec![], vec![]);
100 Composite { graphics, audio, display_buffers }
101 })
102 }
103 fn get_input (&mut self, input_buffer : &mut Vec <view::Input>) {
104 self.graphics.get_input (input_buffer);
105 self.audio.get_input (input_buffer);
106 }
107 fn display_view <V : AsRef <View>> (&mut self,
108 view_tree : &Tree <V>,
109 display_values : std::vec::Drain <(NodeId, view::Display)>
110 ) {
111 self.display_buffers.0 = display_values.collect();
112 self.display_buffers.1 = self.display_buffers.0.clone();
113 self.graphics.display_view (view_tree, self.display_buffers.0.drain(..));
114 self.audio.display_view (view_tree, self.display_buffers.1.drain(..));
115 }
116}
117
118impl <G, A> HasGraphics <G> for Composite <G, A> where
119 G : Graphics,
120 A : Audio
121{
122 fn graphics (&mut self) -> &mut G {
123 &mut self.graphics
124 }
125}
126
127impl <G : Graphics> HasGraphics <G> for G {
128 fn graphics (&mut self) -> &mut G {
129 self
130 }
131}