1 #include <cppurses/widget/widgets/matrix_display.hpp>
2 
3 #include <cstddef>
4 
5 #include <cppurses/painter/painter.hpp>
6 
7 namespace cppurses {
8 
Matrix_display(Glyph_matrix matrix_)9 Matrix_display::Matrix_display(Glyph_matrix matrix_)
10     : matrix{std::move(matrix_)} {
11     this->set_name("Matrix_display");
12 }
13 
Matrix_display(std::size_t width,std::size_t height)14 Matrix_display::Matrix_display(std::size_t width, std::size_t height)
15     : matrix{width, height} {
16     this->set_name("Matrix_display");
17 }
18 
paint_event()19 bool Matrix_display::paint_event() {
20     std::size_t w{matrix.width() > this->width() ? this->width()
21                                                  : matrix.width()};
22     std::size_t h{matrix.height() > this->height() ? this->height()
23                                                    : matrix.height()};
24     Painter p{*this};
25     for (std::size_t y{0}; y < h; ++y) {
26         for (std::size_t x{0}; x < w; ++x) {
27             p.put(matrix(x, y), x, y);
28         }
29     }
30     return Widget::paint_event();
31 }
32 
33 }  // namespace cppurses
34