Tech ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT - Modified ImGuiWrapper::slider_float() to create a compound widget where an additional button can be used to set the keyboard focus into the slider to allow the user to type in the desired value

This commit is contained in:
enricoturri1966
2021-11-05 14:46:44 +01:00
parent 740a1b020c
commit 2cfcc63c58
11 changed files with 183 additions and 37 deletions

View File

@@ -85,14 +85,6 @@ const ImVec4 ImGuiWrapper::COL_BUTTON_HOVERED = COL_ORANGE_LIGHT;
const ImVec4 ImGuiWrapper::COL_BUTTON_ACTIVE = ImGuiWrapper::COL_BUTTON_HOVERED;
ImGuiWrapper::ImGuiWrapper()
: m_glyph_ranges(nullptr)
, m_font_cjk(false)
, m_font_size(18.0)
, m_font_texture(0)
, m_style_scaling(1.0)
, m_mouse_buttons(0)
, m_disabled(false)
, m_new_frame_open(false)
{
ImGui::CreateContext();
@@ -484,6 +476,47 @@ void ImGuiWrapper::tooltip(const wxString &label, float wrap_width)
ImGui::EndTooltip();
}
#if ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT
bool ImGuiWrapper::slider_float(const char* label, float* v, float v_min, float v_max, const char* format/* = "%.3f"*/, float power/* = 1.0f*/, bool clamp /*= true*/, const wxString& tooltip /*= ""*/, bool show_edit_btn /*= true*/)
{
const float max_tooltip_width = ImGui::GetFontSize() * 20.0f;
bool ret = ImGui::SliderFloat(label, v, v_min, v_max, format, power);
if (!tooltip.empty() && ImGui::IsItemHovered())
this->tooltip(into_u8(tooltip).c_str(), max_tooltip_width);
if (clamp)
*v = std::clamp(*v, v_min, v_max);
if (show_edit_btn) {
const ImGuiStyle& style = ImGui::GetStyle();
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, { 1, style.ItemSpacing.y });
ImGui::SameLine();
const std::string btn_name = "..." + std::string(label);
if (ImGui::Button(btn_name.c_str())) {
ImGui::SetKeyboardFocusHere(-1);
this->set_requires_extra_frame();
}
if (ImGui::IsItemHovered())
this->tooltip(into_u8(_L("Edit")).c_str(), max_tooltip_width);
ImGui::PopStyleVar();
}
return ret;
}
bool ImGuiWrapper::slider_float(const std::string& label, float* v, float v_min, float v_max, const char* format/* = "%.3f"*/, float power/* = 1.0f*/, bool clamp /*= true*/, const wxString& tooltip /*= ""*/, bool show_edit_btn /*= true*/)
{
return this->slider_float(label.c_str(), v, v_min, v_max, format, power, clamp, tooltip, show_edit_btn);
}
bool ImGuiWrapper::slider_float(const wxString& label, float* v, float v_min, float v_max, const char* format/* = "%.3f"*/, float power/* = 1.0f*/, bool clamp /*= true*/, const wxString& tooltip /*= ""*/, bool show_edit_btn /*= true*/)
{
auto label_utf8 = into_u8(label);
return this->slider_float(label_utf8.c_str(), v, v_min, v_max, format, power, clamp, tooltip, show_edit_btn);
}
#else
bool ImGuiWrapper::slider_float(const char* label, float* v, float v_min, float v_max, const char* format/* = "%.3f"*/, float power/* = 1.0f*/, bool clamp /*= true*/)
{
bool ret = ImGui::SliderFloat(label, v, v_min, v_max, format, power);
@@ -502,6 +535,7 @@ bool ImGuiWrapper::slider_float(const wxString& label, float* v, float v_min, fl
auto label_utf8 = into_u8(label);
return this->slider_float(label_utf8.c_str(), v, v_min, v_max, format, power, clamp);
}
#endif // ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT
bool ImGuiWrapper::combo(const wxString& label, const std::vector<std::string>& options, int& selection)
{