mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-26 14:41:14 +01:00
Improved algorithm for rearranging toolbars after docking one...
... A double-height bar can now insert left of two stacked single-height bars. For instance you can un-dock the Tools toolbar from the default setup, then drag it back, and now get the same result as you started with.
This commit is contained in:
@@ -147,22 +147,27 @@ void ToolBarConfiguration::Insert(ToolBar *bar, Position position)
|
|||||||
|
|
||||||
// Insert as a leaf, or as an internal node?
|
// Insert as a leaf, or as an internal node?
|
||||||
if (adopt && position.adopt) {
|
if (adopt && position.adopt) {
|
||||||
// Existing child of parent become its grandchild
|
// Existing children of parent become grandchildren
|
||||||
|
|
||||||
// TODO: is it ever correct to adopt more than one, depending on
|
|
||||||
// heights? Could an inserted tall bar adopt two short ones?
|
|
||||||
|
|
||||||
// Make NEW node
|
// Make NEW node
|
||||||
Tree tree;
|
Tree tree;
|
||||||
tree.pBar = bar;
|
tree.pBar = bar;
|
||||||
|
|
||||||
// Do adoption
|
// Do adoption
|
||||||
|
const auto barHeight = bar->GetSize().GetY() + toolbarGap;
|
||||||
|
auto totalHeight = 0;
|
||||||
|
while (iter != pForest->end() &&
|
||||||
|
barHeight >=
|
||||||
|
(totalHeight += (iter->pBar->GetSize().GetY() + toolbarGap))) {
|
||||||
tree.children.push_back(Tree{});
|
tree.children.push_back(Tree{});
|
||||||
auto &child = tree.children.back();
|
auto &child = tree.children.back();
|
||||||
child.pBar = iter->pBar;
|
child.pBar = iter->pBar;
|
||||||
child.children.swap(iter->children);
|
child.children.swap(iter->children);
|
||||||
|
iter = pForest->erase(iter);
|
||||||
|
}
|
||||||
|
|
||||||
// Put the node in the tree
|
// Put the node in the tree
|
||||||
|
iter = pForest->insert(iter, Tree{});
|
||||||
(*iter).swap(tree);
|
(*iter).swap(tree);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user