FifeGUI 0.3.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// Corresponding header include
6#include "fifechan/font.hpp"
7
8// Standard library includes
9#include <cassert>
10#include <string>
11
12// Platform config include
13#include "fifechan/platform.hpp"
14
15namespace fcn
16{
17 int Font::getStringIndexAt(std::string const & text, int x) const
18 {
19 assert("x must be non-negative" && x >= 0);
20
21 for (unsigned int i = 0; i < text.size(); ++i) {
22 if (getWidth(text.substr(0, i)) > x) {
23 return i;
24 }
25 }
26 return text.size();
27 }
28} // 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:17
Used replacement tokens by configure_file():