ffgl_core/handler/
simplified.rs1use super::FFGLHandler;
7
8use crate::parameters::{ParamInfo, SimpleParamInfo};
9
10use crate::{FFGLData, GLInput};
11
12use super::FFGLInstance;
13
14pub struct SimpleFFGLHandler<T: SimpleFFGLInstance> {
16 pub(crate) _marker: std::marker::PhantomData<T>,
17}
18
19pub trait SimpleFFGLInstance: FFGLInstance {
21 fn new(inst_data: &FFGLData) -> Self;
22
23 fn num_params() -> usize {
24 0
25 }
26 fn param_info(_index: usize) -> &'static dyn ParamInfo {
27 panic!("No params")
28 }
29
30 fn plugin_info() -> crate::info::PluginInfo;
31
32 fn get_param(&self, _index: usize) -> f32 {
33 panic!("No params")
34 }
35 fn set_param(&mut self, _index: usize, _value: f32) {
36 panic!("No params")
37 }
38
39 fn draw(&mut self, inst_data: &FFGLData, frame_data: GLInput);
41}
42
43impl<T: SimpleFFGLInstance> FFGLInstance for T {
44 fn get_param(&self, index: usize) -> f32 {
45 SimpleFFGLInstance::get_param(self, index)
46 }
47
48 fn set_param(&mut self, index: usize, value: f32) {
49 SimpleFFGLInstance::set_param(self, index, value)
50 }
51
52 fn draw(&mut self, inst_data: &FFGLData, frame_data: GLInput) {
53 SimpleFFGLInstance::draw(self, inst_data, frame_data)
54 }
55}
56
57impl<T: SimpleFFGLInstance> FFGLHandler for SimpleFFGLHandler<T> {
58 type Instance = T;
59 type NewInstanceError = std::convert::Infallible;
60
61 fn init() -> Self {
62 Self {
63 _marker: std::marker::PhantomData,
64 }
65 }
66
67 fn num_params(&self) -> usize {
68 T::num_params()
69 }
70
71 fn param_info(&'static self, index: usize) -> &'static dyn ParamInfo {
72 T::param_info(index)
73 }
74
75 fn plugin_info(&self) -> crate::info::PluginInfo {
76 T::plugin_info()
77 }
78
79 fn new_instance(&self, inst_data: &FFGLData) -> Result<Self::Instance, Self::NewInstanceError> {
80 Ok(T::new(inst_data))
81 }
82}