mirror of https://github.com/aseprite/aseprite.git
				
				
				
			Fix suffix separation in Entry fields w/TTF fonts (fix #5261)
This commit is contained in:
		
							parent
							
								
									ce742bcbc1
								
							
						
					
					
						commit
						1a6a39700e
					
				|  | @ -1350,6 +1350,7 @@ public: | |||
|     , m_h(h) | ||||
|   { | ||||
|     m_widget->getEntryThemeInfo(&m_index, &m_caret, &m_state, &m_range); | ||||
|     m_suffixIndex = m_widget->text().size(); | ||||
|   } | ||||
| 
 | ||||
|   int index() const { return m_index; } | ||||
|  | @ -1369,6 +1370,11 @@ public: | |||
|     bg = ColorNone; | ||||
|     fg = colors.text(); | ||||
| 
 | ||||
|     // Suffix text
 | ||||
|     if (m_index >= m_suffixIndex) { | ||||
|       fg = colors.entrySuffix(); | ||||
|     } | ||||
| 
 | ||||
|     // Selected
 | ||||
|     if ((m_index >= m_range.from) && (m_index < m_range.to)) { | ||||
|       if (m_widget->hasFocus()) | ||||
|  | @ -1433,6 +1439,7 @@ private: | |||
|   int m_lastX; // Last position used to fill the background
 | ||||
|   int m_y, m_h; | ||||
|   int m_charStartX; | ||||
|   int m_suffixIndex; | ||||
| }; | ||||
| 
 | ||||
| } // anonymous namespace
 | ||||
|  | @ -1445,8 +1452,10 @@ void SkinTheme::drawEntryText(ui::Graphics* g, ui::Entry* widget) | |||
|   DrawEntryTextDelegate delegate(widget, g, bounds.origin(), widget->textHeight()); | ||||
|   int scroll = delegate.index(); | ||||
| 
 | ||||
|   if (!widget->text().empty()) { | ||||
|     const std::string& textString = widget->text(); | ||||
|   // Full text to paint: widget text + suffix
 | ||||
|   const std::string textString = widget->text() + widget->getSuffix(); | ||||
| 
 | ||||
|   if (!textString.empty()) { | ||||
|     base::utf8_decode dec(textString); | ||||
|     auto pos = dec.pos(); | ||||
|     for (int i = 0; i < scroll && dec.next(); ++i) | ||||
|  | @ -1454,36 +1463,24 @@ void SkinTheme::drawEntryText(ui::Graphics* g, ui::Entry* widget) | |||
| 
 | ||||
|     IntersectClip clip(g, bounds); | ||||
|     if (clip) { | ||||
|       g->drawTextWithDelegate( | ||||
|         std::string(pos, textString.end()), // TODO use a string_view()
 | ||||
|       int baselineAdjustment = widget->textBaseline(); | ||||
|       if (auto blob = widget->textBlob()) { | ||||
|         baselineAdjustment -= blob->baseline(); | ||||
|       } | ||||
|       else { | ||||
|         text::FontMetrics metrics; | ||||
|         widget->font()->metrics(&metrics); | ||||
|         baselineAdjustment += metrics.ascent; | ||||
|       } | ||||
| 
 | ||||
|       g->drawTextWithDelegate(std::string(pos, textString.end()), // TODO use a string_view()
 | ||||
|                               colors.text(), | ||||
|                               ColorNone, | ||||
|         gfx::Point(bounds.x, widget->textBaseline() - widget->textBlob()->baseline()), | ||||
|                               gfx::Point(bounds.x, baselineAdjustment), | ||||
|                               &delegate); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   bounds.x += delegate.textBounds().w; | ||||
| 
 | ||||
|   // Draw suffix if there is enough space
 | ||||
|   if (!widget->getSuffix().empty()) { | ||||
|     Rect sufBounds(bounds.x, | ||||
|                    bounds.y, | ||||
|                    bounds.x2() - widget->childSpacing() - bounds.x, | ||||
|                    widget->textHeight()); | ||||
|     IntersectClip clip(g, sufBounds & widget->clientChildrenBounds()); | ||||
|     if (clip) { | ||||
|       drawText(g, | ||||
|                widget->getSuffix().c_str(), | ||||
|                colors.entrySuffix(), | ||||
|                ColorNone, | ||||
|                widget, | ||||
|                sufBounds, | ||||
|                widget->align(), | ||||
|                0); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   // Draw caret at the end of the text
 | ||||
|   if (!delegate.caretDrawn()) { | ||||
|     gfx::Rect charBounds(bounds.x + widget->bounds().x, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue