nngn
Loading...
Searching...
No Matches
text.h
Go to the documentation of this file.
1#ifndef NNGN_TEXT_H
2#define NNGN_TEXT_H
3
4#include <string>
5
6#include "math/vec2.h"
7
8#include "font.h"
9
10namespace nngn {
11
12struct Text {
13 std::string str = {};
14 size_t cur = 0, nlines = 0;
15 float spacing = 0;
16 vec2 size = {0, 0};
17 constexpr Text() = default;
18 Text(const Font &f, std::string_view s);
19 Text(const Font &f, std::string_view s, size_t cur);
20 void update_cur(const Font &f, size_t cur);
21 void update_size(const Font &f);
22 static size_t count_lines(std::string_view s, size_t cur);
23 static float max_width(
24 const Font::Characters &font, std::string_view s, size_t cur);
25};
26
27inline Text::Text(const Font &f, std::string_view s)
28 : Text(f, s, s.size()) {}
29inline Text::Text(const Font &f, std::string_view s, size_t c)
30 : str(s), spacing(static_cast<float>(f.size) / 4.0f)
31 { this->update_cur(f, c); }
32
33}
34
35#endif
c
Definition: gamma.lua:11
font
Definition: repl.lua:1
precision highp float
Definition: common.h:15
function f()) end
std::chrono::seconds s
Definition: timing.cpp:6
Definition: audio.cpp:7
vec2_base< float > vec2
Definition: vec2.h:29
std::string str(const static_vector< S > &v)
Definition: static_vector_test.cpp:32
Definition: font.h:18
std::array< Character, N > Characters
Definition: font.h:25
Definition: text.h:12
constexpr Text()=default
float spacing
Definition: text.h:15
Text(const Font &f, std::string_view s)
size_t nlines
Definition: text.h:14
std::string str
Definition: text.h:13
Text(const Font &f, std::string_view s, size_t cur)
vec2 size
Definition: text.h:16
static size_t count_lines(std::string_view s, size_t cur)
size_t cur
Definition: text.h:14
void update_size(const Font &f)
static float max_width(const Font::Characters &font, std::string_view s, size_t cur)
void update_cur(const Font &f, size_t cur)