tengri/Content/Toasts/UI/WBP_ToastContainer.ts

62 lines
1.8 KiB
TypeScript

// Content/Toasts/UI/WBP_ToastContainer.ts
import {VerticalBox, Widget} from "../../classes.js";
import {ESlateVisibility} from "../../enums.js";
import type {Text} from "../../types.js";
import type {E_MessageType} from "../Enums/E_MessageType.js";
import {WBP_Toast} from "./WBP_Toast.js";
import {AddToArray, CreateWidget, IsValid, RemoveItemFromArray} from "../../functions.js";
export class WBP_ToastContainer extends Widget {
// Category: "Layout"
/**
* Vertical box container for automatic toast stacking
* Handles spacing and positioning automatically
*/
private ToastVerticalBox = new VerticalBox();
// Category: "Container Management"
/**
* Array of child toast widgets for management
*/
private ChildToasts: WBP_Toast[] = [];
// Category: "Container Setup"
/**
* Initialize toast container
* Sets up vertical box with proper spacing
*/
public InitializeContainer(): void {
this.SetVisibility(ESlateVisibility.Visible);
this.AddToViewport();
}
// Category: "Toast Management"
/**
* Add new toast to container
* @param Message - Toast message
* @param Type - Toast type
* @returns Created toast widget reference
*/
public AddToast(Message: Text, Type: E_MessageType): WBP_Toast {
const toast = CreateWidget(new WBP_Toast());
toast.InitializeToast(Message, Type);
this.ToastVerticalBox.AddChild(toast);
AddToArray(this.ChildToasts, toast);
return toast;
}
// Category: "Toast Management"
/**
* Remove toast from container
* @param Toast - Toast widget to remove
*/
public RemoveToast(Toast: WBP_Toast): void {
if (IsValid(Toast)) {
RemoveItemFromArray(this.ChildToasts, Toast);
Toast.SetVisibility(ESlateVisibility.Hidden);
Toast.RemoveFromParent();
}
}
}