sandbox
Loading...
Searching...
No Matches
font.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_UI_FONT_HPP_
3#define LIBSBX_UI_FONT_HPP_
4
5#include <string>
6#include <fstream>
7#include <filesystem>
8#include <unordered_map>
9
10#include <nlohmann/json.hpp>
11
12#include <libsbx/memory/observer_ptr.hpp>
13
14#include <libsbx/math/vector2.hpp>
15
16#include <libsbx/graphics/images/image2d.hpp>
17
18namespace sbx::ui {
19
20struct glyph {
21 std::float_t advance{0.0f};
22
23 std::float_t plane_left{0.0f};
24 std::float_t plane_bottom{0.0f};
25 std::float_t plane_right{0.0f};
26 std::float_t plane_top{0.0f};
27
28 std::float_t uv_left{0.0f};
29 std::float_t uv_bottom{0.0f};
30 std::float_t uv_right{0.0f};
31 std::float_t uv_top{0.0f};
32}; // struct glyph
33
34struct font {
36 std::float_t atlas_width{0.0f};
37 std::float_t atlas_height{0.0f};
38 std::float_t line_height{1.0f};
39 std::float_t sdf_px_range{2.0f};
40 std::unordered_map<std::uint32_t, glyph> glyphs;
41
42 [[nodiscard]] auto find_glyph(std::uint32_t codepoint) const -> memory::observer_ptr<const glyph>;
43
44}; // struct font
45
46[[nodiscard]] auto load_font(graphics::image2d_handle atlas, const std::filesystem::path& json_path) -> font;
47
48} // namespace sbx::ui
49
50#endif // LIBSBX_UI_FONT_HPP_
Definition: resource_storage.hpp:18
A non-owning pointer that can be used to observe the value of a pointer.
Definition: observer_ptr.hpp:29
Definition: font.hpp:34
Definition: font.hpp:20