Skip to content

Commit

Permalink
Add ability to preserve tab states
Browse files Browse the repository at this point in the history
  • Loading branch information
nahkd123 committed Oct 4, 2024
1 parent 515b18e commit 5f8f182
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
28 changes: 19 additions & 9 deletions nahara-motion-ui/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
<script lang="ts">
import Button from "./ui/input/Button.svelte";
import MediaBar from "./ui/bar/MediaBar.svelte";
import TopBar from "./ui/bar/TopBar.svelte";
import MenuHost from "./ui/menu/MenuHost.svelte";
import OutlinerPane from "./ui/outliner/OutlinerPane.svelte";
import PaneHost, { SplitDirection, type PaneLayout } from "./ui/pane/PaneHost.svelte";
import PaneHost, { SplitDirection, type PaneLayout, type TabState } from "./ui/pane/PaneHost.svelte";
import PropertiesPane from "./ui/properties/PropertiesPane.svelte";
import TimelinePane from "./ui/timeline/TimelinePane.svelte";
import ViewportPane from "./ui/viewport/ViewportPane.svelte";
import PopupHost from "./ui/popup/PopupHost.svelte";
import AnimationGraphPane from "./ui/graph/AnimationGraphPane.svelte";
import EmptyPane from "./ui/pane/EmptyPane.svelte";
let states: Record<string, TabState> = {
"default-files": { type: "files", state: {} },
"default-project": { type: "project", state: {} },
"default-outliner": { type: "outliner", state: {} },
"default-timeline": { type: "timeline", state: {} },
"default-animationGraph": { type: "animationGraph", state: {} },
"default-properties": { type: "properties", state: {} },
"default-modifiers": { type: "modifiers", state: {} },
"default-viewport": { type: "viewport", state: {} }
};
let layout: PaneLayout = {
type: "split",
direction: SplitDirection.LeftToRight,
Expand All @@ -19,20 +29,20 @@
type: "split",
direction: SplitDirection.BottomToTop,
firstSize: 500,
first: { type: "tab", tabs: ["files", "project"], selected: "files" },
second: { type: "tab", tabs: ["outliner"], selected: "outliner" }
first: { type: "tab", tabs: ["default-files", "default-project"], selected: "default-files" },
second: { type: "tab", tabs: ["default-outliner"], selected: "default-outliner" }
},
second: {
type: "split",
direction: SplitDirection.BottomToTop,
firstSize: 300,
first: { type: "tab", tabs: ["timeline", "animationGraph"], selected: "timeline" },
first: { type: "tab", tabs: ["default-timeline", "default-animationGraph"], selected: "default-timeline" },
second: {
type: "split",
direction: SplitDirection.RightToLeft,
firstSize: 300,
first: { type: "tab", tabs: ["properties", "modifiers"], selected: "properties" },
second: { type: "tab", tabs: ["viewport"], selected: "viewport" }
first: { type: "tab", tabs: ["default-properties", "default-modifiers"], selected: "default-properties" },
second: { type: "tab", tabs: ["default-viewport"], selected: "default-viewport" }
}
}
};
Expand All @@ -41,13 +51,13 @@
<div class="app">
<div class="content">
<TopBar />
<PaneHost {layout} component={type => {
<PaneHost {layout} {states} component={type => {
if (type == "properties") return PropertiesPane;
if (type == "timeline") return TimelinePane;
if (type == "outliner") return OutlinerPane;
if (type == "viewport") return ViewportPane;
if (type == "animationGraph") return AnimationGraphPane;
return Button;
return EmptyPane;
}} on:layoutupdate={e => layout = e.detail} />
<MediaBar />
</div>
Expand Down
1 change: 1 addition & 0 deletions nahara-motion-ui/src/ui/outliner/OutlinerPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import * as motion from "@nahara/motion";
import Outliner from "./Outliner.svelte";
export let state: any;
const currentScene = app.currentSceneStore;
const selection = app.currentSelectionStore;
Expand Down
3 changes: 3 additions & 0 deletions nahara-motion-ui/src/ui/pane/EmptyPane.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script lang="ts">
export let state: any;
</script>
12 changes: 10 additions & 2 deletions nahara-motion-ui/src/ui/pane/PaneHost.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ Pane host is a component that includes the panes and layout management.
type: T;
}
export interface TabState {
type: string;
state: any;
}
export interface TabLayout extends IBaseLayout<"tab"> {
/**
* An array of IDs that maps to component.
* An array of IDs that maps state ID whose type maps to component.
*/
tabs: string[];
selected: string;
Expand Down Expand Up @@ -66,6 +71,7 @@ Pane host is a component that includes the panes and layout management.
tabs: [],
selected: ""
};
export let states: Record<string, TabState> = {};
export let component: (name: string) => { new(...args: any[]): SvelteComponent };
export let tabNames: (id: string) => string = id => id;
export let dividerSize = 8;
Expand Down Expand Up @@ -372,7 +378,9 @@ Pane host is a component that includes the panes and layout management.
})}
on:paneclose={e => paneNuke(tabLayout)}
>
<svelte:component this={component(tabLayout.selected)} />
{#if tabLayout.selected}
<svelte:component this={component(states[tabLayout.selected].type)} state={states[tabLayout.selected].state} />
{/if}
</TabbedPane>
{/each}
{#each splitLayouts as splitLayout}
Expand Down
1 change: 1 addition & 0 deletions nahara-motion-ui/src/ui/properties/PropertiesPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Dropdown from "../input/Dropdown.svelte";
import { openMenuAt } from "../menu/MenuHost.svelte";
export let state: any;
const currentScene = app.currentSceneStore;
const currentSelection = app.currentSelectionStore;
const seekhead = app.currentSeekheadStore;
Expand Down
1 change: 1 addition & 0 deletions nahara-motion-ui/src/ui/timeline/TimelinePane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { app } from "../../appglobal";
import { snapping } from "../../snapping";
export let state: any;
let labelWidth = 200;
let zoom = 100; // 100 CSS pixels per second
let scroll = 0;
Expand Down
1 change: 1 addition & 0 deletions nahara-motion-ui/src/ui/viewport/ViewportPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { openPopupAt } from "../popup/PopupHost.svelte";
import ColorPickerPopup from "../popup/ColorPickerPopup.svelte";
export let state: any;
let canvas: HTMLCanvasElement;
let ctx: CanvasRenderingContext2D;
$: {
Expand Down

0 comments on commit 5f8f182

Please sign in to comment.