Refactor tooltip display

This commit is contained in:
Dan Paulat 2023-09-09 00:49:23 -05:00
parent 9ebc859756
commit 0badf01a92
8 changed files with 87 additions and 28 deletions

View file

@ -0,0 +1,42 @@
#include <scwx/qt/util/tooltip.hpp>
#include <scwx/qt/settings/text_settings.hpp>
#include <scwx/qt/util/imgui.hpp>
#include <TextFlow.hpp>
namespace scwx
{
namespace qt
{
namespace util
{
namespace tooltip
{
static const std::string logPrefix_ = "scwx::qt::util::tooltip";
void Show(const std::string& text, const QPointF& /* mouseGlobalPos */)
{
std::size_t textWidth = static_cast<std::size_t>(
settings::TextSettings::Instance().hover_text_wrap().GetValue());
// Wrap text if enabled
std::string wrappedText {};
if (textWidth > 0)
{
wrappedText = TextFlow::Column(text).width(textWidth).toString();
}
// Display text is either wrapped or unwrapped text (do this to avoid copy
// when not wrapping)
const std::string& displayText = (textWidth > 0) ? wrappedText : text;
util::ImGui::Instance().DrawTooltip(displayText);
}
void Hide() {}
} // namespace tooltip
} // namespace util
} // namespace qt
} // namespace scwx