summaryrefslogtreecommitdiff
path: root/Widgets/TextBox.h
blob: 626ea6d8df6a1c647670876d28f481722a4aa7dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once

#include "Widget.h"
#include <functional>

class TextBox final : public Widget {
public:
    explicit TextBox(Widget* parent = nullptr);
    virtual ~TextBox() override;

    String text() const { return m_text; }
    void setText(String&&);

    std::function<void(TextBox&)> onReturnPressed;

private:
    virtual void paintEvent(PaintEvent&) override;
    virtual void mouseDownEvent(MouseEvent&) override;
    virtual void keyDownEvent(KeyEvent&) override;
    virtual void timerEvent(TimerEvent&) override;

    void handleBackspace();

    String m_text;
    unsigned m_cursorPosition { 0 };
    bool m_cursorBlinkState { false };
};