[solved] two [grid] tags

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

User avatar
ZombieKnight
Posts: 217
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: two [grid] tags

Post by ZombieKnight »

Thanks, I couldn't find the .on_modified. I'll report back after lunch...
Any idea how to resize/make the text_box transparent?
I haven't found any mainline uses of that.
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
ZombieKnight
Posts: 217
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: two [grid] tags

Post by ZombieKnight »

Jup

Code: Select all

dialog.test_text.on_modified=function()
   if dialog.test_text.text == " " then dialog:close() end
   dialog.test_text.text =""
end
works
...
Any idea why:
'dialog.test_text.on_left_click = function() dialog:close() end'
Doesn't work and break the white_haired_uncle's code?
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
ZombieKnight
Posts: 217
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: two [grid] tags

Post by ZombieKnight »

For the resize and making it invisible...
What is that?
https://devdocs.wesnoth.org/classgui2_1 ... ce9225c0ab
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
Celtic_Minstrel
Developer
Posts: 2255
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: two [grid] tags

Post by Celtic_Minstrel »

ZombieKnight wrote: April 27th, 2024, 7:42 am Thanks!
Oh dumb me, this works "dialog.test_text:focus()"
Yes – either that or "gui.widget.focus(dialog.test_text)".
ZombieKnight wrote: April 27th, 2024, 7:43 am I use

Code: Select all

dialog:set_canvas(1, { } )
To hide the label background...Any idea how to hide text_box background?
Just to clarify, that doesn't hide it. It deletes it. There's no difference though as long as you don't want it back later.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
ZombieKnight
Posts: 217
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: two [grid] tags

Post by ZombieKnight »

Oh, good to know!
How to delete any image of text_box?
I had saurian in profile before, but I've merged my discord profile with forum one...
white_haired_uncle
Posts: 1239
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: two [grid] tags

Post by white_haired_uncle »

Here is an invisible text box that will capture keyboard input:

Code: Select all

local T = wml.tag
local chat = wesnoth.interface.add_chat_message
local sf = string.format

function wesnoth.wml_actions.stacked_widget_gui()
        local dialogDefinition = {
                wml.tag.tooltip { id = "tooltip_large" },
                wml.tag.helptip { id = "helptip_large" },
                wml.tag.grid {  wml.tag.row { wml.tag.column {
                        wml.tag.stacked_widget {
                                id = "stacker",
                                definition = "default",
                                T.layer {
                                        T.row { T.column { T.label { id="my_label1",label = "Hello world" } } }
                                },
                                T.layer {
                                        T.row { T.column { T.text_box { id="my_tb" } } }
                                }
                        }
                } } },
        }

        local function preshow(dialog)
--              wesnoth.print_attributes(dialog.stacker)
        --      gui.show_lua_console()
        --
                dialog.stacker.my_label1.visible = true
                dialog.stacker.my_tb.visible = false
                dialog.my_tb:focus()
                dialog.my_tb.on_modified = function()
                        chat(sf("Text box contains %s",tostring(dialog.my_tb.text)))
        --              dialog.my_tb.on_left_click = function()
        --                      dialog:close()
        --              end
                --dialog.stacker.visible = false
                end
        end
        gui.show_dialog(dialogDefinition,preshow)
end
When I add the on_left_click I can close the gui with a left click, but it also closes if I type more than one key. If all you're really trying to do is make it really easy to close the gui (which you also can't otherwise interact with), I think that would work for you. But I think it might be a bug, as I don't think pressing the letter 'o' (for example) should be handled by on_left_click.

I should test this to see if it is something odd about on_left_click, or (more likely?) an issue with having both callbacks active.
Last edited by white_haired_uncle on April 27th, 2024, 1:54 pm, edited 1 time in total.
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 217
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: two [grid] tags

Post by ZombieKnight »

So I just need to set it to visible = false.
Thanks!

Aaand any idea why my on_left_click isn't working?
I had saurian in profile before, but I've merged my discord profile with forum one...
white_haired_uncle
Posts: 1239
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: two [grid] tags

