HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
stencil.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../geometry/axis_aligned_rectangle.hpp"
8
9namespace tt {
10class draw_context;
11class icon;
12class label;
13struct text_style;
14
15class stencil {
16public:
17 stencil(alignment alignment) :
18 _alignment(alignment), _data_is_modified(true), _size_is_modified(true), _position_is_modified(true)
19 {
20 }
21
22 virtual ~stencil() = default;
23 stencil(stencil const &) noexcept = delete;
24 stencil(stencil &&) noexcept = delete;
25 stencil &operator=(stencil const &) noexcept = delete;
26 stencil &operator=(stencil &&) noexcept = delete;
27
30 [[nodiscard]] virtual extent2 preferred_extent() noexcept
31 {
32 return {};
33 }
34
39 virtual void
41 {
42 if (_rectangle.extent() != rectangle.extent()) {
43 _size_is_modified = true;
44 }
45 if (get<0>(_rectangle) != get<0>(rectangle) || _base_line_position != base_line_position) {
46 _position_is_modified = true;
47 }
48
49 _rectangle = rectangle;
50 _base_line_position =
51 base_line_position != std::numeric_limits<float>::infinity() ? base_line_position : rectangle.middle();
52 }
53
59 virtual void draw(draw_context context, tt::color color = tt::color{}, matrix3 transform = geo::identity()) noexcept = 0;
60
61 [[nodiscard]] static std::unique_ptr<class image_stencil> make_unique(alignment alignment, icon const &icon);
62
63 [[nodiscard]] static std::unique_ptr<class text_stencil>
64 make_unique(alignment alignment, std::u8string const &text, text_style const &style);
65
66 [[nodiscard]] static std::unique_ptr<class label_stencil>
67 make_unique(alignment alignment, tt::label const &label, text_style const &style);
68
69protected:
70 alignment _alignment;
71 aarectangle _rectangle;
72 float _base_line_position;
73
76 bool _data_is_modified;
77 bool _size_is_modified;
78 bool _position_is_modified;
79};
80
81} // namespace tt
This is a RGBA floating point color.
Definition color.hpp:39
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:18
extent2 extent() const noexcept
Get size of the rectangle.
Definition axis_aligned_rectangle.hpp:157
Definition identity.hpp:11
Class which represents an rectangle.
Definition rectangle.hpp:16
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:33
An image, in different formats.
Definition icon.hpp:19
A localized text + icon label.
Definition label.hpp:76
Definition stencil.hpp:15
virtual void set_layout_parameters(aarectangle const &rectangle, float base_line_position=std::numeric_limits< float >::infinity()) noexcept
Pass layout parameters in local coordinates.
Definition stencil.hpp:40
virtual extent2 preferred_extent() noexcept
Return the extent that this cell wants to be drawn as.
Definition stencil.hpp:30
virtual void draw(draw_context context, tt::color color=tt::color{}, matrix3 transform=geo::identity()) noexcept=0
Draw the cell.
Definition text_style.hpp:16
T infinity(T... args)