C++ class: Widgets¶
Description¶
Noncopyable manager for at most 32 widgets.
Qualified name : gaspardos::gui::Widgets.
Header : bindings/cpp/widgets.hpp. C++98.
When to use it¶
Build buttons, menus, ASCII fields and labels in an event loop.
Simple program example¶
#include "widgets.hpp"
#include <cstdio>
#include <cstring>
class ConsolePainter : public gaspardos::gui::Painter
{
public:
int64_t fill(int, int, int, int, uint32_t)
{
return 0;
}
int64_t text(int, int, uint32_t, const char* value)
{
std::puts(value);
return 0;
}
};
int main()
{
gaspardos::gui::Widgets widgets(320, 200);
if (widgets.add(gaspardos::gui::Button(1, 10, 10, 120, 26, "OK")) < 0)
return 1;
gaspardos::gui::Event ready = { gaspardos::gui::Ready, 0, 0, 0, 0 };
widgets.event(ready);
ConsolePainter painter;
return widgets.paint(painter) == 0 ? 0 : 1;
}
Building from Windows¶
Save the program above as build/api-examples/Widgets.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-g++.exe -std=c++98 -O2 -Ibindings/cpp build/api-examples/Widgets.cpp -o build/api-examples/Widgets-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¶
Widgets(int width, int height)¶
Surface dimensions, empty and not ready.
int add(const Widget& w)¶
Copy Widget; zero success, -24 capacity, -22 geometry/type/parent, -17 duplicate ID. Add parent menu first.
const char* value(int id) const¶
Internal text pointer for id; null if missing; do not free.
int setText(int id, const char* text)¶
Copy at most 63 bytes; zero or -9 if absent; mark dirty.
int event(const Event& e)¶
ID >0 action, zero none, -1 close, -2 UI error; send Ready before interaction.
bool dirty() const¶
Repaint is required.
int64_t paint(Painter& painter)¶
-11 before Ready; resume at failed command; zero once painting completes or is already clean.