mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:20:06 +00:00 
			
		
		
		
	Refactor tooltip display
This commit is contained in:
		
							parent
							
								
									9ebc859756
								
							
						
					
					
						commit
						0badf01a92
					
				
					 8 changed files with 87 additions and 28 deletions
				
			
		|  | @ -1,7 +1,7 @@ | |||
| #include <scwx/qt/gl/draw/placefile_icons.hpp> | ||||
| #include <scwx/qt/util/imgui.hpp> | ||||
| #include <scwx/qt/util/maplibre.hpp> | ||||
| #include <scwx/qt/util/texture_atlas.hpp> | ||||
| #include <scwx/qt/util/tooltip.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <execution> | ||||
|  | @ -685,7 +685,7 @@ void PlacefileIcons::Impl::Update(bool textureAtlasChanged) | |||
| bool PlacefileIcons::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|    const QPointF& /* mouseLocalPos */, | ||||
|    const QPointF& /* mouseGlobalPos */, | ||||
|    const QPointF&   mouseGlobalPos, | ||||
|    const glm::vec2& mouseCoords) | ||||
| { | ||||
|    std::unique_lock lock {p->iconMutex_}; | ||||
|  | @ -774,7 +774,7 @@ bool PlacefileIcons::RunMousePicking( | |||
|    if (it != p->currentHoverIcons_.crend()) | ||||
|    { | ||||
|       itemPicked = true; | ||||
|       util::ImGui::Instance().DrawTooltip(it->di_->hoverText_); | ||||
|       util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos); | ||||
|    } | ||||
| 
 | ||||
|    return itemPicked; | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| #include <scwx/qt/gl/draw/placefile_lines.hpp> | ||||
| #include <scwx/qt/util/geographic_lib.hpp> | ||||
| #include <scwx/qt/util/imgui.hpp> | ||||
| #include <scwx/qt/util/maplibre.hpp> | ||||
| #include <scwx/qt/util/tooltip.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <execution> | ||||
|  | @ -498,7 +498,7 @@ void PlacefileLines::Impl::Update() | |||
| bool PlacefileLines::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|    const QPointF& /* mouseLocalPos */, | ||||
|    const QPointF& /* mouseGlobalPos */, | ||||
|    const QPointF&   mouseGlobalPos, | ||||
|    const glm::vec2& mouseCoords) | ||||
| { | ||||
|    std::unique_lock lock {p->lineMutex_}; | ||||
|  | @ -589,7 +589,7 @@ bool PlacefileLines::RunMousePicking( | |||
|    if (it != p->currentHoverLines_.crend()) | ||||
|    { | ||||
|       itemPicked = true; | ||||
|       util::ImGui::Instance().DrawTooltip(it->di_->hoverText_); | ||||
|       util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos); | ||||
|    } | ||||
| 
 | ||||
|    return itemPicked; | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include <scwx/qt/gl/draw/placefile_text.hpp> | ||||
| #include <scwx/qt/util/imgui.hpp> | ||||
| #include <scwx/qt/util/maplibre.hpp> | ||||
| #include <scwx/qt/util/tooltip.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <fmt/format.h> | ||||
|  | @ -210,7 +210,7 @@ void PlacefileText::Deinitialize() | |||
| bool PlacefileText::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& /* params */, | ||||
|    const QPointF& /* mouseLocalPos */, | ||||
|    const QPointF& /* mouseGlobalPos */, | ||||
|    const QPointF& mouseGlobalPos, | ||||
|    const glm::vec2& /* mouseCoords */) | ||||
| { | ||||
|    bool itemPicked = false; | ||||
|  | @ -219,7 +219,7 @@ bool PlacefileText::RunMousePicking( | |||
|    if (!p->hoverText_.empty()) | ||||
|    { | ||||
|       itemPicked = true; | ||||
|       util::ImGui::Instance().DrawTooltip(p->hoverText_); | ||||
|       util::tooltip::Show(p->hoverText_, mouseGlobalPos); | ||||
|    } | ||||
| 
 | ||||
|    return itemPicked; | ||||
|  |  | |||
|  | @ -14,6 +14,7 @@ | |||
| #include <scwx/qt/model/imgui_context_model.hpp> | ||||
| #include <scwx/qt/util/file.hpp> | ||||
| #include <scwx/qt/util/maplibre.hpp> | ||||
| #include <scwx/qt/util/tooltip.hpp> | ||||
| #include <scwx/qt/view/radar_product_view_factory.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| #include <scwx/util/time.hpp> | ||||
|  | @ -1062,6 +1063,7 @@ void MapWidgetImpl::RunMousePicking() | |||
| 
 | ||||
|    // For each layer in reverse
 | ||||
|    // TODO: All Generic Layers, not just Placefile Layers
 | ||||
|    bool itemPicked = false; | ||||
|    for (auto it = placefileLayers_.rbegin(); it != placefileLayers_.rend(); | ||||
|         ++it) | ||||
|    { | ||||
|  | @ -1070,9 +1072,16 @@ void MapWidgetImpl::RunMousePicking() | |||
|              params, lastPos_, lastGlobalPos_, mouseScreenCoordinate)) | ||||
|       { | ||||
|          // If a draw item was picked, don't process additional layers
 | ||||
|          itemPicked = true; | ||||
|          break; | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    // If no draw item was picked, hide the tooltip
 | ||||
|    if (!itemPicked) | ||||
|    { | ||||
|       util::tooltip::Hide(); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void MapWidget::mapChanged(QMapLibreGL::Map::MapChange mapChange) | ||||
|  |  | |||
|  | @ -1,12 +1,10 @@ | |||
| #include <scwx/qt/util/imgui.hpp> | ||||
| #include <scwx/qt/manager/resource_manager.hpp> | ||||
| #include <scwx/qt/manager/settings_manager.hpp> | ||||
| #include <scwx/qt/settings/text_settings.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <mutex> | ||||
| 
 | ||||
| #include <TextFlow.hpp> | ||||
| #include <imgui.h> | ||||
| 
 | ||||
| namespace scwx | ||||
|  | @ -89,23 +87,9 @@ void ImGui::DrawTooltip(const std::string& hoverText) | |||
| { | ||||
|    p->Initialize(); | ||||
| 
 | ||||
|    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(hoverText).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 : hoverText; | ||||
| 
 | ||||
|    ::ImGui::BeginTooltip(); | ||||
|    ::ImGui::PushFont(p->monospaceFont_); | ||||
|    ::ImGui::TextUnformatted(displayText.c_str()); | ||||
|    ::ImGui::TextUnformatted(hoverText.c_str()); | ||||
|    ::ImGui::PopFont(); | ||||
|    ::ImGui::EndTooltip(); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										42
									
								
								scwx-qt/source/scwx/qt/util/tooltip.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								scwx-qt/source/scwx/qt/util/tooltip.cpp
									
										
									
									
									
										Normal 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
 | ||||
							
								
								
									
										22
									
								
								scwx-qt/source/scwx/qt/util/tooltip.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								scwx-qt/source/scwx/qt/util/tooltip.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,22 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <string> | ||||
| 
 | ||||
| #include <QPoint> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace util | ||||
| { | ||||
| namespace tooltip | ||||
| { | ||||
| 
 | ||||
| void Show(const std::string& text, const QPointF& mouseGlobalPos); | ||||
| void Hide(); | ||||
| 
 | ||||
| } // namespace tooltip
 | ||||
| } // namespace util
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat