Prefsize.cpp
Go to the documentation of this file.
1 #include "Prefsize.hpp"
2 
3 namespace iv
4 {
5 
7  OneChildElem< SlotChild >( inst ),
8  SlotChild( this ),
9  cm( inst, this, "Prefsize" ),
10  attr_prefsizeX( &this->cm, std::nullopt ),
11  attr_prefsizeY( &this->cm, std::nullopt ),
12  attr_prefsizeZ( &this->cm, std::nullopt ),
13  attr_prefsizeScale( &this->cm, float3( 1, 1, 1 ) )
14 {
16 }
17 
19 {
20  if( this->child.Get() )
21  {
22  if( this->child.dirty() || this->expectedSize.dirty() )
23  {
24  this->expectedSize.clear_dirty();
25 
26  auto exp = this->expectedSize.Get();
27 
28  if( this->attr_prefsizeX.Get().has_value() )
29  exp.x = std::min( exp.x, this->attr_prefsizeX.Get().value() );
30 
31  if( this->attr_prefsizeY.Get().has_value() )
32  exp.y = std::min( exp.y, this->attr_prefsizeY.Get().value() );
33 
34  if( this->attr_prefsizeZ.Get().has_value() )
35  exp.z = std::min( exp.z, this->attr_prefsizeZ.Get().value() );
36 
37  this->child.Get()->expectedSize.Set( exp );
38  }
39 
40  this->child.Get()->elem()->first_pass( er );
41  }
42 
43  if( this->attr_prefsizeX.clear_dirty() + this->attr_prefsizeY.clear_dirty() + this->attr_prefsizeZ.clear_dirty() + this->attr_prefsizeScale.clear_dirty() + this->child.dirty() + ( this->child.Get() && this->child.Get()->preferredSize.dirty() ) )
44  {
45  //
46  float3 prefsize( 0, 0, 0 );
47 
48  // set child to prefsize
49  if( this->child.Get() )
50  {
52  prefsize = this->child.Get()->preferredSize.Get();
53  }
54 
55  // override with initialization parameters
56  if( this->attr_prefsizeX.Get().has_value() )
57  prefsize.x = this->attr_prefsizeX.Get().value();
58 
59  if( this->attr_prefsizeY.Get().has_value() )
60  prefsize.y = this->attr_prefsizeY.Get().value();
61 
62  if( this->attr_prefsizeZ.Get().has_value() )
63  prefsize.z = this->attr_prefsizeZ.Get().value();
64 
65  // set synthesized parameter
66  this->preferredSize.Set( prefsize * this->attr_prefsizeScale.Get() );
67  }
68 
69  if( this->child.Get() )
70  if( this->child.dirty() || this->modelTransform.dirty() || this->scissor.dirty() )
71  er->QueueSecondPass( this );
72 }
73 
75 {
76  //
77  if( !this->child.Get() )
78  return;
79 
80  //
81  if( this->child.dirty() || this->size.dirty() || this->modelTransform.dirty() || this->scissor.dirty() )
82  {
83  this->child.clear_dirty();
84  this->size.clear_dirty();
86  this->scissor.clear_dirty();
87 
88  this->child.Get()->elem()->modelTransform.Set( this->modelTransform.Get() );
89  this->child.Get()->elem()->scissor.Set( this->scissor.Get() );
90  this->child.Get()->size.Set( this->size.Get() );
91  this->child.Get()->elem()->second_pass( er );
92  }
93 }
94 
96 {
97  this->Elem::enabled( val );
98  return this;
99 }
100 
102 {
103  this->attr_prefsizeScale.Set( val );
104  return this;
105 }
106 
108 {
109  this->attr_prefsizeX.Set( val.x );
110  this->attr_prefsizeY.Set( val.y );
111  this->attr_prefsizeZ.Set( val.z );
112  return this;
113 }
114 
115 Prefsize * Prefsize::prefsizeX( std::optional< float > val )
116 {
117  this->attr_prefsizeX.Set( val );
118  return this;
119 }
120 
121 Prefsize * Prefsize::prefsizeY( std::optional< float > val )
122 {
123  this->attr_prefsizeY.Set( val );
124  return this;
125 }
126 
127 Prefsize * Prefsize::prefsizeZ( std::optional< float > val )
128 {
129  this->attr_prefsizeZ.Set( val );
130  return this;
131 }
132 
133 }