Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you set (or clear) the content of an input field? #7

Open
kerabromsmu opened this issue May 9, 2017 · 2 comments
Open

How do you set (or clear) the content of an input field? #7

kerabromsmu opened this issue May 9, 2017 · 2 comments

Comments

@kerabromsmu
Copy link
Contributor

dirtylarry:input() doesn't have a parameter to control the content of input field. I tried to set the text of input_field/content by using gui.set_text(), but it didn't do anything.

@andsve
Copy link
Owner

andsve commented May 18, 2017

I haven't added a function to modify the content of an input field, but it feels like there is some really good uses for it. There was a thread about it in the Defold forums: https://forum.defold.com/t/i-want-to-use-input-in-dirty-larry-gui-solved/5989/2?u=sven

Here is a copy of what was said in the forum post;

Try adding this function below your require statement for dirtylarry;

local dirtylarry = require "dirtylarry.dirtylarry"

function dirtylarry.set_input(self, node, txt)
    local node_content = gui.get_node(node .. "/content")
    local url = msg.url()
    local key = tostring(url.socket) .. hash_to_hex(url.path) .. hash_to_hex(url.fragment or hash("")) .. node
    dirtylarry.input_nodes[key].data = txt
    gui.set_text(node_content, txt)
end

Again, it makes sense to have this function natively in the library, I'll see when I have time to add it, unless you feel the urge to make a PR for it. 🙂

@kerabromsmu
Copy link
Contributor Author

Just created a pull request for that. In the spirit of the rest of the library (as I understand it), the text is set through an extra parameter to the dirtylarry:input() method. The existing Lua code that uses the library should still work without any changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants