HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
text_widget.hpp
1// Copyright Take Vos 2021.
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 "widget.hpp"
8#include "../GFX/draw_context.hpp"
9#include "../GUI/theme_text_style.hpp"
10#include "../text/shaped_text.hpp"
11#include "../observable.hpp"
12#include "../alignment.hpp"
13#include "../l10n.hpp"
14#include <memory>
15#include <string>
16#include <array>
17#include <optional>
18#include <future>
19
20namespace tt {
21
25class text_widget final : public widget {
26public:
27 using super = widget;
28
32
35 observable<alignment> alignment = alignment::middle_center;
36
39 observable<theme_text_style> text_style = theme_text_style::label;
40
49 template<typename Text, typename Alignment = tt::alignment, typename TextStyle = tt::theme_text_style>
53 Text &&text,
54 Alignment &&alignment = alignment::middle_center,
55 TextStyle &&text_style = theme_text_style::label) noexcept :
57 {
58 this->text = std::forward<Text>(text);
59 this->alignment = std::forward<Alignment>(alignment);
60 this->text_style = std::forward<TextStyle>(text_style);
61 }
62
64 void init() noexcept override;
65 [[nodiscard]] bool constrain(utc_nanoseconds display_time_point, bool need_reconstrain) noexcept override;
66 [[nodiscard]] void layout(utc_nanoseconds displayTimePoint, bool need_layout) noexcept override;
67 void draw(draw_context context, utc_nanoseconds display_time_point) noexcept override;
69private:
70 decltype(text)::callback_ptr_type _text_callback;
71
72 shaped_text _shaped_text;
73 matrix2 _shaped_text_transform;
74
76};
77
78} // namespace tt
alignment
Vertical and horizontal alignment.
Definition alignment.hpp:47
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:28
Definition gui_window.hpp:39
A value which can be observed for modifications.
Definition observable.hpp:464
shaped_text represent a piece of text shaped to be displayed.
Definition shaped_text.hpp:23
Definition text_style.hpp:17
A text widget.
Definition text_widget.hpp:25
text_widget(gui_window &window, widget *parent, Text &&text, Alignment &&alignment=alignment::middle_center, TextStyle &&text_style=theme_text_style::label) noexcept
Construct a text widget.
Definition text_widget.hpp:50
observable< l10n > text
The text to be displayed.
Definition text_widget.hpp:31
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:46
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:41
widget(gui_window &window, widget *parent) noexcept