Add tab renderer panel

This commit is contained in:
MrKBear 2022-03-02 21:02:54 +08:00
parent 19d77dceb0
commit 6f8451ea9b
10 changed files with 95 additions and 11 deletions

View File

@ -94,16 +94,24 @@ div.app-container {
} }
} }
div.app-panel.has-padding {
padding: 10px;
}
div.app-panel { div.app-panel {
width: 100%; width: 100%;
height: 100%; height: 100%;
box-sizing: border-box; box-sizing: border-box;
padding: 10px;
overflow: scroll; overflow: scroll;
-ms-overflow-style: none; -ms-overflow-style: none;
border: .8px solid rgba($color: #000000, $alpha: 0); border: .8px solid rgba($color: #000000, $alpha: 0);
} }
div.app-panel.hide-scrollbar::-webkit-scrollbar {
width : 0; /*高宽分别对应横竖滚动条的尺寸*/
height: 0;
}
div.app-panel::-webkit-scrollbar { div.app-panel::-webkit-scrollbar {
width : 8px; /*高宽分别对应横竖滚动条的尺寸*/ width : 8px; /*高宽分别对应横竖滚动条的尺寸*/
height: 0; height: 0;

View File

@ -39,6 +39,7 @@ class Container extends Component<IContainerProps> {
const classList: string[] = []; const classList: string[] = [];
const theme: Themes = this.props.theme ?? Themes.dark; const theme: Themes = this.props.theme ?? Themes.dark;
const showPanelId = focus ?? panles[0]; const showPanelId = focus ?? panles[0];
const showPanelInfo = getPanelInfoById(showPanelId as any);
classList.push(theme === Themes.light ? "light" : "dark"); classList.push(theme === Themes.light ? "light" : "dark");
classList.push(`background-${BackgroundLevel.Level3}`); classList.push(`background-${BackgroundLevel.Level3}`);
@ -57,7 +58,7 @@ class Container extends Component<IContainerProps> {
const classList: string[] = ["app-tab-header-item"]; const classList: string[] = ["app-tab-header-item"];
if (panelId === this.props.focusId) classList.push("active"); if (panelId === this.props.focusId) classList.push("active");
if (panelId === showPanelId) classList.push("tab"); if (panelId === showPanelId) classList.push("tab");
const panelInfo = getPanelInfoById(showPanelId as any); const panelInfo = getPanelInfoById(panelId as any);
return <LocalizationTooltipHost return <LocalizationTooltipHost
i18nKey={panelInfo ? panelInfo.introKay as any : "Panel.Info.Notfound"} i18nKey={panelInfo ? panelInfo.introKay as any : "Panel.Info.Notfound"}
@ -89,7 +90,12 @@ class Container extends Component<IContainerProps> {
} }
<div <div
onClick={() => this.props.onFocusTab ? this.props.onFocusTab(showPanelId) : undefined} onClick={() => this.props.onFocusTab ? this.props.onFocusTab(showPanelId) : undefined}
className={"app-panel" + (hasActivePanel ? " active" : "")} className={[
"app-panel",
hasActivePanel ? "active" : "",
showPanelInfo?.hidePadding ? "" : "has-padding",
showPanelInfo?.hideScrollBar ? "hide-scrollbar" : ""
].filter(x => !!x).join(" ")}
draggable={false} draggable={false}
> >
{getPanelById(showPanelId as any)} {getPanelById(showPanelId as any)}

View File

@ -20,6 +20,10 @@ abstract class BasicRenderer<
E extends Record<EventType, any> = {} E extends Record<EventType, any> = {}
> extends AbstractRenderer<P, M & IRendererParams, E & {loop: number}> { > extends AbstractRenderer<P, M & IRendererParams, E & {loop: number}> {
public get dom() {
return this.canvas.dom
}
/** /**
* *
*/ */

View File

@ -21,6 +21,8 @@ const EN_US = {
"Command.Bar.Setting.Info": "Global Settings", "Command.Bar.Setting.Info": "Global Settings",
"Panel.Title.Notfound": "{id}", "Panel.Title.Notfound": "{id}",
"Panel.Info.Notfound": "This panel with id {id} can not found!", "Panel.Info.Notfound": "This panel with id {id} can not found!",
"Panel.Title.Render.View": "Live preview",
"Panel.Info.Render.View": "Live simulation results preview",
} }
export default EN_US; export default EN_US;

View File

@ -21,5 +21,7 @@ const ZH_CN = {
"Command.Bar.Setting.Info": "全局设置", "Command.Bar.Setting.Info": "全局设置",
"Panel.Title.Notfound": "找不到面板: {id}", "Panel.Title.Notfound": "找不到面板: {id}",
"Panel.Info.Notfound": "这个编号为 {id} 的面板无法找到!", "Panel.Info.Notfound": "这个编号为 {id} 的面板无法找到!",
"Panel.Title.Render.View": "实时预览",
"Panel.Info.Render.View": "实时仿真结果预览",
} }
export default ZH_CN; export default ZH_CN;

View File

@ -67,6 +67,8 @@ abstract class AbstractRenderer<
E extends AbstractRendererEvent = {loop: number} E extends AbstractRendererEvent = {loop: number}
> extends Emitter<E> { > extends Emitter<E> {
abstract dom: HTMLDivElement | HTMLCanvasElement;
/** /**
* *
*/ */

View File

@ -60,7 +60,7 @@ class SimulatorWeb extends Component {
items: [ items: [
{ {
items: [ items: [
{panles: ["Label A", "Label Aa Bb", "Label aaa"]}, {panles: ["RenderView", "Label Aa Bb", "Label aaa"]},
{ {
items: [{panles: ["Label b", "Label bbb"]}, {panles: ["C"]}], items: [{panles: ["Label b", "Label bbb"]}, {panles: ["C"]}],
scale: 80, scale: 80,

View File

@ -1,10 +1,14 @@
import { ReactNode } from "react"; import { ReactNode, Component, FunctionComponent } from "react";
import { Theme } from "@Component/Theme/Theme"; import { Theme } from "@Component/Theme/Theme";
import { Localization } from "@Component/Localization/Localization"; import { Localization } from "@Component/Localization/Localization";
import { RenderView } from "./RenderView/RenderView";
interface IPanelInfo { interface IPanelInfo {
nameKey: string; nameKey: string;
introKay: string; introKay: string;
class: (new (...p: any) => Component) | FunctionComponent;
hidePadding?: boolean;
hideScrollBar?: boolean;
option?: Record<string, string>; option?: Record<string, string>;
} }
@ -13,15 +17,24 @@ type PanelId = ""
; ;
const PanelInfoMap = new Map<PanelId, IPanelInfo>(); const PanelInfoMap = new Map<PanelId, IPanelInfo>();
PanelInfoMap.set("RenderView", { nameKey: "", introKay: "" }); PanelInfoMap.set("RenderView", {
nameKey: "Panel.Title.Render.View", introKay: "Panel.Info.Render.View", class: RenderView, hidePadding: true, hideScrollBar: true
});
function getPanelById(panelId: PanelId): ReactNode { function getPanelById(panelId: PanelId): ReactNode {
return <Theme> switch (panelId) {
default:
let info = PanelInfoMap.get(panelId);
if (info) {
const C = info.class;
return <C></C>
} else return <Theme>
<Localization i18nKey={"Panel.Info.Notfound"} options={{ <Localization i18nKey={"Panel.Info.Notfound"} options={{
id: panelId id: panelId
}}/> }}/>
</Theme> </Theme>
} }
}
function getPanelInfoById(panelId: PanelId): IPanelInfo | undefined { function getPanelInfoById(panelId: PanelId): IPanelInfo | undefined {
return PanelInfoMap.get(panelId); return PanelInfoMap.get(panelId);

View File

@ -0,0 +1,9 @@
div.render-view {
width: 100%;
height: 100%;
div.canvas {
width: 100%;
height: 100%;
}
}

View File

@ -0,0 +1,38 @@
import { Component, ReactNode, createRef } from "react";
import { useStatus, IMixinStatusProps } from "@Context/Status";
import { useSetting, IMixinSettingProps, Themes } from "@Context/Setting";
import { ClassicRenderer } from "@GLRender/ClassicRenderer";
import "./RenderView.scss";
@useSetting
@useStatus
class RenderView extends Component<IMixinStatusProps & IMixinSettingProps> {
private rootEle = createRef<HTMLDivElement>();
public render(): ReactNode {
const theme = this.props.setting?.themes ?? Themes.dark;
const classList: string[] = ["render-view", "background-lvl5"];
if (theme === Themes.light) classList.push("light");
if (theme === Themes.dark) classList.push("dark");
if (this.props.status) {
(this.props.status.renderer as ClassicRenderer).cleanColor =
(theme === Themes.dark) ?
[27 / 255, 26 / 255, 25 / 255, 1] :
[190 / 255, 187 / 255, 184 / 255, 1]
}
return <div ref={this.rootEle} className={classList.join(" ")}/>;
}
public componentDidMount() {
let div = this.rootEle.current;
console.log(div, div?.childNodes, this.props.status, this.props.status?.renderer.dom)
if (div && (!div.childNodes || div.childNodes.length <= 0) && this.props.status) {
div.appendChild(this.props.status.renderer.dom);
}
}
}
export { RenderView }