HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
LineInputWidget.hpp
1// Copyright 2019, 2020 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include "TTauri/Widgets/Widget.hpp"
7#include "TTauri/Text/EditableText.hpp"
8#include <memory>
9#include <string>
10#include <array>
11#include <optional>
12#include <future>
13
14namespace tt {
15
16class LineInputWidget : public Widget {
17protected:
18 std::string label = "<unknown>";
19
20 EditableText field;
21 ShapedText shapedText;
22 aarect textRectangle = {};
23 aarect textClippingRectangle = {};
24 aarect leftToRightCaret = {};
25 aarect partialGraphemeCaret = {};
26 std::vector<aarect> selectionRectangles = {};
27
31 float dragScrollSpeedX = 0.0f;
32
35 int dragClickCount = 0;
36
37 vec dragSelectPosition = {};
38
41 float textScrollX = 0.0f;
42
43 mat::T2 textTranslate;
44 mat::T2 textInvTranslate;
45
46 static constexpr hires_utc_clock::duration blinkInterval = 500ms;
47 hires_utc_clock::time_point nextRedrawTimePoint;
48 hires_utc_clock::time_point lastUpdateTimePoint;
49public:
50
52 Window &window, Widget *parent,
53 std::string const label
54 ) noexcept;
55
57
58 LineInputWidget(const LineInputWidget &) = delete;
59 LineInputWidget &operator=(const LineInputWidget &) = delete;
61 LineInputWidget &operator=(LineInputWidget &&) = delete;
62
63 [[nodiscard]] int needs(hires_utc_clock::time_point displayTimePoint) noexcept override;
64 void layout(hires_utc_clock::time_point displayTimePoint) noexcept override;
65 void draw(DrawContext const &drawContext, hires_utc_clock::time_point displayTimePoint) noexcept override;
66
67 void handleCommand(string_ltag command) noexcept override;
68
69 void handleMouseEvent(MouseEvent const &event) noexcept override;
70 void handleKeyboardEvent(KeyboardEvent const &event) noexcept override;
71 [[nodiscard]] HitBox hitBoxTest(vec position) const noexcept override;
72
73 [[nodiscard]] bool acceptsFocus() const noexcept override {
74 return *enabled;
75 }
76
77private:
78 void dragSelect() noexcept;
79};
80
81}
Class which represents an axis-aligned rectangle.
Definition aarect.hpp:13
Optimized 2D translate matrix.
Definition mat.hpp:184
A 4D vector.
Definition vec.hpp:37
Draw context for drawing using the TTauri shaders.
Definition DrawContext.hpp:30
Definition HitBox.hpp:12
Definition KeyboardEvent.hpp:37
Definition MouseEvent.hpp:12
Definition Window_vulkan_win32.hpp:15
Definition EditableText.hpp:14
ShapedText represent a piece of text shaped to be displayed.
Definition ShapedText.hpp:21
Definition LineInputWidget.hpp:16
HitBox hitBoxTest(vec position) const noexcept override
Find the widget that is under the mouse cursor.
int needs(hires_utc_clock::time_point displayTimePoint) noexcept override
Request the needs of the widget.
void handleKeyboardEvent(KeyboardEvent const &event) noexcept override
void handleMouseEvent(MouseEvent const &event) noexcept override
bool acceptsFocus() const noexcept override
Check if the widget will accept keyboard focus.
Definition LineInputWidget.hpp:73
void draw(DrawContext const &drawContext, hires_utc_clock::time_point displayTimePoint) noexcept override
Draw widget.
void handleCommand(string_ltag command) noexcept override
Handle command.
void layout(hires_utc_clock::time_point displayTimePoint) noexcept override
Layout the widget.
Definition Widget.hpp:64
observable< bool > enabled
The widget is enabled.
Definition Widget.hpp:150