| 1120 | } |
| 1121 | |
| 1122 | bool radioButtonOrModifier( const char* label, RadioButtonOrModifierState& value, int valButton, int modifiers, int respectedModifiers, std::optional<int> valueOverride ) |
| 1123 | { |
| 1124 | // See `checkboxOrModifier` for detailed comments |
| 1125 | if ( respectedModifiers == -1 ) |
| 1126 | respectedModifiers = modifiers; |
| 1127 | assert( ( respectedModifiers & modifiers ) == modifiers && "`respectedModifiers` must be a superset of `modifiers`." ); |
| 1128 | int modsPressed = ImGui::GetIO().KeyMods & respectedModifiers; |
| 1129 | |
| 1130 | bool modAnyHeld = !valueOverride && modsPressed != 0; // Any nonzero combination of relevant modifiers is pressed |
| 1131 | bool modActivated = !valueOverride && value.effectiveValue != valButton && |
| 1132 | // Return to base value if no modifiers pressed |
| 1133 | ( modsPressed != 0 ? modsPressed == modifiers : value.value == valButton ); |
| 1134 | if ( modActivated ) |
| 1135 | value.effectiveValue = valButton; |
| 1136 | // If no modifiers combination matches any button, a previous effective value remains |
| 1137 | |
| 1138 | bool buttonActivated = radioButtonOrFixedValue( label, &value.effectiveValue, valButton, |
| 1139 | valueOverride ? valueOverride : modAnyHeld ? std::optional( int( value ) ) : std::nullopt ); |
| 1140 | if ( modifiers != 0 ) |
| 1141 | { |
| 1142 | ImGui::SameLine(); |
| 1143 | ImGui::TextDisabled( "[%s]", modifiersToString( modifiers ).c_str() ); |
| 1144 | } |
| 1145 | |
| 1146 | if ( buttonActivated ) |
| 1147 | value.value = valButton; |
| 1148 | //if ( modActivated ) |
| 1149 | // detail::markItemEdited( ImGui::GetID( label ) ); |
| 1150 | |
| 1151 | return buttonActivated || modActivated; |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | /// copy of internal ImGui method |
no test coverage detected