pharo-graphics / Toplo

A widget framework on top of Bloc
MIT License
19 stars 9 forks source link

Tooltip model is based on blockClosure outside context #207

Open Nyan11 opened 1 month ago

Nyan11 commented 1 month ago

The tooltips in are managed by the trait TToElementWithTooltip.

When you add a tooltip, you use one of the following methods:

All the methods use the tooltipContent:. Here is the source code of tooltipContent:.

tooltipContent: anElement

    anElement ifNil: [
        self removeTooltipWindowManager.
        ^ self ].
    self tooltipBuilder: [ :win :requestEventt |
        win root addChild: anElement ]

anElement here is the BlElement we want to display in the tooltip. The element is not added directly in a "tooltip model" but as an outter context variable of a blockClosure.

The advantage of having a BlockClosure is that you can generate on the fly the content of the tooltip. This effect could be achieve by adding new event for tooltip:

plantec commented 1 month ago

the benefit of current implementation is that is is stateless one can store the element in the user data maybe

Nyan11 commented 1 month ago

Why being stateless is a benefit ?

plantec commented 1 month ago

the trait is used by ToElement level as TToElementWithContextMenu so, I guess one have to limit the number of inst variables for a ToElement.

plantec commented 1 month ago

" The advantage of having a BlockClosure is that you can generate on the fly the content of the tooltip. " yes, exactly

"This effect could be achieve by adding new event for tooltip: An event that is trigger just before the tootltip is shown. We could add an event that trigger after the tooltip is hidden in order to manage the destruction of the generated content." I don't get what you mean

Nyan11 commented 1 month ago

I try to explain 2 things:

first

What i try to explain is that you could have the same on the fly generation with events. If you have an event that is trigger before the popup become visible, you could use the event to modify the content of the popup.

Pros of using events is:

Cons of using events is:

If we choose to use BlEventHandler to manage the tooltips we could add events when the tooltip is not yet visible, when the tooltip is visible, when the tooltip is about to be hidden and when the tooltip is hidden.

You could use all this event to manage the panel inside the tooltip. For example:

second

The current implementation of tooltip in Toplo relies on BlockClosure with an outside context.

tooltipContent: anElement

    anElement ifNil: [
        self removeTooltipWindowManager.
        ^ self ].
    self tooltipBuilder: [ :win :requestEventt |
        win root addChild: anElement ]

anElement is a reference inside the BlockClosure ([ :win :requestEventt | win root addChild: anElement ]) and also the arguments of the method (tooltipContent: anElement).

This create high complexity for Pyramid or serialization.

Conclusion

I really do not like the BlockClosure, it is difficult to manage with the serialization and with Pyramid.

I personally think that a block closure add hidden states to the UI that cannot be seen while reading the code.

I would like to have simple Object with a simple API to manage my UI and not a BlockClosure that can do everything.

But maybe there are strong arguments in favor of BlockClosure that i do not see yet.

tinchodias commented 4 weeks ago

@Nyan11 what are the serializer(s) that Pyramid uses to serialize?

I'm analysing a possible solution in Fuel using "clean" blocks. But not sure if you use Fuel.

Nyan11 commented 3 weeks ago

Hello,

I used a custom one that generate executable code: https://github.com/Nyan11/Stash It is inspired from STON.

Currently i only check if the block closure is clean before serializing it. If it is not, i raise an Error.