Rectangle_LumaButton.cpp
Go to the documentation of this file.
2 #include "LumaText.hpp"
3 
4 namespace iv
5 {
6 
7 Rectangle_LumaButton::Rectangle_LumaButton( iv::Instance * inst, ResourcePath const & icon, char const * label, LumaStyleId style_id ) :
8  LumaButton( inst, style_id ),
9  cm( inst, this, "Rectangle_LumaButton" ),
10  img_icon( nullptr ),
11  text( nullptr )
12 {
13  this->cm.inherits( this->LumaButton::cm );
14 
15  this->attr_surface.Set( ResourcePath( "/ivorium_UI/LumaButton/surface.png" ) );
16 
17  //-------------------------------------------
18  auto divider = this->surface_slot.createChild< iv::Align >()
19  ->dontExpand( true )
21  ->axis( Axis::X )
23 
24  // icon
25  if( !icon.empty() )
26  {
27  this->img_icon = divider->createChild< DividerSlot >()
28  ->lowerOrder( 0 )
29  ->createChild< iv::Align >()
30  ->keepAspect( true )
32  ->prefsizeX( 16 )
33  ->prefsizeY( 16 )
34  ->createChild< iv::Image >()
35  ->filename( icon );
36  }
37 
38  // label
39  std::string label_trimmed = iv::string_trim( std::string( label ) );
40  if( !label_trimmed.empty() )
41  {
42  if( !icon.empty() )
43  {
44  divider->createChild< DividerSlot >()
45  ->lowerOrder( 2 )
46  ->createChild< Prefsize >()
47  ->prefsizeX( 4 );
48  }
49 
50  this->text = divider->createChild< DividerSlot >()
51  ->lowerOrder( 1 )
52  ->createChild< iv::Border >()
53  ->createChild< iv::TextLayout >()
55  ->text( label_trimmed )
56  ->fontSize( 15 );
57  }
58 
59  //
60  this->CallColorsChanged();
61 }
62 
64 {
65  if( this->img_icon )
66  {
67  this->img_icon->preblend( surface );
68  this->img_icon->colorTransform( ColorTransform::Scale( on_surface ) );
69  }
70 
71  if( this->text )
72  {
73  this->text->preblend( surface );
74  this->text->color( on_surface );
75  }
76 }
77 
78 }