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

Component is sometimes not correctly rendered #268

Open
coldwarrl opened this issue Jan 11, 2020 · 7 comments
Open

Component is sometimes not correctly rendered #268

coldwarrl opened this issue Jan 11, 2020 · 7 comments
Labels
bug Bugs within the program

Comments

@coldwarrl
Copy link
Member

coldwarrl commented Jan 11, 2020

A component is sometimes not correctly rendered

Expected behavior

The component shall be aligned correctly regarding the alignment

Actual behavior

Sometimes the component is cut at the edge of the screen if using the current master of Zircon

Steps to reproduce the bug

Restart the following app a couple of times to reproduce the issue

package org.hexworks.zircon.examples.components


import org.hexworks.zircon.api.CP437TilesetResources
import org.hexworks.zircon.api.ColorThemes
import org.hexworks.zircon.api.Components
import org.hexworks.zircon.api.SwingApplications
import org.hexworks.zircon.api.application.AppConfig
import org.hexworks.zircon.api.component.ComponentAlignment
import org.hexworks.zircon.api.data.Size
import org.hexworks.zircon.api.extensions.box
import org.hexworks.zircon.api.screen.Screen
import org.hexworks.zircon.internal.component.renderer.NoOpComponentRenderer

object PanelsExampleIssue {

    private val theme = ColorThemes.techLight()
    private val tileset = CP437TilesetResources.rexPaint20x20()

    @JvmStatic
    fun main(args: Array<String>) {

        val tileGrid = SwingApplications.startTileGrid(AppConfig.newBuilder()
                .withDefaultTileset(tileset)
                .withSize(Size.create(60, 30))
                .build())

        val screen = Screen.create(tileGrid)


        val component = Components.button()
                .withDecorations(box())
                .withSize(18, 5)
                .withComponentRenderer(NoOpComponentRenderer())
                .withAlignmentWithin(screen, ComponentAlignment.BOTTOM_RIGHT)
                .build()

        screen.addComponent(component)

        screen.display()
        screen.theme = theme

    }
}
@coldwarrl coldwarrl added the bug Bugs within the program label Jan 11, 2020
@coldwarrl coldwarrl changed the title Panel is sometimes not correctly rendered Component is sometimes not correctly rendered Jan 11, 2020
@coldwarrl
Copy link
Member Author

This issue seems only occuring on Ubuntu (and other Linux distros ?) but not on Windows 10.
Also drawing a tile at the bottom, right corner results into the same issue

@coldwarrl
Copy link
Member Author

coldwarrl commented Jan 11, 2020

so I have found a workaround. But it is not nice. But maybe it could be evolved into a real one.

class SwingCanvasRenderer(private val canvas: Canvas,
                          private val frame: JFrame,
                          private val tileGrid: InternalTileGrid,
                          private val config: AppConfig) : Renderer {

    private var firstDraw = true
    private val tilesetLoader = SwingTilesetLoader()
    private var blinkOn = true
    private var lastRender: Long = SystemUtils.getCurrentTimeMs()
    private var lastBlink: Long = lastRender

    private val keyboardEventListener = KeyboardEventListener()
    private val mouseEventListener = object : MouseEventListener(
            fontWidth = tileGrid.tileset.width,
            fontHeight = tileGrid.tileset.height) {
        override fun mouseClicked(e: MouseEvent) {
            super.mouseClicked(e)
            canvas.requestFocusInWindow()
        }
    }

    override fun create() {
        if (config.fullScreen) {
            frame.extendedState = JFrame.MAXIMIZED_BOTH
            frame.isUndecorated = true
        } else {
            frame.setSize(tileGrid.widthInPixels, tileGrid.heightInPixels)
        }

        frame.isVisible = true
        frame.isResizable = true

the last line...I had the suspicion that the swing frame tries to readjust during create and it could not since the resiable is false. With true it seems to work, although now the user could resize the window

But maybe later it could be reset to false, do not know.
the same is true if Zircon is configured runs in full screen
then it works also everytime, regardless of the isResizable.

@adam-arold
Copy link
Member

Seems like a Linux issue, right?

@coldwarrl
Copy link
Member Author

yes, Ubuntu

@nanodeath
Copy link
Contributor

I'm trying to repro this but having some issues now.

image

This is what it looks like for me with Fedora 34. Can you verify this is still an issue, and if so, include a screenshot?

@coldwarrl
Copy link
Member Author

sorry, I have no running ubuntu anymore...so I cannot confirm the status of this issue

@adam-arold
Copy link
Member

adam-arold commented May 3, 2021

Me neither. 😞 This issue might go away if we implement resizeable components though. Alternatively we can say that resizeable is true but we set an equal min and max size. I'm not sure we can do that, we need to take a look at Swing's API.

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

No branches or pull requests

3 participants