TextInput Manager - Horizon-NTH/HorizonGUI GitHub Wiki

TextInputManager

Overview

The TextInputManager class, located in the hgui namespace, facilitates the creation and management of text input fields within your graphical application. It enables easy integration of text input functionality with customizable parameters to suit various design needs. The class can be found inside the header file TextInputManager.h.

Member Functions

  • std::shared_ptr<kernel::TextInput> create(const size& size, const point& position, const std::pair<std::shared_ptr<kernel::Font>, color>& text, const std::pair<color, color>& colors = {HGUI_COLOR_WHITE, color("#097fe0")}, const std::pair<std::string, color>& placeHolder = {"placeholder", color("#424242")}, const std::pair<color, std::chrono::milliseconds>& caret = {HGUI_COLOR_BLACK, std::chrono::milliseconds(500)}, const std::tuple<TextInput::Function, TextInput::Function, TextInput::Function>& onChanges = {}, unsigned sizeLimit = 0, const std::map<keys, TextInput::Function>& onActions = {}, HGUI_PRECISION cornerRadius = 100.f, unsigned borderWidth = 5.f): Creates a new text input with the specified parameters.

Note: The onActions parameter allow you to override some of the basic action perform when the text input is focused. If you give a function for an action, the classic action provided by the library will not be performed. The possible list of action is: LEFT, RIGHT, REMOVE, BACKSPACE, ENTER, ESCAPE.

Example Usage

#include <hgui/TextInputManager.hpp>

{ // Example Usage of TextInputManager
    hgui::size inputSize(400, 50);
    hgui::point inputPosition(100, 100);
    std::shared_ptr<hgui::kernel::Font> font = /* initialize font */;
    hgui::color textColor = hgui::color("#FFFFFF");
    hgui::color backgroundColor = hgui::color("#000000");
    std::string placeholderText = "Enter text here";
    hgui::color placeholderColor = hgui::color("#CCCCCC");

    // Create a text input field
    std::shared_ptr<hgui::kernel::TextInput> myInput = hgui::TextInputManager::create(inputSize, inputPosition, {font, textColor}, {backgroundColor, hgui::color("#097fe0")}, {placeholderText, placeholderColor}, {hgui::color("#FFFFFF"), std::chrono::milliseconds(500)});

    // Set callback functions for events
    myInput->setOnChangeCallback([](const std::shared_ptr<hgui::kernel::TextInput>& input) {
        // Handle text change event
    });

    myInput->setOnEnterCallback([](const std::shared_ptr<hgui::kernel::TextInput>& input) {
        // Handle enter key pressed event
    });

    myInput->draw();
    // (Apply text input effects here)
} // Here the destructor of myInput is called

Note: In the "Example Usage" section, we demonstrate how to create a text input field with the TextInputManager class and set callback functions for events.