<commit_before>"
A RTFlowLayout arrange elements in a rectangle including space (gapSize) between them, ideally it give you a square if all elements have an equal height and width .

"
Class {
	#name : #RSFlowLayout,
	#superclass : #RSAbstractFlowLayout,
	#category : #'Roassal3-Layouts-Core'
}

{ #category : #hook }
RSFlowLayout >> doExecute: elements [ 
	| x y maxLastLineHeight maxNextLineHeight  nextElement |
	
	x := self gapSize.
	y := self gapSize.
	maxLastLineHeight := 0.
	maxNextLineHeight := 0.
	nextElement := elements first.
	
 	elements do:
		[ :anElement | 
		(anElement = elements last) ifFalse:  [nextElement := (elements after: anElement)] ifTrue: [nextElement := anElement].	

		self isAlignBottom ifTrue: [ 
			translator translateBottomLeftOf: anElement to: x @ y.
			x := x + anElement width + (self gapSize).
			((x > (self maxWidth rsValue: elements)) | ((x + nextElement width) > (self maxWidth rsValue: elements) )) ifTrue:
				[ x := self gapSize.
				maxNextLineHeight := self maxNextLineHeightFrom: nextElement for: elements.
				y := y + (self gapSize) + maxNextLineHeight.
				maxNextLineHeight := 0.
				]
			].
		
		self isAlignCenter ifTrue: [ 
			translator translateCenterLeftOf: anElement to: x @ y.
					
			x := x + (anElement width) +(self gapSize).
			maxLastLineHeight := maxLastLineHeight max: (anElement height).
			((x > (self maxWidth rsValue: elements)) | ((x + nextElement width) > (self maxWidth rsValue: elements) )) ifTrue: 
				[ x := self gapSize.
				maxNextLineHeight := self maxNextLineHeightFrom: nextElement for: elements.
				y := y + (self gapSize) + (maxNextLineHeight / 2) + (maxLastLineHeight / 2).
				maxNextLineHeight := 0.
				maxLastLineHeight := 0.
				]
			].
		
		self isAlignTop ifTrue: [ 
			translator translateTopLeftOf: anElement to: (x @ y).
			x := x + anElement width + (self gapSize).
			maxLastLineHeight := maxLastLineHeight max: (anElement height ).
			( (x > (self maxWidth rsValue: elements)) | ((x + nextElement width) > (self maxWidth rsValue: elements) ))ifTrue: 
				[ x := self gapSize.
				y := y + (self gapSize) + maxLastLineHeight.
				maxLastLineHeight := 0. 
				]
		] 
	]
]

{ #category : #'initialize-release' }
RSFlowLayout >> initialize [
	super initialize.
	self alignTop.
]

{ #category : #utility }
RSFlowLayout >> maxNextLineHeightFrom: ele for: elements [
	| nextLineX maxNextLineHeight anElement |
	maxNextLineHeight := 0.
	nextLineX := self gapSize.
	anElement := ele.
	[ nextLineX < (self maxWidth rsValue: elements) ] whileTrue: [
		nextLineX := nextLineX + (self gapSize) + (anElement width).
		maxNextLineHeight := maxNextLineHeight max: (anElement height).	
		(anElement = elements last) ifFalse:  [anElement := (elements after: anElement) ].
		].
	^ maxNextLineHeight
				
]<commit_msg>update for RSFlowLayout for labels a new experimental method<commit_after>"
A RTFlowLayout arrange elements in a rectangle including space (gapSize) between them, ideally it give you a square if all elements have an equal height and width .

"
Class {
	#name : #RSFlowLayout,
	#superclass : #RSAbstractFlowLayout,
	#category : #'Roassal3-Layouts-Core'
}

{ #category : #alignment }
RSFlowLayout >> alignLabel [
	alignment := #label
]

{ #category : #hook }
RSFlowLayout >> doExecute: elements [

	| x y maxLastLineHeight maxNextLineHeight nextElement maxWidthFloat |
	x := self gapSize.
	y := self gapSize.
	maxLastLineHeight := 0.
	maxNextLineHeight := 0.
	nextElement := elements first.
	maxWidthFloat := self maxWidth rsValue: elements.
	elements doWithIndex: [ :anElement :index | 
		nextElement := index = elements size
			ifTrue: [ anElement ]
			ifFalse: [ elements at: index + 1 ].

		self isAlignBottom ifTrue: [ 
			translator translateBottomLeftOf: anElement to: x @ y.
			x := x + anElement width + self gapSize.
			
			x > maxWidthFloat | (x + nextElement width > maxWidthFloat) ifTrue: [ 
				x := self gapSize.
				maxNextLineHeight := self
					maxNextLineHeightFrom: index + 1
					for: elements.
				y := y + self gapSize + maxNextLineHeight.
				maxNextLineHeight := 0 ] ].

		self isAlignCenter ifTrue: [ 
			translator translateCenterLeftOf: anElement to: x @ y.

			x := x + anElement width + self gapSize.
			maxLastLineHeight := maxLastLineHeight max: anElement height.
			x > maxWidthFloat | (x + nextElement width > maxWidthFloat) ifTrue: [ 
				x := self gapSize.
				maxNextLineHeight := self
					maxNextLineHeightFrom: index + 1
					for: elements.
				y := y + self gapSize + (maxNextLineHeight / 2) + (maxLastLineHeight / 2).
				maxNextLineHeight := 0.
				maxLastLineHeight := 0 ] ].
		alignment = #label ifTrue: [ 
			anElement position: x @ y + (anElement extent / 2) + (0 @ anElement textExtents y_bearing).

			x := x + anElement width + self gapSize.
			maxLastLineHeight := maxLastLineHeight max: anElement height.
			x > maxWidthFloat | (x + nextElement width > maxWidthFloat) ifTrue: [ 
				x := self gapSize.
				maxNextLineHeight := self
					maxNextLineHeightFrom: index + 1
					for: elements.
				y := y + self gapSize + (maxNextLineHeight / 2) + (maxLastLineHeight / 2).
				maxNextLineHeight := 0.
				maxLastLineHeight := 0 ] 
			 ].
		self isAlignTop ifTrue: [ 
			translator translateTopLeftOf: anElement to: x @ y.
			x := x + anElement width + self gapSize.
			maxLastLineHeight := maxLastLineHeight max: anElement height.
			x > maxWidthFloat | (x + nextElement width > maxWidthFloat) ifTrue: [ 
				x := self gapSize.
				y := y + self gapSize + maxLastLineHeight.
				maxLastLineHeight := 0 ] ].

	]
]

{ #category : #'initialize-release' }
RSFlowLayout >> initialize [
	super initialize.
	self alignTop.
]

{ #category : #utility }
RSFlowLayout >> maxNextLineHeightFrom: index for: elements [
	| nextLineX maxNextLineHeight anElement maxWidthFloat i |
	maxNextLineHeight := 0.
	nextLineX := self gapSize.
	i := index min: elements size.
	anElement := elements at: i.
	maxWidthFloat := self maxWidth rsValue: elements.
	[ nextLineX < maxWidthFloat ] whileTrue: [
		nextLineX := nextLineX + self gapSize + anElement width.
		maxNextLineHeight := maxNextLineHeight max: anElement height.
		i = elements size
			ifFalse: [ anElement := elements at: (i := i + 1) ].
		].
	^ maxNextLineHeight
]
{'fraction_non_alphanumeric': 0.10886967659301953, 'fraction_numerical': 0.004963176432917067, 'mean_word_length': 3.5300942712110226, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7380411', 'n_tokens_mistral': 2234, 'n_tokens_neox': 1958, 'n_words': 600}