1 module evael.graphics.gui.controls.Tooltip; 2 3 import std.math : round; 4 5 import evael.graphics.gui.controls.Control; 6 import evael.graphics.gui.controls.TextBlock; 7 8 import evael.utils.Math; 9 10 import evael.utils.Size; 11 import evael.utils.Color; 12 13 /** 14 * Tooltip. 15 * Can't be a Container because Container have a tooltip member, so we handle textblock manually. 16 */ 17 class Tooltip : Control 18 { 19 /// Tooltip text 20 private TextBlock m_textBlock; 21 22 public this()(in auto ref vec2 position) 23 { 24 super(position, Size!int(0, 0)); 25 26 this.m_name = "tooltip"; 27 } 28 29 public this(in float x = 0, in float y = 0) 30 { 31 this(vec2(x, y)); 32 33 this.m_textBlock = new TextBlock(); 34 this.m_textBlock.dock = Control.Dock.Fill; 35 this.m_textBlock.color = Color.White; 36 } 37 38 public override void draw(in float deltaTime) 39 { 40 if (!this.m_isVisible || this.m_textBlock.text is null) 41 return; 42 43 this.m_textBlock.draw(deltaTime); 44 45 } 46 47 public override void initialize() 48 { 49 this.m_textBlock.nvg = this.m_nvg; 50 51 // Theme 52 if(this.m_name in this.m_theme.subThemes) 53 { 54 this.m_textBlock.theme = this.m_theme.subThemes[this.m_name]; 55 } 56 else 57 { 58 this.m_textBlock.theme = this.m_theme; 59 } 60 61 this.m_textBlock.initialize(); 62 63 super.initialize(); 64 } 65 66 @property 67 { 68 public wstring text() const 69 { 70 return this.m_textBlock.text; 71 } 72 73 public void text(in wstring text) 74 { 75 this.m_textBlock.text = text; 76 } 77 78 public override void realPosition(in vec2 value) 79 { 80 // We do this because we need to calculate viewport rect in Control class 81 super.realPosition = value; 82 83 this.m_textBlock.realPosition = this.m_realPosition + this.m_textBlock.position; 84 } 85 } 86 }