Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement custom titlebars that can be configured in Python #42

Merged
merged 28 commits into from
Jun 16, 2023

Conversation

jonahbedouch
Copy link
Contributor

Adds a toggleable navbar to Viser and piggybacks off of PR 40 to expose a Python Interface for adding custom buttons, images, and padding to the navbar. Example below:

titlebarTheme = TitlebarConfig(left=[TitlebarButton(text="Getting Started", href="https://nerf.studio", variant='outlined'),
                                     TitlebarButton(text="Github", icon="GitHub", href="https://github.com/nerfstudio-project/nerfstudio", variant='outlined'),
                                     TitlebarButton(text="Documentation", icon="Description", href="https://docs.nerf.studio", variant='outlined'),
                                     TitlebarButton(text="Viewport Controls", icon="Keyboard", href="https://docs.nerf.studio", variant='outlined'),
                                     ], 
                              right=[TitlebarImage(imageSource="https://docs.nerf.studio/en/latest/_static/imgs/logo.png", alt="NerfStudio Logo"), TitlebarPadding(width="5em")])

server.configure_theme(canvas_background_color=(2, 230, 230),
                       show_titlebar=True,
                       titlebar_content=titlebarTheme);

Resulting in:
image

Relevant to (and in theory closes) #20

@jonahbedouch jonahbedouch requested a review from brentyi June 1, 2023 03:21
Copy link
Collaborator

@brentyi brentyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks really great that was super fast!!

I dropped some comments, mostly related to the typing of the message

@jonahbedouch
Copy link
Contributor Author

After discussions about appearance when scaled down and general security with regards to sending the difference as a string, we made the following changes:

  • Add TypedDict support to the type conversion tool and change the type on both ends to a more strict type

  • Remove hacked type validation on the Typescript side

  • Restrict Icons to a very limited intro set

  • Remove the requirement to "show" the titlebar with a separate configure_theme option. Instead, the titlebar shows automatically whenever a titlebar config is sent.

  • Remove TitlebarPadding class, and rework TitlebarButton and TitlebarImage to be TypedDicts (with optional literals as necessary).

  • Expose TitlebarButton and TitlebarImage from viser.theme

  • Rework API to not take in 3 inputs. Instead, it takes in a list of buttons and an optional image to be used as a header image on the right. This has some room for future work (some of which I've opted to postpone mostly due to the work being done in MUI -> mantine transition #49 ).

    • In a pure styling context, check whether the total size of the buttons exceeds the size of the container, and switch to a dropdown layout to avoid overflow
    • Potentially expose an option to flip the Image to the left and buttons to the right

Given this new setup, the same example from before now works as follows:

buttons = (
    TitlebarButton(
        text="Getting Started",
        icon=None,
        href="https://nerf.studio",
        variant="outlined",
    ),
    TitlebarButton(
        text="Github",
        icon="GitHub",
        href="https://github.com/nerfstudio-project/nerfstudio",
        variant="outlined",
    ),
    TitlebarButton(
        text="Documentation",
        icon="Description",
        href="https://docs.nerf.studio",
        variant="outlined",
    ),
    TitlebarButton(
        text="Viewport Controls",
        icon="Keyboard",
        href="https://docs.nerf.studio",
        variant="outlined",
    ),
)
image = TitlebarImage(
    image_url="https://docs.nerf.studio/en/latest/_static/imgs/logo.png",
    image_alt="NerfStudio Logo",
    href=None,
)

titlebar_theme = TitlebarConfig(buttons=buttons, image=image)

server.configure_theme(
    canvas_background_color=(2, 230, 230),
    titlebar_content=titlebar_theme,
)

Resulting in a very similar:
image

@jonahbedouch jonahbedouch requested a review from brentyi June 16, 2023 03:16
@brentyi brentyi enabled auto-merge (squash) June 16, 2023 06:30
Copy link
Collaborator

@brentyi brentyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look great, thanks @jonahbedouch! Merging because I want to start resolving conflicts with the mantine PR, but I made some small tweaks to the types and example so if you could double-check that that'd be appreciated. :)

@brentyi brentyi merged commit 1a607ef into main Jun 16, 2023
@brentyi brentyi deleted the jonah/titlebar branch June 16, 2023 06:35
yzslab pushed a commit to yzslab/viser that referenced this pull request Oct 20, 2024
…io-project#42)

* Introduce base titlebar component without functionality

Co-authored-by: Abhik Ahuja <[email protected]>

* Implement button, image, and padding insertion without backend

Co-authored by: Abhik Ahuja <[email protected]>

* Implement Python Interface for toggling Navbar and adding Buttons, Images, or Padding

Co-authored by: Abhik Ahuja <[email protected]>

* Introduce base titlebar component without functionality

Co-authored-by: Abhik Ahuja <[email protected]>

* Implement button, image, and padding insertion without backend

Co-authored by: Abhik Ahuja <[email protected]>

* Implement Python Interface for toggling Navbar and adding Buttons, Images, or Padding

Co-authored by: Abhik Ahuja <[email protected]>

* Resolve Build Warnings in Python

Co-authored-by: Abhik Ahuja <[email protected]>

* Resolve Formatting Issues

Co-authored-by: Abhik Ahuja <[email protected]>

* Introduce base titlebar component without functionality

Co-authored-by: Abhik Ahuja <[email protected]>

* Implement button, image, and padding insertion without backend

Co-authored by: Abhik Ahuja <[email protected]>

* Implement Python Interface for toggling Navbar and adding Buttons, Images, or Padding

Co-authored by: Abhik Ahuja <[email protected]>

* Introduce base titlebar component without functionality

Co-authored-by: Abhik Ahuja <[email protected]>

* Implement button, image, and padding insertion without backend

Co-authored by: Abhik Ahuja <[email protected]>

* Implement Python Interface for toggling Navbar and adding Buttons, Images, or Padding

Co-authored by: Abhik Ahuja <[email protected]>

* Resolve Build Warnings in Python

Co-authored-by: Abhik Ahuja <[email protected]>

* Resolve Formatting Issues

Co-authored-by: Abhik Ahuja <[email protected]>

* Add Support for TypedDicts to the Typescript Type Syncer
Co-authored-by: Abhik Ahuja <[email protected]>

* Update Titlebar Interface to rely on a fixed layout consisting of buttons and an optional focus image
Co-authored-by: Abhik Ahuja <[email protected]>

* Add docstrings to titlebar config objects

Co-authored-by: Abhik Ahuja <[email protected]>

* Remove old Titlebar interface from _message_api.py

Co-authored-by: Abhik Ahuja <[email protected]>

* Delete viser/.vscode directory

* Move theming to separate example

* Tweak types

* Run ruff

---------

Co-authored-by: Abhik Ahuja <[email protected]>
Co-authored-by: Brent Yi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants