summaryrefslogtreecommitdiff
path: root/Widgets/TextBox.h
blob: 97b0ab1de2bb08d44cffbc94d64f57b34b444708 (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 <AK/Function.h>

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

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

    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 };
};