1
0
mirror of synced 2025-01-10 21:41:53 +01:00

impr: Better color picker widgets in the settings

This commit is contained in:
WerWolv 2025-01-07 21:46:26 +01:00
parent 5c58e5b545
commit f1d9642cf6
3 changed files with 38 additions and 15 deletions

View File

@ -20,6 +20,7 @@ using ImGuiDataType = int;
using ImGuiInputTextFlags = int;
struct ImColor;
enum ImGuiCustomCol : int;
typedef int ImGuiColorEditFlags;
namespace hex {
@ -192,7 +193,7 @@ namespace hex {
class ColorPicker : public Widget {
public:
explicit ColorPicker(ImColor defaultColor);
explicit ColorPicker(ImColor defaultColor, ImGuiColorEditFlags flags = 0);
bool draw(const std::string &name) override;
@ -202,7 +203,8 @@ namespace hex {
[[nodiscard]] ImColor getColor() const;
protected:
std::array<float, 4> m_value{};
std::array<float, 4> m_value = {}, m_defaultValue = {};
ImGuiColorEditFlags m_flags;
};
class DropDown : public Widget {

View File

@ -349,17 +349,34 @@ namespace hex {
}
ColorPicker::ColorPicker(ImColor defaultColor) {
m_value = {
ColorPicker::ColorPicker(ImColor defaultColor, ImGuiColorEditFlags flags) {
m_defaultValue = m_value = {
defaultColor.Value.x,
defaultColor.Value.y,
defaultColor.Value.z,
defaultColor.Value.w
};
m_flags = flags;
}
bool ColorPicker::draw(const std::string &name) {
return ImGui::ColorEdit4(name.c_str(), m_value.data(), ImGuiColorEditFlags_NoInputs);
ImGui::PushID(name.c_str());
auto result = ImGui::ColorEdit4("##color_picker", m_value.data(), ImGuiColorEditFlags_NoInputs | m_flags);
ImGui::SameLine();
if (ImGui::Button("X", ImGui::GetStyle().FramePadding * 2 + ImVec2(ImGui::GetTextLineHeight(), ImGui::GetTextLineHeight()))) {
m_value = m_defaultValue;
result = true;
}
ImGui::SameLine();
ImGui::TextUnformatted(name.c_str());
ImGui::PopID();
return result;
}
void ColorPicker::load(const nlohmann::json &data) {

View File

@ -288,7 +288,7 @@ namespace hex::plugin::builtin {
bool settingChanged = false;
ImGui::BeginDisabled(m_drawShortcut.matches(m_defaultShortcut));
if (ImGuiExt::IconButton(ICON_VS_X, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
if (ImGui::Button("X", ImGui::GetStyle().FramePadding * 2 + ImVec2(ImGui::GetTextLineHeight(), ImGui::GetTextLineHeight()))) {
this->reset();
if (!m_hasDuplicate) {
m_shortcut = m_defaultShortcut;
@ -789,7 +789,11 @@ namespace hex::plugin::builtin {
}
});
ContentRegistry::Settings::add<Widgets::ColorPicker>("hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.accent", ImGui::GetStyleColorVec4(ImGuiCol_Button))
ContentRegistry::Settings::add<Widgets::ColorPicker>(
"hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.accent",
ImGui::GetStyleColorVec4(ImGuiCol_Button),
ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoDragDrop | ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_NoInputs
)
.setChangedCallback([](auto &widget) {
auto colorPicker = static_cast<Widgets::ColorPicker *>(&widget);
ThemeManager::setAccentColor(colorPicker->getColor());