Skip to content

C++ class: TextInput

Index · Français

Description

Single-line UTF-8 input state.

Qualified name : gaspardos::desktop::TextInput.

Header : bindings/cpp/desktop_gui.hpp. C++98.

When to use it

Manage cursor and text for paths and file names.

Simple program example

#include "desktop_gui.hpp"
#include <cstdio>
#include <cstring>

int main()
{
    gaspardos::desktop::TextInput input("hello");
    input.key('!');
    std::printf("%s\n", input.visible(30, true).c_str());
    return input.value == "hello!" ? 0 : 1;
}

Building from Windows

Save the program above as build/api-examples/TextInput.cpp from the repository root. Create the directory if necessary.

PowerShell — from the repository root:

New-Item -ItemType Directory -Force build/api-examples | Out-Null
& .\build-x64-install\bin\x86_64-gaspardos-gcc.exe -std=gnu1x -O2 -mno-red-zone -c bindings/native/gaspardos_x64_syscall.c -o build/api-examples/syscall.o
if ($LASTEXITCODE -ne 0) { throw "C compilation failed" }
& .\build-x64-install\bin\x86_64-gaspardos-g++.exe -std=c++98 -O2 -Ibindings/cpp build/api-examples/TextInput.cpp build/api-examples/syscall.o bindings/cpp/file_explorer.cpp bindings/cpp/desktop_native.cpp bindings/cpp/desktop_gui.cpp -o build/api-examples/TextInput-x64.elf
if ($LASTEXITCODE -ne 0) { throw "C++ compilation/link failed" }

Run the ELF on GaspardOS, not Windows. The driver supplies CRT and libraries. Prepare the required volumes/services; examples bound their waits and may exit on backpressure rather than retry. Successful compilation does not validate kernel execution.

The headers, implementation files, native wrappers and complete examples are available under Source files.

Class methods

explicit TextInput(const std::string& text = "")

Initialize text and cursor at the end; constructor does not validate or truncate.

void set(const std::string& text)

Copy at most 4095 bytes and move cursor to end; truncation can split UTF-8.

void key(uint32_t key)

UTF-8 editing, arrows 0xF800/1, Home 0xF806, End 0xF807, Backspace/Delete.

std::string visible(unsigned columns, bool focused) const

si focused. Largeur en octets, pas mesure typographique.

Public data

value : std::string ; cursor : std::size_t (byte offset). Conserver un curseur valide / keep a valid cursor.

Native contract

LP64 ABI, 32-bit wchar_t, no packing. Native negative results are not errno. Handle -11 with yield and an application limit. Referenced objects must outlive their users; do not copy handle owners. File uses stdio/errno and invalidates its stream on close, even on error.