mirror of
https://github.com/SikongJueluo/cc-utils.git
synced 2025-11-05 03:37:50 +08:00
reconstruct ccTUI, add Button component
This commit is contained in:
32
src/lib/ccTUI/UIObject.ts
Normal file
32
src/lib/ccTUI/UIObject.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { CCLog } from "../ccLog";
|
||||
|
||||
export abstract class UIObject {
|
||||
readonly objectName: string;
|
||||
private parent?: UIObject;
|
||||
private children: Record<string, UIObject> = {};
|
||||
|
||||
public log?: CCLog;
|
||||
|
||||
constructor(name: string, parent?: UIObject, log?: CCLog) {
|
||||
this.objectName = name;
|
||||
this.parent = parent;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public setParent(parent: UIObject) {
|
||||
this.parent = parent;
|
||||
this.log ??= parent.log;
|
||||
}
|
||||
|
||||
public addChild(child: UIObject) {
|
||||
this.children[child.objectName] = child;
|
||||
}
|
||||
|
||||
public removeChild(child: UIObject) {
|
||||
Object.entries(this.children).forEach(([key, value]) => {
|
||||
if (value === child) {
|
||||
delete this.children[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user