MCPcopy Index your code
hub / github.com/pyfa-org/Pyfa / AdjustTabsSize

Method AdjustTabsSize

gui/chrome_tabs.py:1298–1371  ·  view source on GitHub ↗

Adjust tab sizes to ensure that they are all consistent and can fit into the tab container.

(self)

Source from the content-addressed store, hash-verified

1296 return len(self.tabs)
1297
1298 def AdjustTabsSize(self):
1299 """
1300 Adjust tab sizes to ensure that they are all consistent and can fit into
1301 the tab container.
1302 """
1303 if self.tabWidthMode == 1:
1304 if self.GetTabsCount() > 0:
1305 availableW = self.tab_container_width
1306 overlapSavedW = max(0, len(self.tabs)) * self.inclination * 2
1307 tabsGrouped = {}
1308 for tab in self.tabs:
1309 tabW, _ = tab.GetMinSize()
1310 tabsGrouped.setdefault(math.ceil(tabW), []).append(tab)
1311 clippedTabs = []
1312 clipW = max(tabsGrouped, default=0)
1313
1314 def getUnclippedW():
1315 unclippedW = 0
1316 for w, tabs in tabsGrouped.items():
1317 unclippedW += w * len(tabs)
1318 return unclippedW
1319 while tabsGrouped:
1320 # Check if we're within width limit
1321 neededW = 0
1322 for w, tabs in tabsGrouped.items():
1323 neededW += w * len(tabs)
1324 if clippedTabs:
1325 neededW += clipW * len(clippedTabs)
1326 if neededW <= availableW + overlapSavedW:
1327 break
1328 # If we're not, extract widest tab group and mark it for clipping
1329 currentTabs = tabsGrouped.pop(max(tabsGrouped))
1330 clippedTabs.extend(currentTabs)
1331 proposedClipWidth = math.floor((availableW + overlapSavedW - getUnclippedW()) / len(clippedTabs))
1332 if not tabsGrouped or proposedClipWidth >= max(tabsGrouped, default=0):
1333 clipW = max(0, proposedClipWidth)
1334 break
1335 else:
1336 clipW = max(tabsGrouped)
1337 # Assign width for unclipped tabs
1338 for w, tabs in tabsGrouped.items():
1339 for tab in tabs:
1340 tab.SetSize((w, self.height))
1341 if clippedTabs:
1342 # Some width remains to be used due to rounding to integer
1343 extraWTotal = availableW + overlapSavedW - getUnclippedW() - clipW * len(clippedTabs)
1344 extraWPerTab = math.ceil(extraWTotal / len(clippedTabs))
1345 # Assign width for clipped tabs
1346 for tab in clippedTabs:
1347 extraW = min(extraWTotal, extraWPerTab)
1348 extraWTotal -= extraW
1349 tab.SetSize((clipW + extraW, self.height))
1350 else:
1351 # first we loop through our tabs and calculate the the largest tab. This
1352 # is the size that we will base our calculations off
1353 max_width = 100 # Tab should be at least 100
1354 for tab in self.tabs:
1355 mw, _ = tab.GetMinSize() # Tab min size includes tab contents

Callers 8

UpdateSizeMethod · 0.95
AddTabMethod · 0.95
DeleteTabMethod · 0.95
SetPageTitleMethod · 0.80
SetPageTitleExtraMethod · 0.80
SetPageIconMethod · 0.80
SetPageTextIconMethod · 0.80
updateExtraTextMethod · 0.80

Calls 7

GetTabsCountMethod · 0.95
UpdateTabFXMethod · 0.95
UpdateTabsPositionMethod · 0.95
GetMinSizeMethod · 0.80
itemsMethod · 0.80
SetSizeMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected