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

Feat: PopUps #95

Closed
wants to merge 9 commits into from
Closed

Conversation

OJarrisonn
Copy link
Contributor

This PR is focused on the frontend of patch-hub implementing a PopUp system.

This is still a draft since I'm planning to turn implement a pop-up stack (more explanation below)

The PopUp

PopUp is defined as a trait (this is something @davidbtadokoro and I discussed offline for the future architecture of patch-hub screens) with 3 basic functions:

  • dimensions: defines the dimensions of the pop-up
  • render: draws the pop-up in a rect produced by the app
  • handle: takes care of key events

Since it's a trait, to each new kind of pop-up one must create a type for it and impl PopUp for it

The basic life-cycle of a pop-up is:

  1. A new pop-up is instantiated and upcast to a Box<dyn PopUp>
  2. The pop-up is pushed to the app pop-up stack (at the moment just one pop-up can be display at a time)
  3. The app starts a new drawing cicle drawing the new pop-up last
  4. The app produces a rect with the dimensions specified by PopUp::dimensions (currently the dimensions are a percentage)
  5. The app calls PopUp::render passing the frame and the created rect so the pop-up has freedom to draw it the way it wants
  6. The pop-up being rendered hijacks the key events until it is removed (pressing ESC closes the pop-up)

The Help Pop-Up

This pop-up is both a utility and a blueprint for anyone who needs to create a new pop-up type. It uses a builder to simplify the instantiation. A help pop-up contains:

  • title: displayed in the block of the pop-up
  • description: an optional help description
  • keybinds: a list of pairs of strings representing a key (or a serie of keys) and a short description to what it does

For each screen, I've created a function to simplify the instantiation of a help pop-up to it (in the src/handler/) exactly in the same place where the key events for the screen are defined. I then just added a new key event for the key ? which instantiates a new help pop-up and pushes it to the app "pop-up stack" (it's just an Option atm).

The help pop-up draws all the textual content into a Paragraph and uses movement keys to pan the text around in case it doesn't fit the screen. Currentl the help pop-up consumes 50% of screen width and height

What's next

To complete this PR i just plan to implement an actual pop-up stack in the app but some points that can be worked out in the future for help pop-ups are:

  • Colorize
  • Wrap the lines if they are too long
  • Stop scrolling before the text completly vanishes
  • Size it acording to its content producing a smaller

@OJarrisonn OJarrisonn marked this pull request as ready for review November 14, 2024 01:58
@OJarrisonn OJarrisonn force-pushed the feat/general-popups branch 2 times, most recently from 6f575c7 to bd3aff7 Compare November 14, 2024 02:12
The PopUp trait defines the model for how patch-hub handles PopUps

The app holds an `Option` for the current popup being displayed. The app
renders the popup on top of every component. Also when a popup is being
displayed it hijacks the keyevents (except for the ESC key which always
closes the popup)

A popup implementing PopUp must:

- define its size so the app can produce a centralized Rect for it
- define its rendering method which receives a Rect of the given size
- define how it handles key events

Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
@OJarrisonn OJarrisonn force-pushed the feat/general-popups branch 2 times, most recently from 7ea57d9 to 8cb74f1 Compare November 14, 2024 02:23
The help popup implements the `PopUp` trait and shall be instanced by
each screen to manually define it's help page by listing keybinds, a
title and a description.

Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
Signed-off-by: OJarrisonn <j.h.m.t.v.10@gmail.com>
@th-duvanel
Copy link
Contributor

Nice PR! Great work on the pop up.

@davidbtadokoro
Copy link
Collaborator

Hey @OJarrisonn, thanks so much for this great PR! Change merged into the unstable branch 👍

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.

3 participants