Skip to content

Fixing RadioButton layout #227

Open
Open
@sebpiq

Description

@sebpiq

Hey !

I am working with nexusUI these days and still loving it after all these years (thanks @taylorbf ;) )

The RadioButton introduces some undesired horizontal padding when the width is not a multiple of the height.

Screenshot from 2023-03-07 13-01-19

This is because the button's dimensions are configured like so :

var buttonWidth = this.width / (orientation === "vertical" ? 1 : this._numberOfButtons);
var buttonHeight = this.height / (orientation === "vertical" ? this._numberOfButtons : 1);

for (var i = 0; i < this._numberOfButtons; i++) {
	this.buttons[i].resize(buttonWidth, buttonHeight);
}

I'd suggest taking the min of (width, height) instead :

var buttonWidth = this.width / (orientation === "vertical" ? 1 : this._numberOfButtons);
var buttonHeight = this.height / (orientation === "vertical" ? this._numberOfButtons : 1);
var buttonSize = Math.min(buttonWidth, buttonHeight)

for (var i = 0; i < this._numberOfButtons; i++) {
         this.buttons[i].resize(buttonSize, buttonSize);
}

And then, setting the container's display to flex :

buildFrame: {
        value: function buildFrame() {
                this.element = document.createElement("div");
                this.element.style.display = 'flex'
                this.element.style.flexDirection = 'row' // or 'column' if vertical
                this.element.style.justifyContent = 'space-between'
                this.parent.appendChild(this.element);
        }
},

Then it looks like this :

Screenshot from 2023-03-07 13-06-01

I'd submit a pull request, but don't know the lib so well, and wanted to submit the idea first anyways ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions