text.hpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#pragma once


#include <planet/ui/layout.hpp>
#include <planet/ui/layout.column.hpp>
#include <planet/ui/reflowable.hpp>
#include <planet/sdl/texture.hpp>
#include <planet/sdl/ttf.hpp>


namespace planet::sdl::ui {

A block of text

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    class text : public planet::ui::reflowable {
        renderer &r;
        sdl::font &font;
        affine::extents2d space;

        struct word {
            std::string word;
            std::optional<sdl::texture> texture;
        };

        using layout_type =
                planet::ui::layout<std::vector<planet::ui::element<word>>>;
        layout_type elements;


        constrained_type do_reflow(
                reflow_parameters const &,
                constrained_type const &within) override;
        affine::rectangle2d move_sub_elements(
                reflow_parameters const &,
                affine::rectangle2d const &r) override {
            return r;
        }


      public:
        text(renderer &, sdl::font &, std::string_view);

Draw the texture

45
        void draw();

Identify words within a string

49
50
51
52
53
        static std::vector<std::string_view> identify_words(std::string_view);
    };


}