kworkflow / patch-hub

patch-hub is a TUI that streamlines the interaction of Linux developers with patches archived on lore.kernel.org
GNU General Public License v2.0
8 stars 6 forks source link

Feat: PopUps #95

Open OJarrisonn opened 1 week ago

OJarrisonn commented 1 week ago

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:

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:

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: