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:
A new pop-up is instantiated and upcast to a Box<dyn PopUp>
The pop-up is pushed to the app pop-up stack (at the moment just one pop-up can be display at a time)
The app starts a new drawing cicle drawing the new pop-up last
The app produces a rect with the dimensions specified by PopUp::dimensions (currently the dimensions are a percentage)
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
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
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
itThe basic life-cycle of a pop-up is:
Box<dyn PopUp>
PopUp::dimensions
(currently the dimensions are a percentage)PopUp::render
passing the frame and the created rect so the pop-up has freedom to draw it the way it wantsESC
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 anOption
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 heightWhat'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: