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 minSize = Vector2(0, 0); 32 33 // Check each child 34 foreach (child; children) { 35 36 // Resize the child 37 child.resize(tree, theme, available); 38 39 // Update minSize 40 minSize.x = max(minSize.x, child.minSize.x); 41 minSize.y = max(minSize.y, child.minSize.y); 42 43 } 44 45 } 46 47 protected override void drawImpl(Rectangle outer, Rectangle inner) { 48 49 const style = pickStyle(); 50 style.drawBackground(tree.io, outer); 51 52 foreach (child; filterChildren) { 53 54 child.draw(inner); 55 56 } 57 58 } 59 60 } 61 62 /// 63 unittest { 64 65 import fluid; 66 67 auto myFrame = onionFrame( 68 69 // Draw an image 70 imageView("logo.png"), 71 72 // Draw a label in the middle of the frame 73 label( 74 layout!(1, "center"), 75 "Hello, Fluid!" 76 ), 77 78 ); 79 80 } 81 82 unittest { 83 84 import fluid.label; 85 import fluid.structs; 86 import fluid.image_view; 87 88 ImageView view; 89 Label[2] labels; 90 91 auto io = new HeadlessBackend(Vector2(1000, 1000)); 92 auto root = onionFrame( 93 94 view = imageView("logo.png"), 95 96 labels[0] = label( 97 "Hello, Fluid!" 98 ), 99 100 labels[1] = label( 101 layout!(1, "center"), 102 "Hello, Fluid! This text should fit the image." 103 ), 104 105 ); 106 107 with (Rule) 108 root.theme = nullTheme.derive( 109 rule!Label(textColor = color!"000"), 110 ); 111 root.io = io; 112 root.draw(); 113 114 // imageView 115 io.assertTexture(view.texture, Vector2(0, 0), color!"fff"); 116 117 // First label 118 io.assertTexture(labels[0].text.texture.chunks[0], Vector2(0, 0), color("#fff")); 119 120 // TODO onionFrame should perform shrink-expand ordering similarly to `space`. The last label should wrap. 121 122 }