Jump to content




GUI.API | Simple & Powerful Buttons,Dialogue Boxes, Text-boxes, and More!

api lua computer

49 replies to this topic

#1 account.username

  • Members
  • 20 posts

Posted 31 May 2014 - 05:45 PM

...GUI API...

(Working on new version as this one is outdated and in bad shape)

/A easy to use tool for making GUI's and more/

Pastebin : qz7KGw3R



Changes:

v 2.4 Fixed a bug with [button]:remove()

v 2.3 Added functions [button]:remove() and [bar]:setup()

v 2.0 Added Dialogue Boxes

v 1.2 Added Text-boxes



Screenshots

Spoiler


Example Code/Documentation


Spoiler


Functions (Better Documentation)

Spoiler

...Note...

Text-boxes are VERY work in progress.

Please leave suggestions and bugs in the replies.

Thanks!


Edited by account.username, 06 June 2015 - 02:13 AM.


#2 Televiewed

  • Members
  • 4 posts

Posted 31 May 2014 - 05:52 PM

This is awesome, I gotta check it out.

#3 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 01 June 2014 - 04:44 AM

Looks really useful!
Maybe this is only on my end, but I couldn't get the images to load.

Since text boxes are WIP anyway, maybe add a height option to them to they can be several lines high.

Also, is it buffered, or do all of the drawing operations happen immediately?

I assume

Quote

Creates a bar with a namevvvvvvvv.
is a typo. (Or maybe a Direwolf20 reference?)

Edited by skwerlman, 01 June 2014 - 04:48 AM.


#4 account.username

  • Members
  • 20 posts

Posted 01 June 2014 - 05:54 AM

@skwerlman Hahah that was a typo (push to talk) and the drawing methods are instant.

#5 newcat

  • Members
  • 43 posts
  • LocationStuttgart, Germany

Posted 05 June 2014 - 07:35 PM

This is pretty awesome, easy to use and cool :D Hopefully you continue developing this api.

Edit: Can you add a function to unregister buttons?

Edited by newcat, 05 June 2014 - 08:13 PM.


#6 account.username

  • Members
  • 20 posts

Posted 06 June 2014 - 01:27 AM

@newcat Yeah Ill add that. Thanks for the awesome suggestion.

#7 Rougeminner

  • Members
  • 151 posts

Posted 06 June 2014 - 04:55 AM

as of right now i only have 2 questions, Can we have a video to explain in a bit further depth and was this made to resemble apple script?

#8 newcat

  • Members
  • 43 posts
  • LocationStuttgart, Germany

Posted 06 June 2014 - 03:17 PM

It seems like there is a bug with the new remove function. Everytime I call this function my program just ends. I did a bit research and noticed that the if statement is never true:
if self.name == buttonList[i][1] then
  table.remove(buttonList,buttonList[i])
  print("Deleting Button")
end
Atleast I never see the text "Deleting Button"...

#9 account.username

  • Members
  • 20 posts

Posted 06 June 2014 - 11:09 PM

@rougeminner Yes I will make a video and frankly I don't know what that is unless you mean the literal Apple Script

@newcat Thank You! I'm fixing that now

#10 account.username

  • Members
  • 20 posts

Posted 06 June 2014 - 11:21 PM

@newcat All fixed in version 2.4

#11 newcat

  • Members
  • 43 posts
  • LocationStuttgart, Germany

Posted 08 June 2014 - 05:39 PM

Thanks for fixing it, it does show the text now so that works. But my program still gets stopped after I use btn:remove(). And if I put the print command after the "end" of the for-loop it doesn't get printed out, so I am assuming that self = nil also doesn't get called. Maybe it is the way I am using the functions:

Spoiler

The text "Deleted" also is not printed.

#12 account.username

  • Members
  • 20 posts

Posted 10 June 2014 - 10:23 PM

@newcat Based on the code you sent you are never calling the function "addItem" which that code is in. That might be your problem.

#13 newcat

  • Members
  • 43 posts
  • LocationStuttgart, Germany

Posted 11 June 2014 - 09:49 AM

View Postaccount.username, on 10 June 2014 - 10:23 PM, said:

@newcat Based on the code you sent you are never calling the function "addItem" which that code is in. That might be your problem.
Actually I do but you can't know that since it is done in the function waitMouse() which I didn't paste here :unsure:
But i figured out that I can just call
btnAdd = nil
and it deletes the reference to the object. I know that it doesn't delete the object itself, so it is not good in terms of memory using, but button:remove() still crashes my program.
I already removed the self = nil for testing purposes, but it still crashes so I assume that the table.remove() is the problem...

My workaround works so far but i think i might get issues when I create another button with the same name...

