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_h(h) | ||||||
|   { |   { | ||||||
|     m_widget->getEntryThemeInfo(&m_index, &m_caret, &m_state, &m_range); |     m_widget->getEntryThemeInfo(&m_index, &m_caret, &m_state, &m_range); | ||||||
|  |     m_suffixIndex = m_widget->text().size(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   int index() const { return m_index; } |   int index() const { return m_index; } | ||||||
|  | @ -1369,6 +1370,11 @@ public: | ||||||
|     bg = ColorNone; |     bg = ColorNone; | ||||||
|     fg = colors.text(); |     fg = colors.text(); | ||||||
| 
 | 
 | ||||||
|  |     // Suffix text
 | ||||||
|  |     if (m_index >= m_suffixIndex) { | ||||||
|  |       fg = colors.entrySuffix(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     // Selected
 |     // Selected
 | ||||||
|     if ((m_index >= m_range.from) && (m_index < m_range.to)) { |     if ((m_index >= m_range.from) && (m_index < m_range.to)) { | ||||||
|       if (m_widget->hasFocus()) |       if (m_widget->hasFocus()) | ||||||
|  | @ -1433,6 +1439,7 @@ private: | ||||||
|   int m_lastX; // Last position used to fill the background
 |   int m_lastX; // Last position used to fill the background
 | ||||||
|   int m_y, m_h; |   int m_y, m_h; | ||||||
|   int m_charStartX; |   int m_charStartX; | ||||||
|  |   int m_suffixIndex; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } // anonymous namespace
 | } // anonymous namespace
 | ||||||
|  | @ -1445,8 +1452,10 @@ void SkinTheme::drawEntryText(ui::Graphics* g, ui::Entry* widget) | ||||||
|   DrawEntryTextDelegate delegate(widget, g, bounds.origin(), widget->textHeight()); |   DrawEntryTextDelegate delegate(widget, g, bounds.origin(), widget->textHeight()); | ||||||
|   int scroll = delegate.index(); |   int scroll = delegate.index(); | ||||||
| 
 | 
 | ||||||
|   if (!widget->text().empty()) { |   // Full text to paint: widget text + suffix
 | ||||||
|     const std::string& textString = widget->text(); |   const std::string textString = widget->text() + widget->getSuffix(); | ||||||
|  | 
 | ||||||
|  |   if (!textString.empty()) { | ||||||
|     base::utf8_decode dec(textString); |     base::utf8_decode dec(textString); | ||||||
|     auto pos = dec.pos(); |     auto pos = dec.pos(); | ||||||
|     for (int i = 0; i < scroll && dec.next(); ++i) |     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); |     IntersectClip clip(g, bounds); | ||||||
|     if (clip) { |     if (clip) { | ||||||
|       g->drawTextWithDelegate( |       int baselineAdjustment = widget->textBaseline(); | ||||||
|         std::string(pos, textString.end()), // TODO use a string_view()
 |       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(), |                               colors.text(), | ||||||
|                               ColorNone, |                               ColorNone, | ||||||
|         gfx::Point(bounds.x, widget->textBaseline() - widget->textBlob()->baseline()), |                               gfx::Point(bounds.x, baselineAdjustment), | ||||||
|                               &delegate); |                               &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
 |   // Draw caret at the end of the text
 | ||||||
|   if (!delegate.caretDrawn()) { |   if (!delegate.caretDrawn()) { | ||||||
|     gfx::Rect charBounds(bounds.x + widget->bounds().x, |     gfx::Rect charBounds(bounds.x + widget->bounds().x, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue