Change: Text Layouter support querying all lines for character at pixel
This commit is contained in:
		
				
					committed by
					
						
						Patric Stout
					
				
			
			
				
	
			
			
			
						parent
						
							d1a0ca67be
						
					
				
				
					commit
					4765d0f8c2
				
			@@ -899,7 +899,7 @@ ptrdiff_t GetCharAtPosition(std::string_view str, int x, FontSize start_fontsize
 | 
			
		||||
	if (x < 0) return -1;
 | 
			
		||||
 | 
			
		||||
	Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize);
 | 
			
		||||
	return layout.GetCharAtPosition(x);
 | 
			
		||||
	return layout.GetCharAtPosition(x, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
@@ -270,11 +270,14 @@ Point Layouter::GetCharPosition(std::string_view::const_iterator ch) const
 | 
			
		||||
/**
 | 
			
		||||
 * Get the character that is at a pixel position in the first line of the layouted text.
 | 
			
		||||
 * @param x Position in the string.
 | 
			
		||||
 * @param line_index Which line of the layout to search
 | 
			
		||||
 * @return String offset of the position (bytes) or -1 if no character is at the position.
 | 
			
		||||
 */
 | 
			
		||||
ptrdiff_t Layouter::GetCharAtPosition(int x) const
 | 
			
		||||
ptrdiff_t Layouter::GetCharAtPosition(int x, size_t line_index) const
 | 
			
		||||
{
 | 
			
		||||
	const auto &line = this->front();
 | 
			
		||||
	if (line_index >= this->size()) return -1;
 | 
			
		||||
 | 
			
		||||
	const auto &line = this->at(line_index);
 | 
			
		||||
 | 
			
		||||
	for (int run_index = 0; run_index < line->CountRuns(); run_index++) {
 | 
			
		||||
		const ParagraphLayouter::VisualRun &run = line->GetVisualRun(run_index);
 | 
			
		||||
 
 | 
			
		||||
@@ -177,7 +177,7 @@ public:
 | 
			
		||||
	Layouter(std::string_view str, int maxw = INT32_MAX, TextColour colour = TC_FROMSTRING, FontSize fontsize = FS_NORMAL);
 | 
			
		||||
	Dimension GetBounds();
 | 
			
		||||
	Point GetCharPosition(std::string_view::const_iterator ch) const;
 | 
			
		||||
	ptrdiff_t GetCharAtPosition(int x) const;
 | 
			
		||||
	ptrdiff_t GetCharAtPosition(int x, size_t line_index) const;
 | 
			
		||||
 | 
			
		||||
	static void ResetFontCache(FontSize size);
 | 
			
		||||
	static void ResetLineCache();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user