Jump to content




Gopher's APIs - Old, and broken, but still good. Yah. Still good.

api

  • You cannot reply to this topic
83 replies to this topic

#61 Jan

  • Members
  • 141 posts
  • Locationthe Netherlands

Posted 17 March 2013 - 04:03 AM

View PostGopherAtl, on 17 March 2013 - 03:00 AM, said:

But of course it has keyboard support! b&w support would be silly if it didn't :) And I actually plan on adding an on-screen keyboard for touch-screen monitors, but have not done so yet.

Focusable elements (currently buttons and text fields) are automatically added to a tab group in the order they're created, which you can cycle through with up/down, left/right (not with text fields, which capture these for cursor movement), and tab. You can also override this tab order, setting up a different tab order manually using functions - the redstone sample program demonstrates this.
Okay, great :D

#62 Fenthis

  • Members
  • 13 posts

Posted 15 May 2013 - 06:27 PM

ggui is absolutely awsome. One question: is there a way to register custom event handlers for events that the UI does not handle? Say I want to have a handler for the Misc Peripheral's sort-event running in the background. Also, can a co-routine modify the UI and somehow tell it to redraw, if I chose to do that as a background process?

#63 GopherAtl

  • Members
  • 888 posts

Posted 21 May 2013 - 05:36 PM

been quite busy for a while, first time on here, or even thinking about minecraft, in over a month... not sure I'll be particularly active in the immediate future either. While I'm here...

Fenthis: You can call addEventHandler functions to handle ANY events, not just ggui-specific events. For example, the login sample program has this listener line:

guiScreen.addEventHandler(  {"button_activate", guiScreen.id, loginButton} ,  onLogin  )
which calls the onLogin function (defined in the example) when an event "button_activate" occurs, where it's first argument equals guiScreen.id (the id of the screen) and the second argument is loginButton, the id of the login button. You could just as easily do something like this:

local onRednetMessage(event,modemSide, senderChannel, replyChannel, message, senderDistance)
  --//yer code here
end

guiScreen.addEventHandler(  {"modem_message" } ,  onRednetMessage )

This would cause onRednetMessage to be called every time a modem_message event occurs. This can also be used with any custom event types, sent by your code or other APIs using os.queueEvent(). Thanks to this system, many common things you might be tempted to do with coroutines, you can do without coroutines, using only event handlers. (my past APIs and programs had been rather coroutine-heavy, something I made a deliberate effort to move away from with the ggui api, because coroutines are resource-intensive in luaj)

If you do have background coroutines, I can't think of any reason that any number of coroutines can't modify the ggui at the same time, as long as they have a way to access the same gui objects, which they should if the coroutines are defined in the same program.

#64 GopherAtl

  • Members
  • 888 posts

Posted 17 July 2013 - 12:12 AM

found and fixed two minor bugs...

goroutines - background processes were crashing if they attempted to print or do certain other terminal i/o ops
redirect - can now correctly create black and white buffers on color computers. Before, it would always promote it to color if you were on an advanced computer.

#65 CoderPuppy

  • Members
  • 121 posts

Posted 30 August 2013 - 01:05 PM

Bug: Labels are constrained to a single line. This is because makeLabelString constrains the entire string's length to the width of the label. It could easily be fixed by looping through the lines and constraining each to the width.

Edit: Also I want to be able to override the ggui event handlers. Example: Override left and right key handlers to switch between menus.
Edit: Also can I hide/remove elements.

#66 GopherAtl

  • Members
  • 888 posts

Posted 30 August 2013 - 02:24 PM

that is not a bug, just a design choice. If labels wrapped to multiple lines, it could cause problems with automatic resizing of screens in some cases. It's not ready for release yet, but I've been working on ggui, and just added textArea components, which are multi-line, can scroll vertically, are word-wrapped, and can be either read-only or editable. Those will be what you want.

As for overriding the event handlers, hmm. I might be able to add the ability to override key event handlers, I'll have to think about the best way to implement it for a bit. Your specific use case sounds like you want a more robust form of navigation besides the basic tab ordering it uses now, which is something I've been contemplating improving as well.

re: hiding or removing elements, at present, no. I don't think I'll be allowing removing elements at all, but I will probably add enabling/disabling elements, and I certainly plan on adding page stacks, which will allow most forms of dynamic gui alteration you might want - page stacks are basically tab groups, without the tabs (which are just a menu of buttons for selecting pages anyway)

Not sure how many features will make it into the next update, but certainly TextAreas will, and probably frames, scroll bars, and with luck, list boxes as well. Various forms of pop-ups (menus, pull-downs, dialog boxes, etc) will happen eventually but are unlikely in the next update.

#67 Kermina

  • Members
  • 4 posts

Posted 02 September 2013 - 01:54 PM

Hi, at first I want to thank you for your redirect API. I have altered it to my needs and it works great.

