summaryrefslogtreecommitdiff
path: root/LibGUI/GTextBox.h
blob: ad9c8dd5f82ea982022dc60ad2a30b4ab4ea38fa (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
29
30
31
#pragma once

#include "GWidget.h"
#include <AK/Function.h>

class GTextBox final : public GWidget {
public:
    explicit GTextBox(GWidget* parent);
    virtual ~GTextBox() override;

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

    Function<void(GTextBox&)> on_return_pressed;
    Function<void(GTextBox&)> on_change;

private:
    virtual const char* class_name() const override { return "GTextBox"; }
    virtual void paint_event(GPaintEvent&) override;
    virtual void mousedown_event(GMouseEvent&) override;
    virtual void keydown_event(GKeyEvent&) override;
    virtual void timer_event(GTimerEvent&) override;
    virtual bool accepts_focus() const override { return true; }

    void handle_backspace();

    String m_text;
    unsigned m_cursor_position { 0 };
    bool m_cursor_blink_state { false };
};