| 1926 | } |
| 1927 | |
| 1928 | void ImageViewer::selectGroup(string_view group) { |
| 1929 | // If the group does not exist, select the first group. |
| 1930 | const auto id = groupId(group).value_or(0); |
| 1931 | |
| 1932 | auto& buttons = mGroupButtonContainer->children(); |
| 1933 | for (size_t i = 0; i < buttons.size(); ++i) { |
| 1934 | dynamic_cast<ImageButton*>(buttons[i])->setIsSelected(i == id); |
| 1935 | } |
| 1936 | |
| 1937 | mCurrentGroup = groupName(id); |
| 1938 | mImageCanvas->setRequestedChannelGroup(mCurrentGroup); |
| 1939 | |
| 1940 | // Ensure the currently active group button is always fully on-screen |
| 1941 | Widget* activeGroupButton = nullptr; |
| 1942 | for (Widget* widget : mGroupButtonContainer->children()) { |
| 1943 | if (dynamic_cast<ImageButton*>(widget)->isSelected()) { |
| 1944 | activeGroupButton = widget; |
| 1945 | break; |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | // Ensure the currently active group button is always fully on-screen |
| 1950 | if (activeGroupButton) { |
| 1951 | mGroupButtonContainer->set_position( |
| 1952 | Vector2i{ |
| 1953 | clamp( |
| 1954 | mGroupButtonContainer->position().x(), |
| 1955 | -activeGroupButton->position().x(), |
| 1956 | m_size.x() - activeGroupButton->position().x() - activeGroupButton->width() |
| 1957 | ), |
| 1958 | 0 |
| 1959 | } |
| 1960 | ); |
| 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | void ImageViewer::selectReference(const shared_ptr<Image>& image) { |
| 1965 | if (!image) { |
nothing calls this directly
no test coverage detected