1 /// 2 module fluid.onion_frame; 3 4 import fluid.frame; 5 import fluid.utils; 6 import fluid.style; 7 import fluid.backend; 8 9 10 @safe: 11 12 13 /// An onion frame places its children as layers, drawing one on top of the other, instead of on the side. 14 /// 15 /// Children are placed in order of drawing — the last child will be drawn last, and so, will appear on top. 16 alias onionFrame = simpleConstructor!OnionFrame; 17 18 /// ditto 19 class OnionFrame : Frame { 20 21 this(T...)(T args) { 22 23 super(args); 24 25 } 26 27 protected override void resizeImpl(Vector2 available) { 28 29 import std.algorithm : max; 30 31 use(canvasIO); 32 33 minSize = Vector2(0, 0); 34 35 // Check each child 36 foreach (child; children) { 37 38 // Resize the child 39 resizeChild(child, available); 40 41 // Update minSize 42 minSize.x = max(minSize.x, child.minSize.x); 43 minSize.y = max(minSize.y, child.minSize.y); 44 45 } 46 47 } 48 49 protected override void drawImpl(Rectangle outer, Rectangle inner) { 50 51 const style = pickStyle(); 52 style.drawBackground(tree.io, canvasIO, outer); 53 54 foreach (child; filterChildren) { 55 56 drawChild(child, inner); 57 58 } 59 60 } 61 62 } 63 64 /// 65 unittest { 66 67 import fluid; 68 69 auto myFrame = onionFrame( 70 71 // Draw an image 72 imageView("logo.png"), 73 74 // Draw a label in the middle of the frame 75 label( 76 layout!(1, "center"), 77 "Hello, Fluid!" 78 ), 79 80 ); 81 82 }