Files
bim_engine/src/managers/toolbar-manager.ts

161 lines
4.0 KiB
TypeScript
Raw Normal View History

/**
*
*
*/
import type { ButtonGroupColors, ButtonConfig } from '../components/button-group/index.type';
import { Toolbar } from '../components/button-group/toolbar';
import type { ThemeConfig } from '../themes/types';
import { BaseManager } from '../core/base-manager';
/**
*
* /
*/
export class ToolbarManager extends BaseManager {
/** 工具栏实例 */
private toolbar: Toolbar | null = null;
/** 工具栏容器元素 */
private toolbarContainer: HTMLElement | null = null;
/** 主容器元素 */
private container: HTMLElement;
constructor(container: HTMLElement) {
super();
this.container = container;
this.init();
}
/** 初始化工具栏 */
private init() {
this.toolbarContainer = document.createElement('div');
this.toolbarContainer.id = 'opt-btn-groups';
this.toolbarContainer.className = 'bim-engine-opt-btn-container is-bottom-toolbar';
this.container.appendChild(this.toolbarContainer);
this.toolbar = new Toolbar({
container: this.toolbarContainer,
type: 'glass-pill',
showLabel: true,
direction: 'row',
position: 'bottom-right',
align: 'vertical',
expand: 'up'
});
this.toolbar.init();
}
/**
*
* @param theme
*/
public updateTheme(theme: ThemeConfig) {
this.toolbar?.setTheme(theme);
}
/** 刷新工具栏渲染 */
public refresh() {
this.toolbar?.render();
}
/** 销毁工具栏 */
public destroy() {
this.toolbar?.destroy();
this.toolbar = null;
super.destroy();
}
/**
*
* @param groupId ID
* @param beforeGroupId
*/
public addGroup(groupId: string, beforeGroupId?: string) {
this.toolbar?.addGroup(groupId, beforeGroupId);
this.toolbar?.render();
}
/**
*
* @param config
*/
public addButton(config: ButtonConfig) {
this.toolbar?.addButton(config);
this.toolbar?.render();
}
/**
*
* @param id ID
* @param v
*/
public setButtonVisibility(id: string, v: boolean) {
this.toolbar?.updateButtonVisibility(id, v);
}
/**
*
* @param show
*/
public setShowLabel(show: boolean) {
this.toolbar?.setShowLabel(show);
}
/**
*
* @param id ID
* @param active
*/
public setBtnActive(id: string, active?: boolean) {
this.toolbar?.setBtnActive(id, active);
}
/**
*
* @param visible
*/
public setVisible(visible: boolean) {
if (this.toolbarContainer) {
this.toolbarContainer.style.visibility = visible ? 'visible' : 'hidden';
}
}
2025-12-25 15:47:57 +08:00
/**
*
* @param color
*/
public setBackgroundColor(color: string) {
this.toolbar?.setBackgroundColor(color);
}
/**
*
* @param colors
2025-12-25 15:47:57 +08:00
*/
public setColors(colors: ButtonGroupColors) {
this.toolbar?.setColors(colors);
}
/** 隐藏工具栏 */
2025-12-25 15:47:57 +08:00
public hide(): void {
if (this.toolbarContainer) {
this.toolbarContainer.style.display = 'none';
}
}
/** 显示工具栏 */
2025-12-25 15:47:57 +08:00
public show(): void {
if (this.toolbarContainer) {
this.toolbarContainer.style.display = '';
}
}
/**
*
* @returns
2025-12-25 15:47:57 +08:00
*/
public getContainer(): HTMLElement | null {
return this.toolbarContainer;
}
}