Skip to content

Commit

Permalink
Change ModInt32 to use int in ctor; add ModSliderInt32
Browse files Browse the repository at this point in the history
  • Loading branch information
narknon committed Nov 30, 2023
1 parent 09af905 commit f9a62c0
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/Mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ class ModInt32 : public ModValue<int32_t> {
public:
using Ptr = std::unique_ptr<ModInt32>;

static auto create(std::string_view config_name, uint32_t default_value = 0) {
static auto create(std::string_view config_name, int32_t default_value = 0) {
return std::make_unique<ModInt32>(config_name, default_value);
}

ModInt32(std::string_view config_name, uint32_t default_value = 0)
: ModValue{ config_name, static_cast<int>(default_value) }
ModInt32(std::string_view config_name, int32_t default_value = 0)
: ModValue{ config_name, default_value }
{
}

Expand All @@ -199,6 +199,43 @@ class ModInt32 : public ModValue<int32_t> {
}
};

class ModSliderInt32 : public ModInt32 {
public:
using Ptr = std::unique_ptr<ModSliderInt32>;

static auto create(std::string_view config_name, int32_t mn = -100, int32_t mx = 100, int32_t default_value = 0) {
return std::make_unique<ModSliderInt32>(config_name, mn, mx, default_value);
}

ModSliderInt32(std::string_view config_name, int32_t mn = -100, int32_t mx = 100, int32_t default_value = 0)
: ModInt32{ config_name, default_value },
m_int_range{ mn, mx }
{
}

bool draw(std::string_view name) override {
ImGui::PushID(this);
auto ret = ImGui::SliderInt(name.data(), &m_value, m_int_range.min, m_int_range.max);
ImGui::PopID();

return ret;
}

void draw_value(std::string_view name) override {
ImGui::Text("%s: %i [%i, %i]", name.data(), m_value, m_int_range.min, m_int_range.max);
}

auto& range() {
return m_int_range;
}

protected:
struct SliderIntRange {
int min;
int max;
}m_int_range;
};

class ModCombo : public ModValue<int32_t> {
public:
using Ptr = std::unique_ptr<ModCombo>;
Expand Down

0 comments on commit f9a62c0

Please sign in to comment.