uitextbox update

This commit is contained in:
2026-04-22 08:41:29 +02:00
parent a7a7f9f4e9
commit 8be2cea49a
4 changed files with 133 additions and 59 deletions

View File

@@ -33,7 +33,7 @@ namespace Game::Object {
virtual void update(float deltaTime) = 0;
virtual void onWindowResized(int newWidth, int newHeight) {} // Called when the window is resized, with the new width and height in pixels
virtual void destroyed() {}; // Pre-destruction call
void render(Game::Renderer::Renderer* renderer, Game::Renderer::RendererConfig config);
virtual void render(Game::Renderer::Renderer* renderer, Game::Renderer::RendererConfig config);
// Collision calls
// Called once when a collision begins

View File

@@ -4,21 +4,45 @@
#include <renderer/font.hpp>
#include <renderer/texture.hpp>
#include <utility>
#include <string>
#include <game/input.hpp>
#include <SDL3/SDL.h>
namespace Game::Object {
struct UITextboxConfig {
SDL_Color bgColor = {20, 20, 20, 210};
SDL_Color borderColor = {110, 110, 110, 255};
SDL_Color focusedBorderColor = {200, 175, 70, 255};
SDL_Color textColor = {255, 255, 255, 255};
SDL_Color focusedTextColor = {255, 240, 180, 255};
SDL_Color placeholderColor = {120, 120, 120, 200};
float borderThickness = 2.f;
float paddingX = 8.f;
float paddingY = 4.f;
float minWidth = 160.f;
float minHeight = 32.f;
int maxLength = 0; // 0 = unlimited
std::string placeholder = "";
float cursorBlinkRate = 0.53f; // seconds per blink phase
};
class UITextBox : public Entity {
public:
UITextBox(const std::string& name, std::shared_ptr<Renderer::Font> font, const Transform& transform, float x = 0.f, float y = 0.f);
UITextBox(const std::string& name, std::shared_ptr<Renderer::Font> font,
const Transform& transform,
float x = 0.f, float y = 0.f,
UITextboxConfig config = {});
~UITextBox() override = default;
void start() override;
void start() override;
void update(float deltaTime) override;
void render(Game::Renderer::Renderer* renderer, Game::Renderer::RendererConfig config) override;
void setText(const std::string& text);
std::string getText() const;
void setText(const std::string& text);
std::string getText() const;
std::string getValue() const;
bool isFocused() const;
bool isFocused() const;
void setPosition(float x, float y) { mX = x; mY = y; }
std::pair<float, float> getPosition() const { return {mX, mY}; }
@@ -33,5 +57,9 @@ namespace Game::Object {
float mBoxWidth = 0.f;
float mBoxHeight = 0.f;
bool mNeedsTextRefresh = true;
UITextboxConfig mConfig;
float mCursorTimer = 0.f;
bool mCursorVisible = true;
};
}