Skip to content

Commit

Permalink
Add dark mode option
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Aug 3, 2023
1 parent cc87b11 commit 1840578
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 53 deletions.
2 changes: 2 additions & 0 deletions viser/_message_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ def configure_theme(
*,
titlebar_content: Optional[theme.TitlebarConfig] = None,
fixed_sidebar: bool = False,
dark_mode: bool = False,
) -> None:
"""Configure the viser front-end's visual appearance."""
self._queue(
_messages.ThemeConfigurationMessage(
titlebar_content=titlebar_content,
fixed_sidebar=fixed_sidebar,
dark_mode=dark_mode,
),
)

Expand Down
1 change: 1 addition & 0 deletions viser/_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,4 @@ class ThemeConfigurationMessage(Message):

titlebar_content: Optional[theme.TitlebarConfig]
fixed_sidebar: bool
dark_mode: bool
92 changes: 47 additions & 45 deletions viser/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,44 @@ function SingleViewer() {

const fixed_sidebar = viewer.useGui((state) => state.theme.fixed_sidebar);
return (
<ViewerContext.Provider value={viewer}>
<Titlebar />
<Box
sx={{
width: "100%",
height: "1px",
position: "relative",
flex: "1 0 auto",
}}
>
<MediaQuery smallerThan={"xs"} styles={{ right: 0, bottom: "3.5em" }}>
<Box
sx={(theme) => ({
top: 0,
bottom: 0,
left: 0,
right: fixed_sidebar ? "20em" : 0,
position: "absolute",
backgroundColor:
theme.colorScheme === "light" ? "#fff" : theme.colors.dark[9],
})}
>
<ViewerCanvas>{memoizedWebsocketInterface}</ViewerCanvas>
</Box>
</MediaQuery>
<ControlPanel fixed_sidebar={fixed_sidebar} />
</Box>
</ViewerContext.Provider>
<MantineProvider
withGlobalStyles
withNormalizeCSS
theme={{
colorScheme: viewer.useGui((state) => state.theme.dark_mode)
? "dark"
: "light",
}}
>
<ViewerContext.Provider value={viewer}>
<Titlebar />
<Box
sx={{
width: "100%",
height: "1px",
position: "relative",
flex: "1 0 auto",
}}
>
<MediaQuery smallerThan={"xs"} styles={{ right: 0, bottom: "3.5em" }}>
<Box
sx={(theme) => ({
top: 0,
bottom: 0,
left: 0,
right: fixed_sidebar ? "20em" : 0,
position: "absolute",
backgroundColor:
theme.colorScheme === "light" ? "#fff" : theme.colors.dark[9],
})}
>
<ViewerCanvas>{memoizedWebsocketInterface}</ViewerCanvas>
</Box>
</MediaQuery>
<ControlPanel fixed_sidebar={fixed_sidebar} />
</Box>
</ViewerContext.Provider>
</MantineProvider>
);
}

Expand Down Expand Up @@ -174,24 +184,16 @@ function SceneContextSetter() {

export function Root() {
return (
<MantineProvider
withGlobalStyles
withNormalizeCSS
theme={{
colorScheme: "light",
<Box
sx={{
width: "100%",
height: "100%",
position: "relative",
display: "flex",
flexDirection: "column",
}}
>
<Box
sx={{
width: "100%",
height: "100%",
position: "relative",
display: "flex",
flexDirection: "column",
}}
>
<SingleViewer />
</Box>
</MantineProvider>
<SingleViewer />
</Box>
);
}
1 change: 1 addition & 0 deletions viser/client/src/ControlPanel/GuiState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const cleanGuiState: GuiState = {
type: "ThemeConfigurationMessage",
titlebar_content: null,
fixed_sidebar: false,
dark_mode: false,
},
label: "",
server: "ws://localhost:8080", // Currently this will always be overridden.
Expand Down
9 changes: 1 addition & 8 deletions viser/client/src/WebsocketMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,6 @@ export interface GuiSetValueMessage {
id: string;
value: any;
}
export interface MessageGroupStart {
type: "MessageGroupStart";
}
export interface MessageGroupEnd {
type: "MessageGroupEnd";
}
export interface ThemeConfigurationMessage {
type: "ThemeConfigurationMessage";
titlebar_content: {
Expand All @@ -327,6 +321,7 @@ export interface ThemeConfigurationMessage {
} | null;
} | null;
fixed_sidebar: boolean;
dark_mode: boolean;
}

export type Message =
Expand Down Expand Up @@ -371,6 +366,4 @@ export type Message =
| GuiSetVisibleMessage
| GuiSetDisabledMessage
| GuiSetValueMessage
| MessageGroupStart
| MessageGroupEnd
| ThemeConfigurationMessage;

0 comments on commit 1840578

Please sign in to comment.