cangine
Loading...
Searching...
No Matches
inputfield_component.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <functional>
5
6#include "../textrenderer_component.hpp"
7
8namespace cangine {
9 struct KeyEvent;
10 class QuadRenderer;
11
20 private:
21 float blinkTimer = 0;
24 size_t startIdx;
27
32 void draw(double dt);
33
34 public:
35 int width = 128;
36 int height = 25;
37
38 std::string content;
39 int cursorpos = 0;
40
41 // event
42 std::function<void(std::string)> onReturn = nullptr;
43
44 // style
46 std::string placeholder;
52
55 void firstFrame() override;
56 void frame(double dt) override;
58 void updateView();
63 void inputEventHandler(std::string s);
68 void keyEventHandler(KeyEvent event);
69 void onMouseEvent(const MouseEvent *e) override;
70 };
71}
Editable single-line text input field.
Definition inputfield_component.hpp:19
void onMouseEvent(const MouseEvent *e) override
Called when a mouse event is dispatched to the owning object.
Definition inputfield_component.cpp:249
size_t eventHandlerID
Id of the registered character-event handler.
Definition inputfield_component.hpp:22
void inputEventHandler(std::string s)
Inserts typed characters at the caret.
Definition inputfield_component.cpp:173
float blinkTimer
Accumulator driving the caret blink.
Definition inputfield_component.hpp:21
Color cursorColor
Caret color.
Definition inputfield_component.hpp:50
void updateView()
Recomputes the visible text window from the caret position.
Definition inputfield_component.cpp:155
int height
Field height in pixels.
Definition inputfield_component.hpp:36
float borderWidth
Border thickness in pixels.
Definition inputfield_component.hpp:45
QuadRenderer * qr
Renderer used to draw border/caret.
Definition inputfield_component.hpp:26
~InputFieldComponent()
Definition inputfield_component.cpp:22
Color borderColor
Border color when not focused.
Definition inputfield_component.hpp:48
size_t keyEventHandlerID
Id of the registered key-event handler.
Definition inputfield_component.hpp:23
std::string content
Current text content.
Definition inputfield_component.hpp:38
int width
Field width in pixels.
Definition inputfield_component.hpp:35
void draw(double dt)
Draws the field background, border, text and caret.
Definition inputfield_component.cpp:30
std::function< void(std::string)> onReturn
Called with the content when Enter is pressed.
Definition inputfield_component.hpp:42
void firstFrame() override
Called once before the first frame update.
Definition inputfield_component.cpp:108
size_t startIdx
Index of the first visible character (horizontal scroll).
Definition inputfield_component.hpp:24
Color placeholderColor
Color of the placeholder text.
Definition inputfield_component.hpp:47
static InputFieldComponent * focused
The currently focused field, or nullptr.
Definition inputfield_component.hpp:51
Transform * t
Cached transform of the owning object.
Definition inputfield_component.hpp:25
void frame(double dt) override
Called every frame to update the component.
Definition inputfield_component.cpp:128
std::string placeholder
Text shown when the field is empty.
Definition inputfield_component.hpp:46
void keyEventHandler(KeyEvent event)
Handles editing keys (arrows, backspace, enter, ...).
Definition inputfield_component.cpp:180
InputFieldComponent()
Definition inputfield_component.cpp:12
int cursorpos
Caret position as an index into content.
Definition inputfield_component.hpp:39
Color borderColorFocus
Border color when focused.
Definition inputfield_component.hpp:49
Batched renderer for textured quads (rectangles).
Definition quad_renderer.hpp:33
Component that renders a text string, optionally over a background.
Definition textrenderer_component.hpp:18
Component holding an object's position, rotation and scale.
Definition transform_component.hpp:17
Definition audiomanager.cpp:4
RGBA color stored as normalized floating-point components.
Definition color.hpp:12
A keyboard event: which key and what happened to it.
Definition key.hpp:51
A mouse event carrying its type, button, position and scroll offset.
Definition mouse.hpp:37