wplot/sys/
context_changer.rs

1/// Internal namespace.
2pub( crate ) mod private
3{
4  use crate::protected::*;
5
6  /// Context.
7  #[ allow( dead_code ) ]
8  #[ derive( Clone ) ]
9  pub struct ContextChanger
10  {
11    /// Id.
12    pub( crate ) id : Id,
13    /// Stroke brush.
14    pub( crate ) stroke : Option< Id >,
15    /// Drawing.
16    pub( crate ) drawing : Option< Id >,
17    /// Queue of changes.
18    pub changes : Vec< Box< dyn ChangeInterface > >,
19  }
20
21  impl ContextChanger
22  {
23    /// Parameters of stroke.
24    #[ inline ]
25    pub fn stroke( self ) -> StrokeBrushChanger
26    {
27      let changer = StrokeBrushChanger::_new( self );
28      changer
29    }
30    /// Draw.
31    #[ inline ]
32    pub fn draw( self ) -> DrawChanger
33    {
34      let changer = DrawChanger::_new( self );
35      changer
36    }
37  }
38
39  impl fmt::Debug for ContextChanger
40  {
41    fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result
42    {
43      f.write_str( "ContextChanger" )?;
44      for ( _i, e ) in self.changes.iter().enumerate()
45      {
46        f.write_str( &wtools::string::indentation( "  ", format!( "\n{:?}", e ), "" ) )?;
47      }
48      Ok( () )
49    }
50  }
51
52  impl ChangerInterface for ContextChanger
53  {
54    type Parent = ContextChanger;
55    type Root = ContextChanger;
56
57    #[ inline ]
58    fn root( &mut self ) -> &mut Self::Root
59    {
60      self
61    }
62
63    #[ inline ]
64    fn context( self ) -> Self::Root
65    {
66      self
67    }
68
69    #[ inline ]
70    fn parent( &mut self ) -> &mut Self::Parent
71    {
72      self
73    }
74
75    #[ inline ]
76    fn end( self ) -> Self::Parent
77    {
78      self
79    }
80
81    #[ inline ]
82    fn change_add< Change >( &mut self, change : Change ) -> &mut Self
83    where
84      Change : ChangeInterface + 'static,
85    {
86      self.changes.push( Box::new( change ) );
87      self
88    }
89
90  }
91
92  impl HasIdInterface for ContextChanger
93  {
94    #[ inline ]
95    fn id( &self ) -> Id
96    {
97      self.id
98    }
99  }
100
101}
102
103crate::mod_interface!
104{
105  exposed use ContextChanger;
106}