Post by white_haired_uncle »

I just edited my previous message, adding in on_left_click

Well, I was wrong. I added click_dismiss = true at the top level (next to tooltip/helptip), and that was what was actually causing the left click to close the gui.

It looks like if you set on_left_click on a text_box, it will be called on keyboard input, but NOT from a mouse click (even with no on_modified callback). It I'm right, that's just weird.

Okay, try this. You can use either left click or space bar to close the gui, and the input is invisible:

Code: Select all

function wesnoth.wml_actions.stacked_widget_gui()
        local dialogDefinition = {
                wml.tag.tooltip { id = "tooltip_large" },
                wml.tag.helptip { id = "helptip_large" },
                click_dismiss = true,
                wml.tag.grid {  wml.tag.row { wml.tag.column {
                        wml.tag.stacked_widget {
                                id = "stacker",
                                definition = "default",
                                T.layer {
                                        T.row { T.column { T.label { id="my_label1",label = "Hello world" } } }
                                },
                                T.layer {
                                        T.row { T.column { T.text_box { id="my_tb" } } }
                                }
                        }
                } } },
        }

        local function preshow(dialog)
                dialog.stacker.my_label1.visible = true
                dialog.stacker.my_tb.visible = false
                dialog.my_tb:focus()
                dialog.my_tb.on_modified = function() 
                        if dialog.my_tb.text == " " then dialog:close() end
                        chat(sf("Text box contains %s",tostring(dialog.my_tb.text)))
                end
        end
        gui.show_dialog(dialogDefinition,preshow)
end
Last edited by white_haired_uncle on April 27th, 2024, 2:05 pm, edited 1 time in total.
Speak softly, and carry Doombringer.
User avatar
Ravana
Forum Moderator
Posts: 3038
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: two [grid] tags

Post by Ravana »

That does not match what previously described use case was. You code that after something has been entered, start listening for mouse event. But mouse event callback just does not work anyways https://github.com/wesnoth/wesnoth/issues/8815
User avatar
ZombieKnight
Posts: 217
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: two [grid] tags

Post by ZombieKnight »

I had no idea I could put click_dismiss there.

...

Thanks!
Now I have a working, fully message-like-closing custom_message([narration])
^^ <3
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
Ravana
Forum Moderator
Posts: 3038
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: two [grid] tags

Post by Ravana »

Your latest version does not need callbacks at all. Can be simplified to

Code: Select all

# lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg"))
[lua]
	code=<<
local T = wml.tag
local chat = wesnoth.interface.add_chat_message
local sf = string.format

function wesnoth.wml_actions.stacked_widget_gui()
        local dialogDefinition = {
                wml.tag.tooltip { id = "tooltip_large" },
                wml.tag.helptip { id = "helptip_large" },
                click_dismiss = true,
                wml.tag.grid {  wml.tag.row { wml.tag.column {
                        wml.tag.stacked_widget {
                                id = "stacker",
                                definition = "default",
                                T.layer {
                                        T.row { T.column { T.label { id="my_label1",label = "Hello world" } } }
                                }
                        }
                } } },
        }

        local function preshow(dialog)
        end
        gui.show_dialog(dialogDefinition,preshow)
end

wesnoth.wml_actions.stacked_widget_gui()
>>
[/lua]
User avatar
ZombieKnight
Posts: 217
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: [solved] two [grid] tags

Post by ZombieKnight »

Wait...
All the time all I needed was click_dismiss???
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
ZombieKnight
Posts: 217
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: [solved] two [grid] tags

Post by ZombieKnight »

Got some usefull xp on the way...
But still...
Good to know, thanks!
I had saurian in profile before, but I've merged my discord profile with forum one...
white_haired_uncle
Posts: 1239
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: [solved] two [grid] tags

Post by white_haired_uncle »

"~add-ons/EventLoader/action.cfg" ?
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 217
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: [solved] two [grid] tags

Post by ZombieKnight »

That's what?
I had saurian in profile before, but I've merged my discord profile with forum one...
Post Reply