Skip to content

Commit

Permalink
Add hints/tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Jun 19, 2023
1 parent 49bd503 commit b958b64
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/11_colmap_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main(
cameras = read_cameras_binary(colmap_path / "cameras.bin")
images = read_images_binary(colmap_path / "images.bin")
points3d = read_points3d_binary(colmap_path / "points3D.bin")
gui_reset_up = server.add_gui_button("Reset up direction")
gui_reset_up = server.add_gui_button("Reset up direction", hint="Set the camera control 'up' direction to the current camera's 'up'.")

@gui_reset_up.on_click
def _(_) -> None:
Expand Down
2 changes: 2 additions & 0 deletions viser/_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class _GuiHandleState(Generic[T]):
order: float
id: str
initial_value: T
hint: Optional[str]


@dataclasses.dataclass
Expand Down Expand Up @@ -245,6 +246,7 @@ def options(self, options: Iterable[StringType]) -> None:
id=self._impl.id,
label=self._impl.label,
folder_labels=self._impl.folder_labels,
hint=self._impl.hint,
initial_value=self._impl.initial_value,
options=self._impl_options,
)
Expand Down
16 changes: 16 additions & 0 deletions viser/_message_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def add_gui_button(
label: str,
disabled: bool = False,
visible: bool = True,
hint: Optional[str] = None,
) -> GuiButtonHandle:
"""Add a button to the GUI. The value of this input is set to `True` every time
it is clicked; to detect clicks, we can manually set it back to `False`."""
Expand All @@ -243,6 +244,7 @@ def add_gui_button(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
initial_value=False,
),
disabled=disabled,
Expand All @@ -263,6 +265,7 @@ def add_gui_button_group(
options: Tuple[TLiteralString, ...],
visible: bool = True,
disabled: bool = False,
hint: Optional[str] = None,
) -> GuiButtonGroupHandle[TLiteralString]:
...

Expand All @@ -273,6 +276,7 @@ def add_gui_button_group(
options: Tuple[TString, ...],
visible: bool = True,
disabled: bool = False,
hint: Optional[str] = None,
) -> GuiButtonGroupHandle[TString]:
...

