flowcontainer.py (6825B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\primitives\flowcontainer.py 2 from carbonui import uiconst 3 from carbonui.primitives.base import Base 4 from carbonui.primitives.container import Container 5 from carbonui.uiconst import AxisAlignment 6 from carbonui.uicore import uicore 7 import uthread 8 import uthread2 9 import blue 10 ALLOWED_AUTO_HEIGHT_ALIGNMENTS = (uiconst.BOTTOMLEFT, 11 uiconst.BOTTOMRIGHT, 12 uiconst.CENTER, 13 uiconst.CENTERBOTTOM, 14 uiconst.CENTERLEFT, 15 uiconst.CENTERRIGHT, 16 uiconst.CENTERTOP, 17 uiconst.TOBOTTOM, 18 uiconst.TOBOTTOM_NOPUSH, 19 uiconst.TOPLEFT, 20 uiconst.TOPRIGHT, 21 uiconst.TOTOP, 22 uiconst.TOTOP_NOPUSH) 23 24 class FlowContainer(Container): 25 default_name = 'flowContainer' 26 27 def __init__(self, contentSpacing = (0, 0), centerContent = False, contentAlignment = AxisAlignment.START, crossAxisAlignment = AxisAlignment.START, autoHeight = True, **kwargs): 28 self.contentSpacing = contentSpacing 29 if centerContent: 30 self._contentAlignment = AxisAlignment.CENTER 31 else: 32 self._contentAlignment = contentAlignment 33 self._crossAxisAlignment = crossAxisAlignment 34 self._autoHeight = autoHeight 35 super(FlowContainer, self).__init__(**kwargs) 36 37 @property 38 def contentAlignment(self): 39 return self._contentAlignment 40 41 @contentAlignment.setter 42 def contentAlignment(self, value): 43 if self._contentAlignment != value: 44 self._contentAlignment = value 45 self._ForceAlignmentDirty() 46 47 @property 48 def crossAxisAlignment(self): 49 return self._crossAxisAlignment 50 51 @crossAxisAlignment.setter 52 def crossAxisAlignment(self, value): 53 if self._crossAxisAlignment != value: 54 self._crossAxisAlignment = value 55 self._ForceAlignmentDirty() 56 57 @property 58 def autoHeight(self): 59 return self._autoHeight 60 61 @autoHeight.setter 62 def autoHeight(self, value): 63 if self._autoHeight != value: 64 self._autoHeight = value 65 self._ForceAlignmentDirty() 66 67 def _ForceAlignmentDirty(self): 68 self.FlagAlignmentDirty() 69 self._childrenAlignmentDirty = True 70 71 def UpdateAlignment(self, budgetLeft = 0, budgetTop = 0, budgetWidth = 0, budgetHeight = 0, updateChildrenOnly = False): 72 if self.destroyed: 73 return (budgetLeft, 74 budgetTop, 75 budgetWidth, 76 budgetHeight, 77 False) 78 forceUpdate = self._forceUpdateAlignment 79 if updateChildrenOnly: 80 childrenDirty = True 81 sizeChange = False 82 retBudgetLeft, retBudgetTop, retBudgetWidth, retBudgetHeight = (budgetLeft, 83 budgetTop, 84 budgetWidth, 85 budgetHeight) 86 else: 87 retBudgetLeft, retBudgetTop, retBudgetWidth, retBudgetHeight, sizeChange = Base.UpdateAlignment(self, budgetLeft, budgetTop, budgetWidth, budgetHeight) 88 childrenDirty = self._childrenAlignmentDirty 89 self._childrenAlignmentDirty = False 90 if childrenDirty or forceUpdate or sizeChange: 91 92 def AdjustRow(rowObjects, width, height, rowY): 93 if self.contentAlignment == AxisAlignment.CENTER: 94 xOffset = (self.displayWidth - width) / 2 95 elif self.contentAlignment == AxisAlignment.END: 96 xOffset = self.displayWidth - width 97 else: 98 xOffset = 0 99 for item in rowObjects: 100 yOffset = 0 101 if self.crossAxisAlignment != AxisAlignment.START and item.displayHeight != height: 102 if self.crossAxisAlignment == AxisAlignment.CENTER: 103 yOffset = (height - item.displayHeight) / 2 104 elif self.crossAxisAlignment == AxisAlignment.END: 105 yOffset = height - item.displayHeight 106 item.displayY = rowY + yOffset 107 item.displayX += xOffset 108 109 x = 0 110 y = 0 111 rowItems = [] 112 rowHeight = 0 113 rowWidth = 0 114 spacingX = uicore.ScaleDpi(self.contentSpacing[0]) 115 spacingY = uicore.ScaleDpi(self.contentSpacing[1]) 116 for each in self.children: 117 if each.align != uiconst.NOALIGN: 118 continue 119 if each.display: 120 scaledWidth = uicore.ScaleDpi(each.width) 121 scaledHeight = uicore.ScaleDpi(each.height) 122 if scaledWidth != each.displayWidth or scaledHeight != each.displayHeight or forceUpdate: 123 if forceUpdate: 124 each._forceUpdateAlignment = True 125 each._alignmentDirty = True 126 each.UpdateAlignment() 127 if x + scaledWidth > self.displayWidth: 128 AdjustRow(rowItems, rowWidth - spacingX, rowHeight, y) 129 x = 0 130 y += rowHeight + spacingY 131 rowWidth = 0 132 rowHeight = 0 133 rowItems = [] 134 rowItems.append(each) 135 rowHeight = max(rowHeight, scaledHeight) 136 rowWidth += scaledWidth + spacingX 137 each.displayX = x 138 x += scaledWidth + spacingX 139 140 AdjustRow(rowItems, rowWidth - spacingX, rowHeight, y) 141 if self.autoHeight and self.align in ALLOWED_AUTO_HEIGHT_ALIGNMENTS: 142 newHeight = uicore.ReverseScaleDpi(y + rowHeight) 143 if newHeight != self.height: 144 self.height = newHeight 145 retBudgetLeft, retBudgetTop, retBudgetWidth, retBudgetHeight, sizeChange = Base.UpdateAlignment(self, budgetLeft, budgetTop, budgetWidth, budgetHeight) 146 return (retBudgetLeft, 147 retBudgetTop, 148 retBudgetWidth, 149 retBudgetHeight, 150 sizeChange) 151 152 def UnifyContentSize(self): 153 maxWidth = 0 154 maxHeight = 0 155 for each in self.children: 156 maxWidth = max(maxWidth, each.width) 157 maxHeight = max(maxHeight, each.height) 158 159 for each in self.children: 160 each.width = maxWidth 161 each.height = maxHeight 162 163 def _AppendChildRO(self, child): 164 child.align = uiconst.NOALIGN 165 Container._AppendChildRO(self, child) 166 167 def _InsertChildRO(self, idx, child): 168 child.align = uiconst.NOALIGN 169 Container._InsertChildRO(self, idx, child) 170 171 def _RemoveChildRO(self, child): 172 Container._RemoveChildRO(self, child) 173 if not self.destroyed: 174 self._childrenAlignmentDirty = True 175 self.FlagAlignmentDirty()