But I find a bug that nobody seems to spot. It cause edit (and posibly other programs) to crash.
On line 15 of your redirect API you have:
if cx<=buffer.width then
Problem is that edit, when text is scrolled horizontaly, sets cursor x value to negative number and writes from that position.
To fix this problem simply alter line 15 to:
if cx >= 1 and cx<=buffer.width then

Since many use your redirect API, this secret flaw may cause probably big (and very rare) problems for many programs and shells. So if you know who use your redirect API, please tell them.

Thanks for all your work on these APIs.

#68 GopherAtl

  • Members
  • 888 posts

Posted 03 September 2013 - 11:35 AM

Ah! Thanks for that. I'll make that fix to the pastebin version now, thanks. Funny, I'm positive I ran into, and fixed, that bug once before. This is what I get for not using any sort of version control on my cc lua projects.

#69 CoderPuppy

  • Members
  • 121 posts

Posted 04 September 2013 - 10:39 PM

What does the "Ch" mean in "leftCh" for the ggui styles?

#70 ElvishJerricco

  • Members
  • 803 posts

Posted 04 September 2013 - 11:56 PM

Would like to note for ctrlkeys, you can check for shift better by seeing if the letter is capital or not. Something like bshift = char:upper() == char. Probably won't work for stuff like semicolons and stuff though unless you map out every char and it's respective shifted char, which can vary by keyboard.

#71 GopherAtl

  • Members
  • 888 posts

Posted 05 September 2013 - 06:17 AM

CoderPuppy: Character. They are characters drawn on to the left and right of the element, and the Focused variants are drawn only when the element has focus. Only supported by buttons and text fields, I think? leftChFocused and rightChFocused are the only ones used in the default style, I think, to add "[" and "]" surrounding buttons and text fields when they are selected, and that only in the monochrome style.

Elvish: Ehrum. When ctrl is held down, you don't get char events. That's kindof how ctrlkeys works in the first place. :)

Tho I should note that I've learned ctrlkeys doesn't work in an entirely consistent way between operating systems, there's inconsistencies at least with ctrl+v and ctrl+1 through ctrl+0 on osx vs windows.

#72 ElvishJerricco

  • Members
  • 803 posts

Posted 05 September 2013 - 09:45 AM

View PostGopherAtl, on 05 September 2013 - 06:17 AM, said:

Elvish: Ehrum. When ctrl is held down, you don't get char events. That's kindof how ctrlkeys works in the first place.

Oh brainderp. My bad.

#73 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 07 September 2013 - 05:08 PM

Hey, I'm experiencing a bug with this. When I use Goroutine along with the redirect thing, I can't use paintutils inside of my redirect.
edit: forgot I wasn't using the redirect with what I was doing. The bug is sitll there, not sure if it happens when you use redirect.

#74 GopherAtl

  • Members
  • 888 posts

Posted 07 September 2013 - 07:02 PM

I'd have to see some code, I can't think of any reason one particular api would become inaccessible?

#75 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 05 October 2013 - 10:56 AM

By the way, is there any way to have a goroutine pause itself, like the default coroutine's yield? I'm trying to make advanced ram and cpu management, so one program can run while the other ones are frozen, then unfreeze the others when the user wants to instantly.
Also: I'm very impressed how goroutines can kill an event running an app--even shell-- and the app quits aswell. Nice work there.

#76 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 October 2013 - 02:00 AM

I'm not sure what you mean. Coroutine.yield() or anything that wraps it should cause goroutines to yield in the same way. It would be up to you to make sure not to resume them until you wanted to.

#77 jay5476

  • Members
  • 289 posts

Posted 26 October 2013 - 11:02 PM

the cursor blink after an error is red... but still writes whatever color you previously had

#78 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 28 October 2013 - 09:50 AM

Please provide complete reproduction instructions.

#79 Symmetryc

  • Members
  • 434 posts

Posted 22 November 2013 - 11:03 PM

Ctrl Keys seems a bit overly complex, couldn't you just do something like this?
local pullEvent = function(_filter)
    local t = {}
    while t[1] ~= (_filter or t[1] or 0) do
        t = {os.pullEvent()}
        t[1] = t[1] == "key" and (os.startTimer(0) == ({os.pullEvent()})[2] and "ctrl_key" or os.pullEvent() and t[1]) or t[1]
    end
    return unpack(t)
end

Or am I just missing something?

Edit: I've updated the code, but I can see that it has some problems; You can't pull events more than about 6 or 7 times a second, otherwise it may mistake ctrl_keys as normal keys :/.

Edited by Symmetryc, 23 November 2013 - 09:04 AM.


#80 Magik6k

  • Members
  • 29 posts

Posted 24 November 2013 - 09:23 AM

Awesome work! I'm definitely going to put these API's to my operating system.
Is there any limit for number of tasks created with goroutines?





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users