From 93e269990a043b3d2291f6d09019f6f0d80a6dd9 Mon Sep 17 00:00:00 2001 From: Brent Yi Date: Thu, 26 Oct 2023 18:06:50 -0700 Subject: [PATCH] Add configurable control panel width (#123) * Add configurable control panel width * Tweak comment --- examples/13_theming.py | 5 +++++ src/viser/_message_api.py | 2 ++ src/viser/_messages.py | 1 + .../client/src/ControlPanel/ControlPanel.tsx | 20 +++++++++++++++++-- .../client/src/ControlPanel/FloatingPanel.tsx | 12 +++++++---- .../client/src/ControlPanel/GuiState.tsx | 1 + .../client/src/ControlPanel/SidebarPanel.tsx | 8 +++++--- src/viser/client/src/WebsocketMessages.tsx | 1 + 8 files changed, 41 insertions(+), 9 deletions(-) diff --git a/examples/13_theming.py b/examples/13_theming.py index 82078ef69..ecb01049f 100644 --- a/examples/13_theming.py +++ b/examples/13_theming.py @@ -53,6 +53,9 @@ control_layout = server.add_gui_dropdown( "Control layout", ("floating", "fixed", "collapsible") ) +control_width = server.add_gui_dropdown( + "Control width", ("small", "medium", "large"), initial_value="medium" +) synchronize = server.add_gui_button("Apply theme", icon=viser.Icon.CHECK) @@ -60,6 +63,7 @@ def synchronize_theme() -> None: server.configure_theme( titlebar_content=titlebar_theme if titlebar.value else None, control_layout=control_layout.value, + control_width=control_width.value, dark_mode=dark_mode.value, show_logo=show_logo.value, brand_color=brand_color.value, @@ -70,6 +74,7 @@ def synchronize_theme() -> None: server.configure_theme( titlebar_content={"titlebar_content" if titlebar.value else None}, control_layout="{control_layout.value}", + control_width="{control_width.value}", dark_mode={dark_mode.value}, show_logo={show_logo.value}, brand_color={brand_color.value}, diff --git a/src/viser/_message_api.py b/src/viser/_message_api.py index 8725851ac..dc18f0357 100644 --- a/src/viser/_message_api.py +++ b/src/viser/_message_api.py @@ -177,6 +177,7 @@ def configure_theme( *, titlebar_content: Optional[theme.TitlebarConfig] = None, control_layout: Literal["floating", "collapsible", "fixed"] = "floating", + control_width: Literal["small", "medium", "large"] = "medium", dark_mode: bool = False, show_logo: bool = True, brand_color: Optional[Tuple[int, int, int]] = None, @@ -224,6 +225,7 @@ def configure_theme( _messages.ThemeConfigurationMessage( titlebar_content=titlebar_content, control_layout=control_layout, + control_width=control_width, dark_mode=dark_mode, show_logo=show_logo, colors=colors_cast, diff --git a/src/viser/_messages.py b/src/viser/_messages.py index c4ffbcf8f..26397ba71 100644 --- a/src/viser/_messages.py +++ b/src/viser/_messages.py @@ -521,6 +521,7 @@ class ThemeConfigurationMessage(Message): titlebar_content: Optional[theme.TitlebarConfig] control_layout: Literal["floating", "collapsible", "fixed"] + control_width: Literal["small", "medium", "large"] show_logo: bool dark_mode: bool colors: Optional[Tuple[str, str, str, str, str, str, str, str, str, str]] diff --git a/src/viser/client/src/ControlPanel/ControlPanel.tsx b/src/viser/client/src/ControlPanel/ControlPanel.tsx index cbfe38b18..6d5cdbb4e 100644 --- a/src/viser/client/src/ControlPanel/ControlPanel.tsx +++ b/src/viser/client/src/ControlPanel/ControlPanel.tsx @@ -38,6 +38,19 @@ export default function ControlPanel(props: { ); const [showSettings, { toggle }] = useDisclosure(false); + const controlWidthString = viewer.useGui( + (state) => state.theme.control_width, + ); + const controlWidth = ( + controlWidthString == "small" + ? "16em" + : controlWidthString == "medium" + ? "20em" + : controlWidthString == "large" + ? "24em" + : null + )!; + const generatedServerToggleButton = ( + @@ -101,7 +114,10 @@ export default function ControlPanel(props: { } else { /* Sidebar view. */ return ( - + {generatedServerToggleButton} diff --git a/src/viser/client/src/ControlPanel/FloatingPanel.tsx b/src/viser/client/src/ControlPanel/FloatingPanel.tsx index aa688e5d1..f60920774 100644 --- a/src/viser/client/src/ControlPanel/FloatingPanel.tsx +++ b/src/viser/client/src/ControlPanel/FloatingPanel.tsx @@ -8,6 +8,7 @@ import { useDisclosure } from "@mantine/hooks"; const FloatingPanelContext = React.createContext; expanded: boolean; + width: string; maxHeight: number; toggleExpanded: () => void; dragHandler: ( @@ -27,8 +28,10 @@ const FloatingPanelContext = React.createContext(null); const [expanded, { toggle: toggleExpanded }] = useDisclosure(true); @@ -202,6 +205,7 @@ export default function FloatingPanel({ value={{ wrapperRef: panelWrapperRef, expanded: expanded, + width: width, maxHeight: maxHeight, toggleExpanded: toggleExpanded, dragHandler: dragHandler, @@ -213,7 +217,7 @@ export default function FloatingPanel({ shadow="lg" sx={{ boxSizing: "border-box", - width: "20em", + width: width, zIndex: 10, position: "absolute", top: "1em", @@ -286,11 +290,11 @@ FloatingPanel.Contents = function FloatingPanelContents({ const context = React.useContext(FloatingPanelContext)!; return ( - + {children} diff --git a/src/viser/client/src/ControlPanel/GuiState.tsx b/src/viser/client/src/ControlPanel/GuiState.tsx index 07fa06f36..7cd0d2012 100644 --- a/src/viser/client/src/ControlPanel/GuiState.tsx +++ b/src/viser/client/src/ControlPanel/GuiState.tsx @@ -61,6 +61,7 @@ const cleanGuiState: GuiState = { type: "ThemeConfigurationMessage", titlebar_content: null, control_layout: "floating", + control_width: "medium", dark_mode: false, show_logo: true, colors: null, diff --git a/src/viser/client/src/ControlPanel/SidebarPanel.tsx b/src/viser/client/src/ControlPanel/SidebarPanel.tsx index c3aebd97b..0e14f5a6f 100644 --- a/src/viser/client/src/ControlPanel/SidebarPanel.tsx +++ b/src/viser/client/src/ControlPanel/SidebarPanel.tsx @@ -14,9 +14,11 @@ export const SidebarPanelContext = React.createContext {children} diff --git a/src/viser/client/src/WebsocketMessages.tsx b/src/viser/client/src/WebsocketMessages.tsx index 8e8d934cc..28e782a02 100644 --- a/src/viser/client/src/WebsocketMessages.tsx +++ b/src/viser/client/src/WebsocketMessages.tsx @@ -607,6 +607,7 @@ export interface ThemeConfigurationMessage { } | null; } | null; control_layout: "floating" | "collapsible" | "fixed"; + control_width: "small" | "medium" | "large"; show_logo: boolean; dark_mode: boolean; colors: