1 module rpui.alignment; 2 3 import std.math; 4 5 enum RegionAlign { 6 none, 7 left, 8 right, 9 top, 10 bottom, 11 client, 12 } 13 14 enum Align { 15 none, 16 left, 17 center, 18 right, 19 } 20 21 enum VerticalAlign { 22 none, 23 top, 24 middle, 25 bottom, 26 } 27 28 RegionAlign oppositeRegionAlign(in RegionAlign regionAlign) { 29 switch (regionAlign) { 30 case RegionAlign.top: 31 return RegionAlign.bottom; 32 33 case RegionAlign.bottom: 34 return RegionAlign.top; 35 36 case RegionAlign.left: 37 return RegionAlign.right; 38 39 case RegionAlign.right: 40 return RegionAlign.left; 41 42 default: 43 return regionAlign; 44 } 45 } 46 47 float alignBox(in Align align_, in float width, in float containerWidth) { 48 switch (align_) { 49 case Align.center: 50 return round((containerWidth - width) * 0.5); 51 52 case Align.right: 53 return containerWidth - width; 54 55 default: 56 return 0; 57 } 58 } 59 60 float verticalAlignBox(in VerticalAlign verticalAlign, in float height, in float containerHeight) { 61 switch (verticalAlign) { 62 case VerticalAlign.bottom: 63 return containerHeight - height; 64 65 case VerticalAlign.middle: 66 return round((containerHeight - height) * 0.5); 67 68 default: 69 return 0; 70 } 71 }