MCPcopy Create free account
hub / github.com/VitalAudio/visage / positionToIndex

Method positionToIndex

visage_widgets/text_editor.cpp:249–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247 }
248
249 int TextEditor::positionToIndex(const std::pair<float, float>& position) const {
250 float line_height = font().lineHeight();
251 int line = std::min<int>(line_breaks_.size(), (position.second - yMargin()) / line_height);
252 std::pair<int, int> range = lineRange(line);
253
254 float full_width = font().stringWidth(text_.text().c_str() + range.first,
255 range.second - range.first, text_.characterOverride());
256
257 float line_x = (width() - full_width) * 0.5f;
258 float x_margin = xMargin();
259 if (justification() & Font::kLeft)
260 line_x = x_margin;
261 else if (justification() & Font::kRight)
262 line_x = width() - x_margin - full_width;
263
264 int index = font().widthOverflowIndex(text_.text().c_str() + range.first, range.second - range.first,
265 position.first - line_x, true, text_.characterOverride());
266 return std::min(range.first + index, range.second);
267 }
268
269 bool TextEditor::enterPressed() {
270 if (!active_)

Callers

nothing calls this directly

Calls 8

widthFunction · 0.85
stringWidthMethod · 0.80
c_strMethod · 0.80
textMethod · 0.80
characterOverrideMethod · 0.80
widthOverflowIndexMethod · 0.80
lineHeightMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected