Skip to content

Commit

Permalink
import double-click fixes from podcast-plugins
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Feb 4, 2025
1 parent ef4d10e commit b463086
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion dpf-widgets
19 changes: 12 additions & 7 deletions plugin/MasterMeUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1967,26 +1967,31 @@ class MasterMeUI : public UI,
area = slider->getAbsoluteArea();
}

doubleClickHelper = new DoubleClickHelper(this, this, widget, area, theme);

String s;
char text[32] = {};
if (isInteger)
s = String(static_cast<int>(value));
std::snprintf(text, 31, "%d", static_cast<int>(value));
else
s = String(std::round(value * 10.f)/10.f);
std::snprintf(text, 31, "%.1f", std::round(value * 10.f)/10.f);

doubleClickHelper->setText(s.buffer());
doubleClickHelper = new DoubleClickHelper(this, this, widget, text, area, theme);
}

static inline float safeNumberFromText(const uint id, const bool isInteger, const char* const text) noexcept
{
float value;

if (isInteger)
{
try {
value = static_cast<float>(std::atoi(text));
} DISTRHO_SAFE_EXCEPTION_RETURN("safeNumberFromText", kParameterRanges[id].def);
}
else
{
const ScopedSafeLocale ssl;

try {
value = static_cast<float>(isInteger ? std::atoi(text) : std::atof(text));
value = static_cast<float>(std::atof(text));
} DISTRHO_SAFE_EXCEPTION_RETURN("safeNumberFromText", kParameterRanges[id].def);
}

Expand Down
20 changes: 5 additions & 15 deletions plugin/widgets/DoubleClickHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,20 @@ class DoubleClickHelper : public ImGuiTopLevelWidget
explicit DoubleClickHelper(TopLevelWidget* const tlw,
Callback* const cb,
SubWidget* const w,
const char* const text,
const Rectangle<int>& area,
const QuantumTheme& theme)
: ImGuiTopLevelWidget(tlw->getWindow(), theme.fontSize),
callback(cb),
widget(w)
{
// FIXME: DGL should trigger resizes automatically when creating non-1st top level widgets
ResizeEvent ev;
ev.size = tlw->getSize();
onResize(ev);

pos = ImVec2(area.getX(), area.getY());
size = ImVec2(area.getWidth(), area.getHeight());

ImGuiIO& io(ImGui::GetIO());
io.ConfigFlags &= ~ImGuiConfigFlags_None;
std::strncpy(textBuf, text, sizeof(textBuf)-1);

ImGuiStyle& style(ImGui::GetStyle());
style.WindowPadding = ImVec2(theme.padding, theme.padding);
style.WindowPadding = ImVec2();
style.WindowRounding = style.WindowBorderSize = 0.f;
style.ChildRounding = style.ChildBorderSize = 0.f;
style.PopupRounding = style.PopupBorderSize = 0.f;
Expand All @@ -80,11 +75,6 @@ class DoubleClickHelper : public ImGuiTopLevelWidget
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4Color(theme.widgetActiveColor);
}

void setText(const char* const text)
{
std::strncpy(textBuf, text, sizeof(textBuf)-1);
}

protected:
void idleCallback() override
{
Expand All @@ -102,6 +92,7 @@ class DoubleClickHelper : public ImGuiTopLevelWidget
{
ImGui::SetNextWindowPos(pos);
ImGui::SetNextWindowSize(size);
ImGui::SetNextWindowContentSize(size);
ImGui::SetNextWindowFocus();

constexpr const ImGuiWindowFlags windowFlags = 0
Expand All @@ -114,6 +105,7 @@ class DoubleClickHelper : public ImGuiTopLevelWidget
|ImGuiInputTextFlags_CharsDecimal
|ImGuiInputTextFlags_CharsScientific
|ImGuiInputTextFlags_CharsNoBlank
|ImGuiInputTextFlags_AutoSelectAll
|ImGuiInputTextFlags_EnterReturnsTrue;

const bool wasFirstOpen = firstOpen;
Expand All @@ -126,8 +118,6 @@ class DoubleClickHelper : public ImGuiTopLevelWidget
ImGui::SetKeyboardFocusHere();
}

ImGui::SetCursorPosY(ImGui::GetTextLineHeight() * 0.5f);

closeOnNextIdle |= ImGui::InputText("Value", textBuf, sizeof(textBuf), textFlags);

if (!wasFirstOpen && !ImGui::IsItemActive())
Expand Down

0 comments on commit b463086

Please sign in to comment.