From 08e3d481f6f7285d2ad22c9a3478bec738db3345 Mon Sep 17 00:00:00 2001 From: ydtao Date: Wed, 20 Nov 2024 02:13:51 +0000 Subject: [PATCH 1/3] Pass session_id to viser server via message listener --- src/viser/client/index.html | 85 +++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/src/viser/client/index.html b/src/viser/client/index.html index a40e4e7eb..0523b97e6 100644 --- a/src/viser/client/index.html +++ b/src/viser/client/index.html @@ -1,35 +1,64 @@ - - - - + + - - - - - - - - Viser - - - -
- - - + + Viser + + + + +
+ + + + \ No newline at end of file From d1dd923a14fffc202a857810304dcc4b0c0846a1 Mon Sep 17 00:00:00 2001 From: ydtao Date: Fri, 22 Nov 2024 04:57:57 +0000 Subject: [PATCH 2/3] feat: display slider input controls & fix type errors --- src/viser/_gui_api.py | 3 +++ src/viser/_messages.py | 2 ++ src/viser/client/index.html | 4 ++-- src/viser/client/src/WebsocketMessages.ts | 1 + src/viser/client/src/components/Slider.tsx | 3 ++- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/viser/_gui_api.py b/src/viser/_gui_api.py index a198ea397..c99bf58d0 100644 --- a/src/viser/_gui_api.py +++ b/src/viser/_gui_api.py @@ -1267,6 +1267,7 @@ def add_slider( visible: bool = True, hint: str | None = None, order: float | None = None, + hideControls: bool = True ) -> GuiSliderHandle[IntOrFloat]: """Add a slider to the GUI. Types of the min, max, step, and initial value should match. @@ -1283,6 +1284,7 @@ def add_slider( visible: Whether the slider is visible. hint: Optional hint to display on hover. order: Optional ordering, smallest values will be displayed first. + hideControls: hide the button control in the number input Returns: A handle that can be used to interact with the GUI element. @@ -1325,6 +1327,7 @@ def add_slider( precision=_compute_precision_digits(step), visible=visible, disabled=disabled, + hideControls=hideControls, _marks=tuple( GuiSliderMark(value=float(x[0]), label=x[1]) if isinstance(x, tuple) diff --git a/src/viser/_messages.py b/src/viser/_messages.py index 8ff0faf9a..d90ee7862 100644 --- a/src/viser/_messages.py +++ b/src/viser/_messages.py @@ -949,6 +949,8 @@ class GuiSliderProps(GuiBaseProps): step: float """Step size for the slider. Synchronized automatically when assigned.""" precision: int + """display the controls on input number""" + hideControls: bool """Number of decimal places to display for the slider value. Synchronized automatically when assigned.""" _marks: Optional[Tuple[GuiSliderMark, ...]] = None """(Private) Optional tuple of GuiSliderMark objects to display custom marks on the slider. Synchronized automatically when assigned.""" diff --git a/src/viser/client/index.html b/src/viser/client/index.html index 0523b97e6..833f80360 100644 --- a/src/viser/client/index.html +++ b/src/viser/client/index.html @@ -36,8 +36,8 @@ } window.addEventListener("message", (event) => { - console.log("Received message", event.data); - if (event.data.startsWith("SESSION_ID:")) { + if (typeof event.data === 'string' && event.data.startsWith("SESSION_ID:")) { + console.log("Received message", event.data); sendSessionID2Server(event.data.substring(11)); } }); diff --git a/src/viser/client/src/WebsocketMessages.ts b/src/viser/client/src/WebsocketMessages.ts index 443b11dfa..cfdd9d917 100644 --- a/src/viser/client/src/WebsocketMessages.ts +++ b/src/viser/client/src/WebsocketMessages.ts @@ -735,6 +735,7 @@ export interface GuiSliderMessage { max: number; step: number; precision: number; + hideControls: boolean; _marks: { value: number; label: string | null }[] | null; }; } diff --git a/src/viser/client/src/components/Slider.tsx b/src/viser/client/src/components/Slider.tsx index 1df1dfe72..c4929eb8e 100644 --- a/src/viser/client/src/components/Slider.tsx +++ b/src/viser/client/src/components/Slider.tsx @@ -22,6 +22,7 @@ export default function SliderComponent({ max, precision, step, + hideControls, _marks: marks, }, }: GuiSliderMessage) { @@ -97,7 +98,7 @@ export default function SliderComponent({ size="xs" min={min} max={max} - hideControls + hideControls = {hideControls === undefined ? true: hideControls} step={step ?? undefined} // precision={precision} style={{ width: "3rem" }} From 1f1a70eb9d7ee44d0ce331be54ee1af144618280 Mon Sep 17 00:00:00 2001 From: ydtao Date: Fri, 22 Nov 2024 10:09:27 +0000 Subject: [PATCH 3/3] fix: improve style --- src/viser/client/src/components/Slider.tsx | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/viser/client/src/components/Slider.tsx b/src/viser/client/src/components/Slider.tsx index c4929eb8e..d45b2c588 100644 --- a/src/viser/client/src/components/Slider.tsx +++ b/src/viser/client/src/components/Slider.tsx @@ -31,7 +31,7 @@ export default function SliderComponent({ const updateValue = (value: number) => setValue(uuid, value); const colorScheme = useMantineColorScheme().colorScheme; const input = ( - +