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 hi::inline v1 {
19
32class label_widget final : public widget {
33public:
34 using super = widget;
35
39
58 observable<alignment> alignment = hi::alignment::top_right();
59
62 observable<semantic_text_style> text_style = semantic_text_style::label;
63
77 template<typename Label, typename Alignment = hi::alignment, typename TextStyle = hi::semantic_text_style>
79 gui_window &window,
80 widget *parent,
81 Label &&label,
82 Alignment &&alignment = hi::alignment::top_right(),
83 TextStyle &&text_style = semantic_text_style::label) noexcept :
84 label_widget(window, parent)
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 [[nodiscard]] generator<widget *> children() const noexcept override
93 {
94 co_yield _icon_widget.get();
95 co_yield _text_widget.get();
96 }
97
98 widget_constraints const &set_constraints() noexcept override;
99 void set_layout(widget_layout const &layout) noexcept override;
100 void draw(draw_context const &context) noexcept;
101 [[nodiscard]] hitbox hitbox_test(point3 position) const noexcept;
103private:
104 float _icon_size;
105 float _inner_margin;
106
107 decltype(label)::token_type _label_cbt;
108 decltype(text_style)::token_type _text_style_cbt;
109
110 aarectangle _icon_rectangle;
111 widget_constraints _icon_constraints;
112 std::unique_ptr<icon_widget> _icon_widget;
113 aarectangle _text_rectangle;
114 widget_constraints _text_constraints;
115 std::unique_ptr<text_widget> _text_widget;
116
117 label_widget(gui_window &window, widget *parent) noexcept;
118};
119
120} // namespace hi::inline v1
STL namespace.
Definition alignment.hpp:64
A return value for a generator-function.
Definition generator.hpp:28
Definition gui_window.hpp:39
A label consisting of localizable text and an icon.
Definition label.hpp:27
An observable value.
Definition observable.hpp:359
Definition text_style.hpp:175
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=hi::alignment::top_right(), TextStyle &&text_style=semantic_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
An interactive graphical object as part of the user-interface.
Definition widget.hpp:39