Skip to content

Formspec: Add alignment styles to label[]#16982

Open
CrazyladMT wants to merge 2 commits intoluanti-org:masterfrom
CrazyladMT:add-label-styling
Open

Formspec: Add alignment styles to label[]#16982
CrazyladMT wants to merge 2 commits intoluanti-org:masterfrom
CrazyladMT:add-label-styling

Conversation

@CrazyladMT
Copy link
Contributor

@CrazyladMT CrazyladMT commented Feb 27, 2026

Fixes #7613

Note

I used GPT-5 to partially assist with these changes.

Falls under section 2.3 in the roadmap

Adds support for aligning text in a label[] element by adding two new styles: halign (horizontal alignment) and valign (vertical alignment)

halign can be either one of the following:

  • left
  • center
  • right

valign can be either one of the following:

  • top
  • center
  • bottom
screenshot_20260227_153820

To do

This PR is a Work in Progress.

  • add documentation
  • add examples to test_formspec in devtest?

How to test

  1. Run the test code below
Test code
core.register_chatcommand("test_labels", {
    func = function(name)
        local fs = [[
            formspec_version[6]
            size[11,9]

            box[0.5,2.8;3,1;#222]
            label[0.5,2.8;3,1;Default]

            box[4,2.8;3,1;#222]
            style_type[label;halign=center;valign=center]
            label[4,2.8;3,1;Center/Center]

            box[7.5,2.8;3,1;#222]
            style_type[label;halign=right;valign=bottom]
            label[7.5,2.8;3,1;Right/Bottom]

            # Reset style
            style_type[label;halign=left;valign=top]

            box[0.5,4.2;3,1;#222]
            style_type[label;halign=left;valign=bottom]
            label[0.5,4.2;3,1;Left/Bottom]

            box[4,4.2;3,1;#222]
            style_type[label;halign=center;valign=top]
            label[4,4.2;3,1;Center/Top]

            box[7.5,4.2;3,1;#222]
            style_type[label;halign=right;valign=center]
            label[7.5,4.2;3,1;Right/Center]

            # Reset again
            style_type[label;halign=left;valign=top]

            label[0.5,5.7;Font size tests:]

            box[0.5,6.2;3,1.2;#222]
            style_type[label;font_size=16;halign=center;valign=center]
            label[0.5,6.2;3,1.2;Size 16]

            box[4,6.2;3,1.2;#222]
            style_type[label;font_size=26;halign=center;valign=center]
            label[4,6.2;3,1.2;Size 26]

            box[7.5,6.2;3,1.2;#222]
            style_type[label;font_size=36;halign=center;valign=center]
            label[7.5,6.2;3,1.2;Size 36]

            # Reset styles at end
            style_type[label;halign=left;valign=top;font_size=16]
        ]]

        core.show_formspec(name, "test:labels", fs)
    end
})

@sfan5 sfan5 added Feature ✨ PRs that add or enhance a feature Formspec labels Feb 27, 2026
@siliconsniffer
Copy link
Contributor

Could you also support styling of textarea[] elements? This would help with #16953.

@CrazyladMT
Copy link
Contributor Author

CrazyladMT commented Feb 28, 2026

Could you also support styling of textarea[] elements? This would help with #16953.

I totally overlooked that. Will do :)

@CrazyladMT
Copy link
Contributor Author

Regarding textarea[] styling, should it only be able to be aligned when it is in read-only mode, or edit mode too? I find the latter strange.

@siliconsniffer
Copy link
Contributor

One thing to keep in mind: styling a read-only textarea[] element would only be possible through style-type[] since style[] uses the name for selection.
That being said, I don't think it matters much although I could see centered text in edit mode being used.

@CrazyladMT

This comment was marked as off-topic.

@CrazyladMT
Copy link
Contributor Author

I will leave textarea[] styling for another PR since this PR is about adding styling to labels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature ✨ PRs that add or enhance a feature Formspec

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formspec label alignment

3 participants