1
0
mirror of synced 2025-01-11 05:42:15 +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; using ImGuiInputTextFlags = int;
struct ImColor; struct ImColor;
enum ImGuiCustomCol : int; enum ImGuiCustomCol : int;
typedef int ImGuiColorEditFlags;
namespace hex { namespace hex {
@ -192,7 +193,7 @@ namespace hex {
class ColorPicker : public Widget { class ColorPicker : public Widget {
public: public:
explicit ColorPicker(ImColor defaultColor); explicit ColorPicker(ImColor defaultColor, ImGuiColorEditFlags flags = 0);
bool draw(const std::string &name) override; bool draw(const std::string &name) override;
@ -202,7 +203,8 @@ namespace hex {
[[nodiscard]] ImColor getColor() const; [[nodiscard]] ImColor getColor() const;
protected: protected:
std::array<float, 4> m_value{}; std::array<float, 4> m_value = {}, m_defaultValue = {};
ImGuiColorEditFlags m_flags;
}; };
class DropDown : public Widget { class DropDown : public Widget {

View File

@ -349,17 +349,34 @@ namespace hex {
} }
ColorPicker::ColorPicker(ImColor defaultColor) { ColorPicker::ColorPicker(ImColor defaultColor, ImGuiColorEditFlags flags) {
m_value = { m_defaultValue = m_value = {
defaultColor.Value.x, defaultColor.Value.x,
defaultColor.Value.y, defaultColor.Value.y,
defaultColor.Value.z, defaultColor.Value.z,
defaultColor.Value.w defaultColor.Value.w
}; };
m_flags = flags;
} }
bool ColorPicker::draw(const std::string &name) { 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) { void ColorPicker::load(const nlohmann::json &data) {

View File

@ -288,7 +288,7 @@ namespace hex::plugin::builtin {
bool settingChanged = false; bool settingChanged = false;
ImGui::BeginDisabled(m_drawShortcut.matches(m_defaultShortcut)); 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(); this->reset();
if (!m_hasDuplicate) { if (!m_hasDuplicate) {
m_shortcut = m_defaultShortcut; m_shortcut = m_defaultShortcut;
@ -789,11 +789,15 @@ 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>(
.setChangedCallback([](auto &widget) { "hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.accent",
auto colorPicker = static_cast<Widgets::ColorPicker *>(&widget); ImGui::GetStyleColorVec4(ImGuiCol_Button),
ThemeManager::setAccentColor(colorPicker->getColor()); ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoDragDrop | ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_NoInputs
}); )
.setChangedCallback([](auto &widget) {
auto colorPicker = static_cast<Widgets::ColorPicker *>(&widget);
ThemeManager::setAccentColor(colorPicker->getColor());
});
ContentRegistry::Settings::add<ScalingWidget>("hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.scaling_factor") ContentRegistry::Settings::add<ScalingWidget>("hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.scaling_factor")
.requiresRestart(); .requiresRestart();