| 1085 | } |
| 1086 | |
| 1087 | bool WaveChannelView::ToggleSubView(Display display) |
| 1088 | { |
| 1089 | size_t ii = 0; |
| 1090 | size_t found = 0; |
| 1091 | if (WaveChannelSubViews::FindIf([&](const WaveChannelSubView &subView) { |
| 1092 | if (subView.SubViewType().id == display) { |
| 1093 | found = ii; |
| 1094 | return true; |
| 1095 | } |
| 1096 | ++ii; |
| 1097 | return false; |
| 1098 | })) { |
| 1099 | auto &placements = DoGetPlacements(); |
| 1100 | auto &foundPlacement = placements[found]; |
| 1101 | if ( foundPlacement.fraction > 0.0 ) { |
| 1102 | // Toggle off |
| 1103 | |
| 1104 | if (GetDisplays().size() < 2) |
| 1105 | // refuse to do it |
| 1106 | return false; |
| 1107 | |
| 1108 | auto index = foundPlacement.index; |
| 1109 | foundPlacement = { -1, 0.0 }; |
| 1110 | if (index >= 0) { |
| 1111 | for ( auto &placement : placements ) { |
| 1112 | if ( placement.index > index ) |
| 1113 | --placement.index; |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | return true; |
| 1118 | } |
| 1119 | else { |
| 1120 | // Toggle on |
| 1121 | float total = 0; |
| 1122 | int greatest = -1; |
| 1123 | unsigned nn = 0; |
| 1124 | for ( const auto &placement : placements ) { |
| 1125 | if ( placement.fraction > 0.0 && placement.index >= 0 ) { |
| 1126 | total += placement.fraction; |
| 1127 | greatest = std::max( greatest, placement.index ); |
| 1128 | ++nn; |
| 1129 | } |
| 1130 | } |
| 1131 | // Turn on the sub-view, putting it lowest, and with average of the |
| 1132 | // heights of the other sub-views |
| 1133 | foundPlacement = { greatest + 1, total / nn }; |
| 1134 | |
| 1135 | return true; |
| 1136 | } |
| 1137 | } |
| 1138 | else |
| 1139 | // unknown sub-view |
| 1140 | return false; |
| 1141 | } |
| 1142 | |
| 1143 | // If exclusive, make the chosen view take up all the height. Else, |
| 1144 | // partition equally, putting the specified view on top. |
no test coverage detected