Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Utils for distributing views evenly across vertically/horizontally. #615

Merged
merged 1 commit into from
May 4, 2022

Conversation

Kietyo
Copy link
Contributor

@Kietyo Kietyo commented May 2, 2022

Real life example:

	val numbers = container {
		repeat(5) {
			val num = it + 1
			UIButton(BUTTON_WIDTH, BUTTON_HEIGHT, num.toString()).apply {
				onClick {
					if (checkBox.checked) {
						sudokuBoard.applyHint(num)
					} else {
						sudokuBoard.applyNumber(num)
					}
				}
			}.addTo(this)
		}
	}
	distributeEvenlyHorizontally(numbers.children, sudokuBoard.scaledWidth)

image

@soywiz
Copy link
Contributor

soywiz commented May 2, 2022

Nice!

BTW. Are you aware of the uiVerticalStack { },uiHorizontalStack { },uiHorizontalVerticalFill { } etc.?
Before merging I would like to understand if you have tried them and if those would work for you?

Example: https://github.com/korlibs/korge-next/blob/fd5dd1525eacdbf81549257732ffe94e63ad046a/korge-sandbox/src/commonMain/kotlin/MainBlur.kt#L74
You can uncomment this line and execute ./gradlew :korge-sandbox:runJvm: https://github.com/korlibs/korge-next/blob/fd5dd1525eacdbf81549257732ffe94e63ad046a/korge-sandbox/src/commonMain/kotlin/Main.kt#L40

@Kietyo
Copy link
Contributor Author

Kietyo commented May 3, 2022

I've tried them and my biggest pet peeve with them is that they modify the child views themselves, changing their widths and height.

uiHorizontalFill:

image

uiHorizontalStack:

image

Note that the utils I introduce do not change the views width or height. It is very similar to this functionality here in Google Slides:

image

@soywiz soywiz merged commit ffa055f into korlibs-archive:main May 4, 2022
@soywiz
Copy link
Contributor

soywiz commented May 4, 2022

Perfect.

T H A N K S !

:)

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

Successfully merging this pull request may close these issues.

None yet

2 participants