reconstruct ccTUI, add Button component

This commit is contained in:
2025-10-10 21:43:24 +08:00
parent 61baedb606
commit 8e95fe8ad1
14 changed files with 1292 additions and 1162 deletions

28
src/lib/ccTUI/Signal.ts Normal file
View File

@@ -0,0 +1,28 @@
/**
* Signal and Slot system similar to Qt
* Allows components to communicate with each other
*/
export class Signal<T = void> {
private slots: ((data?: T) => void)[] = [];
connect(slot: (data?: T) => void): void {
this.slots.push(slot);
}
disconnect(slot: (data?: T) => void): void {
const index = this.slots.indexOf(slot);
if (index !== -1) {
this.slots.splice(index, 1);
}
}
emit(data?: T): void {
for (const slot of this.slots) {
try {
slot(data);
} catch (e) {
printError(e);
}
}
}
}