Skip to content
windwp edited this page May 22, 2022 · 4 revisions

Click on main component

basic.click_test = {
    text = function ()
        return "Click me"
    end,
    click = function ()
        print("Do click")
    end
}

click on child component

you need to wrap it on function make_click and choose a unique name.

local windline = require('windline')
local language = 'EN'

local click_change_language = windline.make_click('change_language', function()
    language = language == 'EN' and 'US' or 'EN'
end)

basic.language = {
    text = function()
        return {
            { 'LANG: ', '' },
            {
                language,
                '',
                click_change_language,
            },
        }
    end,
}

or you can do this

local windline = require('windline')
local language = 'EN'
basic.language = {
    text = function()
        return {
            { 'LANG: ', '' },
            {
                language,
                '',
                windline.make_click('change_language', function()
                    language = language == 'EN' and 'US' or 'EN'
                end),
            },
        }
    end,
}

the first version have better performance. it reduce the complex of text function because child component is create on runtime .

Clone this wiki locally