When creating and rendering a widget a set of information and capabilities must be available such as:
- Writing cells
- Display width, height
- The area to render the widget in
If you want to support animations and collapsing cells you also need:
- The time delta (animations)
- Collapsed borders so blocks can be merged together (collapsing cells)
While these are the most common ones a widget implementer needs, there some more niche ones as well:
- Mouse position
- Cursor position
These are a bit problematic as it would allow users to implement bad widgets where it keeps moving the cursor around and remove control from the widget user. I think that implementations that rely on some state like the cursor position should be handled outside of the widget. So in practice this means the provided argument should not allow the cursor to be moved around.
My main question is: What information should be exposed to a widget as a minimum?
When I say Widget I am referring to a trait and its draw function with the set of information mentioned above as an argument.
Using a trait here allows the users to use dynamic dispatch (Box<dyn Thing>) to implement something like a bunch of swap-able panes of different widgets determined at runtime.
When creating and rendering a widget a set of information and capabilities must be available such as:
If you want to support animations and collapsing cells you also need:
While these are the most common ones a widget implementer needs, there some more niche ones as well:
These are a bit problematic as it would allow users to implement bad widgets where it keeps moving the cursor around and remove control from the widget user. I think that implementations that rely on some state like the cursor position should be handled outside of the widget. So in practice this means the provided argument should not allow the cursor to be moved around.
My main question is: What information should be exposed to a widget as a minimum?
When I say Widget I am referring to a trait and its draw function with the set of information mentioned above as an argument.
Using a trait here allows the users to use dynamic dispatch (
Box<dyn Thing>) to implement something like a bunch of swap-able panes of different widgets determined at runtime.