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
precision highp float
Definition common.h:15
local c
Definition gamma.lua:11
Definition audio.cpp:7
std::string str(const static_vector< S > &v)
Definition static_vector_test.cpp:32
local font
Definition repl.lua:1
local function f()) end
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
size_t nlines
Definition text.h:14
std::string str
Definition text.h:13
static size_t count_lines(std::string_view s, size_t cur)
Definition text.cpp:26
static float max_width(const Font::Characters &font, std::string_view s, size_t cur)
Definition text.cpp:33
vec2 size
Definition text.h:16
size_t cur
Definition text.h:14
void update_size(const Font &f)
Definition text.cpp:17
void update_cur(const Font &f, size_t cur)
Definition text.cpp:10
std::chrono::seconds s
Definition timing.cpp:6