Edit: This is my waitMouse() function:
function waitMouse(trigger)
  while true do
	local ev,mb,x,y = os.pullEvent("mouse_click")
	if (mb == 1 and gui.detect(x,y, false) ~= nil) then
	  return gui.detect(x,y, trigger)
	end
  end
end
So it's checking if somebody clicked with the left MB on one of the buttons (so basically it's a bit of an extension of your gui.detect() )

Edit2:
While trying your dialogue box I noticed that the button "hitbox" isn't correct. In my try (with table as body) it was 3 pixel too far left, so there was just one pixel which was on the button. The rest of the button was... um... let's say for beauty reasons ;)

Also I now ran into problems with my workaround. But with these problems I noticed a improvement you could do with your button-click-detection. Since it is possible to create overlapping buttons (which is not useful, but I did since I can't remove the old buttons from the detection yet) you may want to check the newest buttons first, because the newest buttons will always be on top of the older.
function detect( x,y,trigger )
  for i = #buttonList,1,-1 do
	-all the stuff here
  end
end

And another thing, just for your documentation, in the function btn:draw() the width is actually the height

I know thats quite much all in all, but please don't take that as criticism, these are all just tips how you can improve your API even further, but still this API is really powerful, easy to use and AWESOME, so please continue this great work!

Edit3:

Just noticed some bugs with your textboxes:
  • When typing a number, it always adds 1 to it. So if i press '1' it writes 2. If I press '9' it writes 10, if i press '0' it writes 11
  • It's not possible to write capital letters yet

Edited by newcat, 11 June 2014 - 02:44 PM.


#14 timia2109

  • Members
  • 71 posts

Posted 11 June 2014 - 10:49 AM

Nice design!
Think I will use it in my next project!

#15 account.username

  • Members
  • 20 posts

Posted 11 June 2014 - 11:29 PM

@newcat Which dialog box type and I think I may have fixed the remove() bug

#16 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 12 June 2014 - 01:09 AM

Ummm, sorry to be dumb, I've never done this before, but do I just use he pastebin link and put GUI. Infront and that it, or is there a special installation for these, is there a video explaining how to use this, I've never used buttons before, so the stuff in closed brackets are cuss right so I can create a button with name one and then draw button and type one in the square brackets?

#17 account.username

  • Members
  • 20 posts

Posted 12 June 2014 - 03:36 AM

@Hbomb_79 I don't quite understand what you're asking. Please clarify (improve grammar and such).

#18 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 12 June 2014 - 04:36 AM

View PostHbomb_79, on 12 June 2014 - 01:09 AM, said:

Ummm, sorry to be dumb, I've never done this before, but do I just use he pastebin link and put GUI. Infront and that it, or is there a special installation for these, is there a video explaining how to use this, I've never used buttons before, so the stuff in closed brackets are cuss right so I can create a button with name one and then draw button and type one in the square brackets?
Firstly, inexperienced/new ~= dumb. Everyone was new to lua/CC once.

Run
pastebin get qz7KGw3R gui
to install it.

In your code, include
os.loadAPI('/gui')
to load it.

Finally, you can just call the API's functions from anywhere after the above line. Make sure to preface them with gui.
e.g.: gui.createButton(<your parameters here>)

More info on os.loadAPI can be found here.

If you still need help, create a topic here. Ask A Pro is generally a better place for an in-depth explanation with Q&A.

Edited by skwerlman, 12 June 2014 - 04:36 AM.


#19 newcat

  • Members
  • 43 posts
  • LocationStuttgart, Germany

Posted 12 June 2014 - 05:12 PM

I used the "ok" dialogue box type.

Btw: There is one d too much at the end of the for-loop in the remove() function ;)

Edit:

I just figured out the problem with button:remove()
After removing the row the table has one row less, but the for-loop will iterate so many times like the table had rows before (sorry for my bad english).

I fixed it like this:
function Buttons:remove()
  for i = 1,#buttonList do
    if self.name == buttonList[i][1] then
	  table.remove(buttonList,i)
	  return true
    end
  end
end

In this case the table stops iterating after it found the right button. You can also do
function Buttons:remove()
  for i = 1,#buttonList-1 do
    if self.name == buttonList[i][1] then
	  table.remove(buttonList,i)
    end
  end
end
But the problem with this version is that it'll delete ALL buttons with the name, with the other version it'll just delete the oldest.

Edited by newcat, 12 June 2014 - 09:05 PM.


#20 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 12 June 2014 - 10:12 PM

Thanks for you answer skwerlman, one more question, how do I use the buttons to call a function once clicked, could someone please give a quick example code.... I have never used an api, also how would I use a dialogue box and check what they clicked on e.g. Like with an if statement...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users