FifeGUI 0.2.0
A C++ GUI library designed for games.
font.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#include "fifechan/font.hpp"
6
7#include <string>
8
9namespace fcn
10{
11 int Font::getStringIndexAt(std::string const & text, int x) const
12 {
13 for (unsigned int i = 0; i < text.size(); ++i) {
14 if (getWidth(text.substr(0, i)) > x) {
15 return i;
16 }
17 }
18 return text.size();
19 }
20} // namespace fcn
virtual int getWidth(std::string const &text) const =0
Gets the width of a string.
virtual int getStringIndexAt(std::string const &text, int x) const
Gets a string index in a string providing an x coordinate.
Definition font.cpp:11