Expand All @@ -282,6 +286,7 @@ def add_gui_button_group(
options: Tuple[TLiteralString, ...] | Tuple[TString, ...],
visible: bool = True,
disabled: bool = False,
hint: Optional[str] = None,
) -> GuiButtonGroupHandle[Any]: # Return types are specified in overloads.
"""Add a button group to the GUI."""
initial_value = options[0]
Expand All @@ -294,6 +299,7 @@ def add_gui_button_group(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
initial_value=initial_value,
options=options,
),
Expand All @@ -320,6 +326,7 @@ def add_gui_checkbox(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
initial_value=initial_value,
),
disabled=disabled,
Expand All @@ -344,6 +351,7 @@ def add_gui_text(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
initial_value=initial_value,
),
disabled=disabled,
Expand Down Expand Up @@ -387,6 +395,7 @@ def add_gui_number(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
initial_value=initial_value,
min=min,
max=max,
Expand Down Expand Up @@ -431,6 +440,7 @@ def add_gui_vector2(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
initial_value=initial_value,
min=min,
max=max,
Expand Down Expand Up @@ -475,6 +485,7 @@ def add_gui_vector3(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
initial_value=initial_value,
min=min,
max=max,
Expand Down Expand Up @@ -530,6 +541,7 @@ def add_gui_dropdown(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
initial_value=initial_value,
options=tuple(options),
),
Expand Down Expand Up @@ -577,6 +589,7 @@ def add_gui_slider(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
min=min,
max=max,
step=step,
Expand Down Expand Up @@ -605,6 +618,7 @@ def add_gui_rgb(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
initial_value=initial_value,
),
disabled=disabled,
Expand All @@ -628,6 +642,7 @@ def add_gui_rgba(
id=id,
label=label,
folder_labels=tuple(self._gui_folder_labels),
hint=hint,
initial_value=initial_value,
),
disabled=disabled,
Expand Down Expand Up @@ -1022,6 +1037,7 @@ def _create_gui_input(
id=message.id,
order=message.order,
initial_value=initial_value,
hint=message.hint,
)
self._gui_handle_state_from_id[handle_state.id] = handle_state
handle_state.cleanup_cb = lambda: self._gui_handle_state_from_id.pop(
Expand Down
1 change: 1 addition & 0 deletions viser/_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ class _GuiAddMessageBase(Message):
id: str
label: str
folder_labels: Tuple[str, ...]
hint: Optional[str]


@dataclasses.dataclass
Expand Down
6 changes: 3 additions & 3 deletions viser/client/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"files": {
"main.css": "/static/css/main.82973013.css",
"main.js": "/static/js/main.fb147a9e.js",
"main.js": "/static/js/main.679eff5c.js",
"index.html": "/index.html",
"main.82973013.css.map": "/static/css/main.82973013.css.map",
"main.fb147a9e.js.map": "/static/js/main.fb147a9e.js.map"
"main.679eff5c.js.map": "/static/js/main.679eff5c.js.map"
},
"entrypoints": [
"static/css/main.82973013.css",
"static/js/main.fb147a9e.js"
"static/js/main.679eff5c.js"
]
}
2 changes: 1 addition & 1 deletion viser/client/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.svg"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Viser</title><script defer="defer" src="/static/js/main.fb147a9e.js"></script><link href="/static/css/main.82973013.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.svg"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Viser</title><script defer="defer" src="/static/js/main.679eff5c.js"></script><link href="/static/css/main.82973013.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

78 changes: 42 additions & 36 deletions viser/client/src/ControlPanel/Generated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Stack,
Text,
TextInput,
Tooltip,
} from "@mantine/core";
import { makeThrottledMessageSender } from "../WebsocketInterface";

Expand Down Expand Up @@ -144,47 +145,45 @@ function GeneratedInput({ conf }: { conf: GuiConfig }) {
break;
case "GuiAddSliderMessage":
input = (
<>
<Flex justify="space-between">
<Box sx={{ flexGrow: 1 }}>
<Slider
id={conf.id}
size="sm"
pt="0.3rem"
showLabelOnHover={false}
min={conf.min}
max={conf.max}
step={conf.step ?? undefined}
precision={conf.precision}
value={value}
onChange={updateValue}
marks={[{ value: conf.min }, { value: conf.max }]}
disabled={disabled}
/>
<Flex justify="space-between" sx={{ marginTop: "-0.2em" }}>
<Text fz="0.7rem" c="dimmed">
{conf.min}
</Text>
<Text fz="0.7rem" c="dimmed">
{conf.max}
</Text>
</Flex>
</Box>
<NumberInput
value={value}
onChange={updateValue}
size="xs"
<Flex justify="space-between">
<Box sx={{ flexGrow: 1 }}>
<Slider
id={conf.id}
size="sm"
pt="0.3rem"
showLabelOnHover={false}
min={conf.min}
max={conf.max}
hideControls
step={conf.step ?? undefined}
precision={conf.precision}
sx={{ width: "3rem", height: "1rem", minHeight: "1rem" }}
styles={{ input: { padding: "0.3rem" } }}
ml="xs"
value={value}
onChange={updateValue}
marks={[{ value: conf.min }, { value: conf.max }]}
disabled={disabled}
/>
</Flex>
</>
<Flex justify="space-between" sx={{ marginTop: "-0.2em" }}>
<Text fz="0.7rem" c="dimmed">
{conf.min}
</Text>
<Text fz="0.7rem" c="dimmed">
{conf.max}
</Text>
</Flex>
</Box>
<NumberInput
value={value}
onChange={updateValue}
size="xs"
min={conf.min}
max={conf.max}
hideControls
step={conf.step ?? undefined}
precision={conf.precision}
sx={{ width: "3rem", height: "1rem", minHeight: "1rem" }}
styles={{ input: { padding: "0.3rem" } }}
ml="xs"
/>
</Flex>
);
break;
case "GuiAddNumberMessage":
Expand Down Expand Up @@ -315,6 +314,13 @@ function GeneratedInput({ conf }: { conf: GuiConfig }) {
);
}

if (conf.hint !== null)
input = (
<Tooltip label={conf.hint} multiline w="15rem" withArrow openDelay={500}>
{input}
</Tooltip>
);

if (labeled)
return <LabeledInput id={conf.id} label={conf.label} input={input} />;
else return input;
Expand Down
12 changes: 12 additions & 0 deletions viser/client/src/WebsocketMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ export interface _GuiAddMessageBase {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
}
export interface GuiAddButtonMessage {
type: "GuiAddButtonMessage";
order: number;
id: string;
label: string;
folder_labels: string[];
hint: string | null;
initial_value: boolean;
}
export interface GuiAddSliderMessage {
Expand All @@ -154,6 +156,7 @@ export interface GuiAddSliderMessage {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
min: number;
max: number;
step: number | null;
Expand All @@ -166,6 +169,7 @@ export interface GuiAddNumberMessage {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
initial_value: number;
precision: number;
step: number;
Expand All @@ -178,6 +182,7 @@ export interface GuiAddRgbMessage {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
initial_value: [number, number, number];
}
export interface GuiAddRgbaMessage {
Expand All @@ -186,6 +191,7 @@ export interface GuiAddRgbaMessage {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
initial_value: [number, number, number, number];
}
export interface GuiAddCheckboxMessage {
Expand All @@ -194,6 +200,7 @@ export interface GuiAddCheckboxMessage {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
initial_value: boolean;
}
export interface GuiAddVector2Message {
Expand All @@ -202,6 +209,7 @@ export interface GuiAddVector2Message {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
initial_value: [number, number];
min: [number, number] | null;
max: [number, number] | null;
Expand All @@ -214,6 +222,7 @@ export interface GuiAddVector3Message {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
initial_value: [number, number, number];
min: [number, number, number] | null;
max: [number, number, number] | null;
Expand All @@ -226,6 +235,7 @@ export interface GuiAddTextMessage {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
initial_value: string;
}
export interface GuiAddDropdownMessage {
Expand All @@ -234,6 +244,7 @@ export interface GuiAddDropdownMessage {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
initial_value: string;
options: string[];
}
Expand All @@ -243,6 +254,7 @@ export interface GuiAddButtonGroupMessage {
id: string;
label: string;
folder_labels: string[];
hint: string | null;
initial_value: string;
options: string[];
}
Expand Down

0 comments on commit b958b64

Please sign in to comment.