coffee icon indicating copy to clipboard operation
coffee copied to clipboard

Scrollable widget support

Open hecrj opened this issue 5 years ago • 1 comments

Scrolling is quite a basic feature for a UI toolkit. We need it!

I see two different approaches to tackle this:

  1. Draw the scrollable contents into a Canvas. The issue is that we would need to recreate it once the scrollable changes dimensions. We could circumvent this initially by forcing users to set a fixed width and height for scrollables. However, this destroys the purpose of a responsive UI. Another approach could be simply avoid resizing the Canvas every frame while resizes happen, and only do it at a specific rate. Although this would cause the UI to not resize smoothly, it could be good enough for now.
  2. Implement scissor test support for Target. This sounds way more elegant, but it entails more work as we will have to add scissor support for all the current pipelines (quads and font rendering). It should be doable, but it needs to be done carefully.

In both scenarios, Widget::draw definition will probably need to change to improve composability and recursive draws (scrollables inside scrollables). Although I think a tree-like data structure stored in Renderer could work too.

Any other ideas?

hecrj avatar Jun 10 '19 11:06 hecrj

Triangles can be cropped to fit the rectangle. If you are collecting all vertices into batch and drawing them then you can just pass them trough cropping algorithm that will calculate new vertex and texture positions based of view rectangle. Assuming all objects inside ui can be represented by rectangles (AABB) when being drawn.

jakubDoka avatar Jul 19 '21 14:07 jakubDoka