| 87 | } |
| 88 | |
| 89 | int TextBoxWidget::getCursorDrawOffset() const { // horizontal only |
| 90 | float scale; |
| 91 | context()->setTextStyle(m_textStyle); |
| 92 | if (m_hAnchor == HorizontalAnchor::LeftAnchor) { |
| 93 | scale = 1.0; |
| 94 | } else if (m_hAnchor == HorizontalAnchor::HMidAnchor) { |
| 95 | scale = 0.5; |
| 96 | } else if (m_hAnchor == HorizontalAnchor::RightAnchor) { |
| 97 | scale = -1.0; |
| 98 | if (m_textHidden) { |
| 99 | int width = context()->stringWidth("*"); |
| 100 | size_t chars = m_text.size(); |
| 101 | return (width * chars) * scale + (width * (chars - m_cursorOffset)); |
| 102 | } else { |
| 103 | return context()->stringWidth(m_text) * scale |
| 104 | + context()->stringWidth(m_text.substr(m_cursorOffset, m_text.size())); |
| 105 | } |
| 106 | } else { |
| 107 | throw GuiException("Somehow, the value of m_hAnchor became bad"); |
| 108 | } |
| 109 | |
| 110 | if (m_textHidden) { |
| 111 | int width = context()->stringWidth("*"); |
| 112 | size_t chars = m_text.size(); |
| 113 | return (int)std::ceil((width * chars) * scale - (width * (chars - m_cursorOffset))); |
| 114 | } else { |
| 115 | return (int)std::ceil(context()->stringWidth(m_text) * scale |
| 116 | - context()->stringWidth(m_text.substr(m_cursorOffset, m_text.size()))); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void TextBoxWidget::update(float dt) { |
| 121 | Widget::update(dt); |
nothing calls this directly
no test coverage detected