Skip to content

Commit

Permalink
Refac components
Browse files Browse the repository at this point in the history
  • Loading branch information
jkulhanek committed Jan 30, 2024
1 parent 9c36398 commit 9e5a015
Show file tree
Hide file tree
Showing 24 changed files with 1,039 additions and 830 deletions.
157 changes: 83 additions & 74 deletions src/viser/_gui_api.py

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/viser/_gui_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,10 @@ def options(self, options: Iterable[StringType]) -> None:
label=self._impl.label,
container_id=self._impl.container_id,
hint=self._impl.hint,
initial_value=self._impl.initial_value,
value=self._impl.initial_value,
options=self._impl_options,
visible=self._impl.visible,
disabled=self._impl.disabled,
)
)

Expand All @@ -337,6 +339,7 @@ class GuiTabGroupHandle:
_gui_api: GuiApi
_container_id: str # Parent.
_order: float
_visible: bool

@property
def order(self) -> float:
Expand Down Expand Up @@ -374,6 +377,7 @@ def _sync_with_client(self) -> None:
tab_labels=tuple(self._labels),
tab_icons_base64=tuple(self._icons_base64),
tab_container_ids=tuple(tab._id for tab in self._tabs),
visible=self._visible,
)
)

Expand Down Expand Up @@ -567,6 +571,7 @@ def content(self, content: str) -> None:
id=self._id,
markdown=_parse_markdown(content, self._image_root),
container_id=self._container_id,
visible=self._visible,
)
)

Expand Down
31 changes: 18 additions & 13 deletions src/viser/_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ class GuiAddFolderMessage(Message):
label: str
container_id: str
expand_by_default: bool
visible: bool


@dataclasses.dataclass
Expand All @@ -361,6 +362,7 @@ class GuiAddMarkdownMessage(Message):
id: str
markdown: str
container_id: str
visible: bool


@dataclasses.dataclass
Expand All @@ -371,6 +373,7 @@ class GuiAddTabGroupMessage(Message):
tab_labels: Tuple[str, ...]
tab_icons_base64: Tuple[Union[str, None], ...]
tab_container_ids: Tuple[str, ...]
visible: bool


@dataclasses.dataclass
Expand All @@ -382,7 +385,9 @@ class _GuiAddInputBase(Message):
label: str
container_id: str
hint: Optional[str]
initial_value: Any
value: Any
visible: bool
disabled: bool


@dataclasses.dataclass
Expand All @@ -399,9 +404,9 @@ class GuiCloseModalMessage(Message):

@dataclasses.dataclass
class GuiAddButtonMessage(_GuiAddInputBase):
# All GUI elements currently need an `initial_value` field.
# All GUI elements currently need an `value` field.
# This makes our job on the frontend easier.
initial_value: bool
value: bool
color: Optional[
Literal[
"dark",
Expand All @@ -428,13 +433,13 @@ class GuiAddSliderMessage(_GuiAddInputBase):
min: float
max: float
step: Optional[float]
initial_value: float
value: float
precision: int


@dataclasses.dataclass
class GuiAddNumberMessage(_GuiAddInputBase):
initial_value: float
value: float
precision: int
step: float
min: Optional[float]
Expand All @@ -443,22 +448,22 @@ class GuiAddNumberMessage(_GuiAddInputBase):

@dataclasses.dataclass
class GuiAddRgbMessage(_GuiAddInputBase):
initial_value: Tuple[int, int, int]
value: Tuple[int, int, int]


@dataclasses.dataclass
class GuiAddRgbaMessage(_GuiAddInputBase):
initial_value: Tuple[int, int, int, int]
value: Tuple[int, int, int, int]


@dataclasses.dataclass
class GuiAddCheckboxMessage(_GuiAddInputBase):
initial_value: bool
value: bool


@dataclasses.dataclass
class GuiAddVector2Message(_GuiAddInputBase):
initial_value: Tuple[float, float]
value: Tuple[float, float]
min: Optional[Tuple[float, float]]
max: Optional[Tuple[float, float]]
step: float
Expand All @@ -467,7 +472,7 @@ class GuiAddVector2Message(_GuiAddInputBase):

@dataclasses.dataclass
class GuiAddVector3Message(_GuiAddInputBase):
initial_value: Tuple[float, float, float]
value: Tuple[float, float, float]
min: Optional[Tuple[float, float, float]]
max: Optional[Tuple[float, float, float]]
step: float
Expand All @@ -476,18 +481,18 @@ class GuiAddVector3Message(_GuiAddInputBase):

@dataclasses.dataclass
class GuiAddTextMessage(_GuiAddInputBase):
initial_value: str
value: str


@dataclasses.dataclass
class GuiAddDropdownMessage(_GuiAddInputBase):
initial_value: str
value: str
options: Tuple[str, ...]


@dataclasses.dataclass
class GuiAddButtonGroupMessage(_GuiAddInputBase):
initial_value: str
value: str
options: Tuple[str, ...]


Expand Down
Loading

0 comments on commit 9e5a015

Please sign in to comment.