-
Notifications
You must be signed in to change notification settings - Fork 138
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
Box title alignment support #371
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...n/org/hexworks/zircon/internal/component/renderer/decoration/BoxDecorationRendererTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.hexworks.zircon.internal.component.renderer.decoration | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.hexworks.zircon.api.CP437TilesetResources | ||
import org.hexworks.zircon.api.ComponentDecorations.box | ||
import org.hexworks.zircon.api.Components | ||
import org.hexworks.zircon.api.DrawSurfaces | ||
import org.hexworks.zircon.api.component.renderer.ComponentDecorationRenderer | ||
import org.hexworks.zircon.api.component.renderer.ComponentDecorationRenderer.Alignment.* | ||
import org.hexworks.zircon.api.data.Size | ||
import org.hexworks.zircon.convertCharacterTilesToString | ||
import org.hexworks.zircon.internal.graphics.Renderable | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
|
||
@RunWith(Parameterized::class) | ||
class BoxDecorationRendererTest( | ||
@Suppress("unused") private val testTitle: String, // used by Parameterized for display in IntelliJ/terminal | ||
private val decorator: ComponentDecorationRenderer, | ||
private val expected: String | ||
) { | ||
@Test | ||
fun renderTest() { | ||
val target = Components.panel() | ||
.withTileset(CP437TilesetResources.rexPaint20x20()) | ||
.withDecorations(decorator) | ||
.build() | ||
|
||
val graphics = DrawSurfaces.tileGraphicsBuilder().withSize(Size.create(12, 4)).build() | ||
(target as Renderable).render(graphics) | ||
assertThat(graphics.convertCharacterTilesToString()).isEqualTo(expected.trimIndent()) | ||
} | ||
|
||
companion object { | ||
@Parameterized.Parameters(name = "{index}: {0}") | ||
@JvmStatic | ||
fun data() = listOf( | ||
arrayOf("Default parameters", box(), """ | ||
┌──────────┐ | ||
│ │ | ||
│ │ | ||
└──────────┘ | ||
"""), | ||
arrayOf("With title", box(title = "Foo"), """ | ||
┌┤Foo├─────┐ | ||
│ │ | ||
│ │ | ||
└──────────┘ | ||
"""), | ||
arrayOf("With title, right-aligned", box(title = "Foo", titleAlignment = TOP_RIGHT), """ | ||
┌─────┤Foo├┐ | ||
│ │ | ||
│ │ | ||
└──────────┘ | ||
"""), | ||
// Titlebar is even-sized width, but title is odd-sized, so we're off by half, rounding to the left. | ||
arrayOf("With title, center-aligned, approx center", box(title = "Foo", titleAlignment = TOP_CENTER), """ | ||
┌──┤Foo├───┐ | ||
│ │ | ||
│ │ | ||
└──────────┘ | ||
"""), | ||
arrayOf("With title, center-aligned, exact center", box(title = "Food", titleAlignment = TOP_CENTER), """ | ||
┌──┤Food├──┐ | ||
│ │ | ||
│ │ | ||
└──────────┘ | ||
"""), | ||
arrayOf("With title, bottom left-aligned", box(title = "Foo", titleAlignment = BOTTOM_LEFT), """ | ||
┌──────────┐ | ||
│ │ | ||
│ │ | ||
└┤Foo├─────┘ | ||
"""), | ||
arrayOf("With title, bottom right-aligned", box(title = "Foo", titleAlignment = BOTTOM_RIGHT), """ | ||
┌──────────┐ | ||
│ │ | ||
│ │ | ||
└─────┤Foo├┘ | ||
"""), | ||
arrayOf("With title, bottom center-aligned", box(title = "Foo", titleAlignment = BOTTOM_CENTER), """ | ||
┌──────────┐ | ||
│ │ | ||
│ │ | ||
└──┤Foo├───┘ | ||
""") | ||
) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should have written
this should never happen
😂There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want me to? 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, it is OK.