Skip to content

Commit

Permalink
🤏 [AspectRatio] Scroll on dropdown to switch between items
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed Nov 9, 2024
1 parent ad733a2 commit 482478b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/Cool/Image/AspectRatio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <regex>
#include <smart/smart.hpp>
#include <stringify/stringify.hpp>
#include "Cool/String/String.h"
#include "Cool/ImGui/ImGuiExtras.h"

namespace Cool {

Expand Down Expand Up @@ -74,15 +74,16 @@ auto AspectRatio::imgui(float width, const char* label) -> bool
bool b = false;

static const auto ratios = std::array{
std::make_pair(" A4 Horizontal ", std::sqrt(2.f)),
// Sorted from biggest to smallest
std::make_pair(" 16 / 9 ", 16.f / 9.f),
std::make_pair(" 3 / 2 ", 3.f / 2.f),
std::make_pair(" A4 Horizontal ", std::sqrt(2.f)),
std::make_pair(" 4 / 3 ", 4.f / 3.f),
std::make_pair(" 1 / 1 ", 1.f),
std::make_pair(" 3 / 4 ", 3.f / 4.f),
std::make_pair(" A4 Vertical ", 1.f / std::sqrt(2.f)),
std::make_pair(" 9 / 16 ", 9.f / 16.f),
std::make_pair(" 2 / 3 ", 2.f / 3.f),
std::make_pair(" 3 / 4 ", 3.f / 4.f),
std::make_pair(" 9 / 16 ", 9.f / 16.f),
};

ImGui::SetNextItemWidth(
Expand All @@ -100,6 +101,7 @@ auto AspectRatio::imgui(float width, const char* label) -> bool
{
_input = string_from_ratio(_ratio);
}
bool const input_text_is_hovered = ImGui::IsItemHovered();

ImGui::SameLine(0.f, 0.f);

Expand All @@ -116,6 +118,22 @@ auto AspectRatio::imgui(float width, const char* label) -> bool
ImGui::EndCombo();
}

if ((input_text_is_hovered || ImGui::IsItemHovered()) && ImGui::GetIO().MouseWheel != 0.f)
{
bool const find_bigger = ImGui::GetIO().MouseWheel > 0.f;
int const sz = ratios.size();

Check failure on line 124 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Windows MSVC Release

the following warning is treated as an error

Check warning on line 124 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Windows MSVC Release

'initializing': conversion from 'size_t' to 'int', possible loss of data

Check warning on line 124 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Windows MSVC Release

'initializing': conversion from 'size_t' to 'const int', possible loss of data

Check failure on line 124 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Windows MSVC Debug

the following warning is treated as an error

Check warning on line 124 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Windows MSVC Debug

'initializing': conversion from 'size_t' to 'int', possible loss of data

Check warning on line 124 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Windows MSVC Debug

'initializing': conversion from 'size_t' to 'const int', possible loss of data
for (int i = find_bigger ? sz - 1 : 0; find_bigger ? (i >= 0) : (i < sz); i += find_bigger ? -1 : 1)
{
float const ratio = ratios.at(i).second;

Check failure on line 127 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Linux Clang Debug

implicit conversion changes signedness: 'int' to 'std::array::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]

Check failure on line 127 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Linux GCC Release

conversion to ‘std::array<std::pair<const char*, float>, 9>::size_type’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Werror=sign-conversion]

Check failure on line 127 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Linux Clang Release

implicit conversion changes signedness: 'int' to 'std::array::size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]

Check failure on line 127 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Linux GCC Debug

conversion to ‘std::array<std::pair<const char*, float>, 9>::size_type’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Werror=sign-conversion]

Check failure on line 127 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Windows Clang Debug

implicit conversion changes signedness: 'int' to 'size_type' (aka 'unsigned long long') [-Werror,-Wsign-conversion]

Check failure on line 127 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / Windows Clang Release

implicit conversion changes signedness: 'int' to 'size_type' (aka 'unsigned long long') [-Werror,-Wsign-conversion]

Check failure on line 127 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / MacOS Clang Debug

implicit conversion changes signedness: 'int' to 'size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]

Check failure on line 127 in src/Cool/Image/AspectRatio.cpp

View workflow job for this annotation

GitHub Actions / MacOS Clang Release

implicit conversion changes signedness: 'int' to 'size_type' (aka 'unsigned long') [-Werror,-Wsign-conversion]
if (find_bigger ? (ratio > _ratio) : (ratio < _ratio))
{
set(ratio);
b = true;
break;
}
}
}

return b;
}

Expand Down

0 comments on commit 482478b

Please sign in to comment.