Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG ?] LinearGradientPaint vertical becomes horizontal for no apparent reason ? #648

Open
Enzo-Demeulenaere opened this issue Nov 18, 2024 · 4 comments

Comments

@Enzo-Demeulenaere
Copy link
Contributor

Hello,

I stumbled across something that looks like a bug to me :

I'm trying to prototype some kind of collapse widget with a small animation to show my element collapsing or not, for now I have the following snippet you can try :

container := BlElement new layout: BlLinearLayout vertical; position: 50 asPoint; constraintsDo: [ :c | 
	c vertical fitContent. c horizontal exact: 250 ]; yourself.

opened := true.

bgPaint := (BlLinearGradientPaint vertical from: Color green to: Color red).

openedAnimation := BlNumberTransition new from: 0; to: 150; duration: 1 second; onStepDo: [ :point | collapsed height: 0 + point ].
closedAnimation := BlNumberTransition new from: 0; to: 150; duration: 1 second; onStepDo: [ :point | collapsed height: 150 - point ].

openCollapsedBlock := [ opened 
	ifTrue: [
		collapsed addAnimation: openedAnimation copy ] 
	ifFalse: [ 
		collapsed addAnimation: closedAnimation copy ] ].

handle := BlTextElement new background: Color lightBlue; size: 250 @ 50; addEventHandlerOn: BlClickEvent do: [ :e | e consume. opened := opened not.
	openCollapsedBlock value];
	text: 'Click here' asRopedText;
	 yourself.

collapsed := BlElement new background: bgPaint ; size: 250 @ 150; border: (BlBorderBuilder new paint: Color red; width: 3; dashed; build); yourself.

container addChild: handle.
container addChild: collapsed.
container openInSpace 

The thing is when clicking a first time the element collapses as intended but when clicking again it finds its original size but the BlLinearGradientPaint became apparently horizontal.

Before :
Capture d’écran 2024-11-18 à 16 04 04

After:
Capture d’écran 2024-11-18 à 16 04 32

Enzo

@Nyan11
Copy link
Contributor

Nyan11 commented Nov 18, 2024

The bug seem to be cause when the height is reduce to 0.
If i do not reduce the height to 0, i do not have the bug.
For example (i added a very small value to the closedAnimation (collapsed height: 150 - point + 0.01)):

container := BlElement new layout: BlLinearLayout vertical; position: 50 asPoint; constraintsDo: [ :c | 
	c vertical fitContent. c horizontal exact: 250 ]; yourself.

opened := true.

bgPaint := (BlLinearGradientPaint vertical from: Color green to: Color red).

openedAnimation := BlNumberTransition new from: 0; to: 150; duration: 1 second; onStepDo: [ :point | 
    collapsed height: 0 + point ].
closedAnimation := BlNumberTransition new from: 0; to: 150; duration: 1 second; onStepDo: [ :point | 
    collapsed height: 150 - point + 0.01 ].

openCollapsedBlock := [ opened 
	ifTrue: [
		collapsed addAnimation: openedAnimation copy ] 
	ifFalse: [ 
		collapsed addAnimation: closedAnimation copy ] ].

handle := BlTextElement new background: Color lightBlue; size: 250 @ 50; addEventHandlerOn: BlClickEvent do: [ :e | e consume. opened := opened not.
	openCollapsedBlock value];
	text: 'Click here' asRopedText;
	yourself.

collapsed := BlElement new background: bgPaint ; size: 250 @ 150; border: (BlBorderBuilder new paint: Color red; width: 3; dashed; build); yourself.

container addChild: handle.
container addChild: collapsed.

container openInSpace 

@Nyan11
Copy link
Contributor

Nyan11 commented Nov 18, 2024

You can debug the original example by:

  1. collapsing the element.
  2. inspecting the bgPaint variable
  3. placing an object centric debug point (break on write) on the #end variable.
  4. open the debug point browser
  5. set the Once option.
  6. re-open the collapsed element.

@rvillemeur
Copy link
Contributor

BlLinearLayout was probably never designed to be used that way, in animation (probably only in fixed size scenario) The size of the background is determined by the size of its BlElement, and updated
through BlLinearLayout >> matchExtent: method. When you collapse your element, it's height will equal 0. When you reopen it, both start and end slots would equals 0, and BlLinearLayout will default to horizontal.

One fix would be for BlLinearLayout to remember its direction, independently of the size of its element, to cover this use case. Another quick fix is to reset its direction when you reopen it like

openCollapsedBlock := [  opened                      
ifTrue: [ bgPaint start: 0 @ 0; end: 0 @ 1. collapsed addAnimation: openedAnimation copy ]                     
ifFalse: [ collapsed addAnimation: closedAnimation copy ] ].

@tinchodias
Copy link
Collaborator

tinchodias commented Nov 18, 2024

This issue is somehow related: #270

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants