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 "../aarect.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 f32x4 preferred_extent() noexcept
31 {
32 return {};
33 }
34
39 virtual void
40 set_layout_parameters(aarect const &rectangle, float base_line_position = std::numeric_limits<float>::infinity()) noexcept
41 {
42 if (_rectangle.extent() != rectangle.extent()) {
43 _size_is_modified = true;
44 }
45 if (_rectangle.offset() != rectangle.offset() || _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, bool use_context_color = false) 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 aarect _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
STL namespace.
numeric_array< T, 4 > offset() const noexcept
Get vector from origin to the bottom-left corner.
Definition aarect.hpp:216
T middle() const noexcept
The middle on the y-axis between bottom and top.
Definition aarect.hpp:272
numeric_array< T, 4 > extent() const noexcept
Get size of the rectangle.
Definition aarect.hpp:225
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 image_stencil.hpp:11
Definition label_stencil.hpp:17
Definition stencil.hpp:15
virtual void draw(draw_context context, bool use_context_color=false) noexcept=0
Draw the cell.
virtual f32x4 preferred_extent() noexcept
Return the extent that this cell wants to be drawn as.
Definition stencil.hpp:30
virtual void set_layout_parameters(aarect const &rectangle, float base_line_position=std::numeric_limits< float >::infinity()) noexcept
Pass layout parameters in local coordinates.
Definition stencil.hpp:40
Definition text_stencil.hpp:14
Definition text_style.hpp:16
T infinity(T... args)