zircon icon indicating copy to clipboard operation
zircon copied to clipboard

Component is sometimes not correctly rendered

Open coldwarrl opened this issue 5 years ago • 7 comments

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 avatar Jan 11 '20 09:01 coldwarrl

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 avatar Jan 11 '20 18:01 coldwarrl

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.

coldwarrl avatar Jan 11 '20 18:01 coldwarrl

Seems like a Linux issue, right?

adam-arold avatar Jan 11 '20 23:01 adam-arold

yes, Ubuntu

coldwarrl avatar Jan 18 '20 12:01 coldwarrl

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?

nanodeath avatar May 01 '21 16:05 nanodeath

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

coldwarrl avatar May 01 '21 16:05 coldwarrl

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.

adam-arold avatar May 03 '21 17:05 adam-arold