Skip to content

Permit scrollbars to be styled#17075

Open
Signal-mt wants to merge 1 commit intoluanti-org:masterfrom
Signal-mt:scrollbar-styling
Open

Permit scrollbars to be styled#17075
Signal-mt wants to merge 1 commit intoluanti-org:masterfrom
Signal-mt:scrollbar-styling

Conversation

@Signal-mt
Copy link
Copy Markdown

@Signal-mt Signal-mt commented Mar 31, 2026

  • Goal of the PR
    • To permit scrollbars in formspecs to be themed.
  • How does the PR work?
    • style and style_type rules can now affect scrollbars in more ways than just noclip. GUIScrollBar is modified to reflect styling properties, and various formspec element classes are modified to pass styling information to their implicit scrollbars. All style properties used by scrollbars are defined already, so there is no change in that regard.
  • Does it resolve any reported issue?
  • Does this relate to a goal in the roadmap?
    • This PR is a prerequisite for a new main menu (2.3), unless it is superseded by a new UI API, though it relates to UI improvements in general.
  • If not a bug fix, why is this PR needed? What usecases does it solve?
    • Among other things, it is now possible to provide a background and thumb image to a scrollbar, tint the default border of a scrollbar, and let the thumb have a fixed size.
  • If you have used an LLM/AI to help with code or assets, you must disclose this.
    • Grok wrote a lot of the test code included below. It also helped me figure out how the source code works, and offered pointers on how C++ works.

To do

This PR is ready for review.

A few questions to consider:

How to test

Create and load a mod with the following code in MTG, then run /scrollbardemo:

local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)

-- Helper to escape formspec strings
local esc = minetest.formspec_escape

-- A long dummy list for scrolling
local function long_list(sep, num)
    local items = {}
    for i = 1, num or 80 do
        table.insert(items, "Line " .. i .. "   • some content • lorem ipsum dolor")
    end
    return table.concat(items, sep or ",\n")
end

local function get_demo_formspec()
    return "formspec_version[6]" ..
    "size[16,10]" ..

    -- 1. Default (no custom style)
    "label[0.2,0.2;1. Default styling.]" ..
    "textarea[0.2,0.6;3.8,4;ta_default;;Some very long text that needs scrolling...\n" ..
        "Line 2\nLine 3\n...\n"..long_list().."]" ..

    -- 2. Custom color + thin size
    "style[ta_color.scrollbar;bgcolor=#ff880044;size=12]" ..
    "textarea[4.2,0.2;3.8,1;;;2. Thin implicit scrollbar, orange tint.]" ..
    "textarea[4.2,1.1;3.8,3.5;ta_color;;Long scrolling content...\n"..long_list().."\n...]" ..

    -- 3. Image track + image thumb (9-slice style)
    "style[ta_image.scrollbar;" ..
        "border=false;" ..
        "bgimg=default_glass.png;" ..
        "bgimg_middle=4;" ..
        "fgimg=default_tree_top.png;" ..
        "fgimg_middle=4;" ..
        "padding=8;" ..
        "size=24]" ..
    "label[8.2,0.2;3.8,1;3. Glass track, 9-slice thumb, padding.]" ..
    "textarea[8.2,1.1;3.8,3.5;ta_image;;" .. long_list("\n", 10) .. "]" ..

    -- 4. Textlist with custom scrollbar (wide purple thumb, arrows styled)
    "style[tl_custom.scrollbar;bgcolor=#aa44ff88;fgimg=default_lava.png;" ..
        "fgimg_middle=6,6,12,12]" ..
    "style[tl_custom.scrollbar.up;fgimg=default_paper.png;bgimg=default_wood.png]" ..
    "style[tl_custom.scrollbar.down;fgimg=default_mese_crystal.png]" ..
    "label[12.2,0.2;3.8,1;4. Textlist, purple tint, images, styled arrows.]" ..
    "textlist[12.2,1.1;3.8,3.5;tl_custom;" .. long_list(",") .. ";1;false]" ..

    -- 5. Explicit scrollbar with arrows=show, thumbsize=0 (square thumb)
    "scrollbaroptions[arrows=show;thumbsize=0]" ..
    "style[explicit_sb;border=false;bgcolor=#4488ff;fgimg=default_mineral_diamond.png]" ..
    "style[explicit_sb.up;border=false;fgimg=default_book.png]" ..
    "scrollbar[0.2,5.2;15,0.6;horizontal;explicit_sb;400]" ..
    "label[0.2,5;5. Explicit horizontal scrollbar (image thumb, borderless, arrow styles).]" ..

    -- 6. Table with custom thin scrollbar
    "style[table_demo.scrollbar;size=10;bgcolor=#88ff4488;bgimg=default_snow.png;border=false]" ..
    "tablecolumns[text;text;text;text]" ..
    "table[0.2,6.2;7.8,3.6;table_demo;" ..
        "Header1,Header2,Header3," ..
        "Cell A1,Cell B1,Cell C1," ..
        "Cell A2,Cell B2 with longer text,Cell C2," ..
        "A3,B3,C3," ..
        long_list(",_,_,") ..
    ";1]"
end

minetest.register_chatcommand("scrollbardemo", {
    description = "Show scrollbar styling demo formspec",
    func = function(name)
        minetest.show_formspec(name, modname .. ":demo", get_demo_formspec())
    end,
})

@Zughy Zughy added @ Script API Feature ✨ PRs that add or enhance a feature Formspec Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it labels Mar 31, 2026
@CrazyladMT
Copy link
Copy Markdown
Contributor

CrazyladMT commented Mar 31, 2026

This is amazing! I tried compiling it to see what problems I could fix, and adding #include "IVideoDriver.h" to the top of guiScrollbar.cpp seems to fix most of the problems

@SmallJoker
Copy link
Copy Markdown
Member

I would prefer to first merge the custom scrollbar code back to the Irrlicht part to deduplicate lots of code. This has been on my TODO list for a while but it seems it's now time to do it.

@sfan5 sfan5 changed the title Permit scrollbars to be styled. Permit scrollbars to be styled Mar 31, 2026
@Signal-mt Signal-mt force-pushed the scrollbar-styling branch from c6c48c2 to 3ed6e7f Compare April 1, 2026 01:42
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 Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it @ Script API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to stylize the scrollbar

5 participants