globaltcad / swing-tree

A small DSL library for building Swing UIs
MIT License
6 stars 0 forks source link

ScrollConfig #102

Closed Mazi-S closed 1 week ago

Mazi-S commented 3 months ago

Currently, if the content of a scrollPane' implements theScrollable' interface and you change the behavior of how the content is scrolled, the changed behavior is applied only if no add config was specified when the content was added:

The specified behavior is applied.

.add(GROW, scrollPane()
    .add(content)
)

The specified behavior is NOT applied.

.add(GROW, scrollPane()
    .add("", content)
)

I think it would be nice to allow both (AddConstraint and define how the content should be scrolled).

The following would be a good approach, and would also eliminate the need to implement the `Scrollable' interface every time you want to define the behavior.

.add(GROW, scrollPane()
    .withConfig(scrollConfig -> scrollConfig
        .forceContentWidthMatchViewportWidth(true)
    .add("", content)
)
Gleethos commented 1 month ago

I suggest making this configurable through an overload of the UI.scrollPane() factory method, which currently does not have any other overloads and offers itself very well for this sort of config... This would also make it consistent with other factory methods, ike for example the UI.table(Configurator) method where you can build the table model using the configurator lambda.

So I I'd imagine this to look like this:

.add(GROW, 
    scrollPane( conf -> conf 
        .prefSize( it -> it.component().getPreferredSize() )
        .scrollIncrement( it -> 42 )
        .fitWidth( it -> true )
        .fitHeight( it -> false )
    )
)

...where it is a delegate object for the Scrollable component (we could call it ScrollableComponentDelegate) as well as some useful context information like for example:

Gleethos commented 1 month ago

I did a proof of concelt implementation of this. Since you have alreay worked with the Scrollable interface and how it works, can you check out the implementation and check if it has the expected behaviour?