1 module w95.icon_button; 2 3 import fluid; 4 import raylib; 5 6 import w95.theme; 7 8 @safe: 9 10 alias iconButton = simpleConstructor!IconButton; 11 12 /// Button that optionally displays an icon to its left. 13 class IconButton : FrameButton { 14 15 public { 16 17 NodeSlot!ImageView icon; 18 NodeSlot!Label label; 19 20 } 21 22 this(ImageView icon, string text, void delegate() @safe callback) { 23 24 this( 25 icon, 26 .label(.layout!"center", text), 27 callback 28 ); 29 30 } 31 32 this(ImageView icon, Label text, void delegate() @safe callback) { 33 34 super( 35 this.icon = nodeSlot!ImageView( 36 .layout!"center", 37 icon 38 ), 39 this.label = nodeSlot!Label( 40 .layout!(1, "center"), 41 text 42 ), 43 callback 44 ); 45 this.isHorizontal = true; 46 47 } 48 49 protected override void drawImpl(Rectangle outer, Rectangle inner) { 50 51 const isHovered = tree.hover is this; 52 53 super.drawImpl(outer, inner); 54 55 // Ensure no child takes hover away from the button 56 if (isHovered) { 57 58 tree.hover = this; 59 60 } 61 62 } 63 64 }