HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
label_widget.hpp
1// Copyright Take Vos 2020-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 "text_widget.hpp"
9#include "icon_widget.hpp"
10#include "../alignment.hpp"
11#include "../label.hpp"
12#include <memory>
13#include <string>
14#include <array>
15#include <optional>
16#include <future>
17
18namespace tt {
19
32class label_widget final : public widget {
33public:
34 using super = widget;
35
39
58 observable<alignment> alignment = alignment::middle_right;
59
62 observable<theme_text_style> text_style = theme_text_style::label;
63
77 template<typename Label, typename Alignment = tt::alignment, typename TextStyle = tt::theme_text_style>
81 Label &&label,
82 Alignment &&alignment = alignment::middle_right,
83 TextStyle &&text_style = theme_text_style::label) noexcept :
85 {
86 this->label = std::forward<Label>(label);
87 this->alignment = std::forward<Alignment>(alignment);
88 this->text_style = std::forward<TextStyle>(text_style);
89 }
90
92 void init() noexcept override;
93 [[nodiscard]] bool constrain(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept override;
94 [[nodiscard]] void layout(hires_utc_clock::time_point displayTimePoint, bool need_layout) noexcept override;
96private:
97 float _icon_size;
98 float _inner_margin;
99
100 decltype(label)::callback_ptr_type _label_callback;
101
102 icon_widget *_icon_widget = nullptr;
103 text_widget *_text_widget = nullptr;
104
106};
107
108} // namespace tt
alignment
Vertical and horizontal alignment.
Definition alignment.hpp:47
Definition gui_window.hpp:36
Timestamp.
Definition hires_utc_clock.hpp:19
A label consisting of localizable text and an icon.
Definition label.hpp:27
An observable value.
Definition observable.hpp:280
Definition text_style.hpp:16
An simple GUI widget that displays an icon.
Definition icon_widget.hpp:26
The GUI widget displays and lays out text together with an icon.
Definition label_widget.hpp:32
label_widget(gui_window &window, widget *parent, Label &&label, Alignment &&alignment=alignment::middle_right, TextStyle &&text_style=theme_text_style::label) noexcept
Construct a label widget.
Definition label_widget.hpp:78
observable< label > label
The label to display.
Definition label_widget.hpp:38
A text widget.
Definition text_widget.hpp:25
An interactive graphical object as part of the user-interface.
Definition widget.hpp:39
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:48
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:43
widget(gui_window &window, widget *parent) noexcept