Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Tips for Making GUI's Keyboard Accessible (https://forums.graalonline.com/forums/showthread.php?t=134265178)

fowlplay4 12-06-2011 05:39 AM

Tips for Making GUI's Keyboard Accessible
 
The GUI objects are great for creating nice and easy GUIs that are navigate-able by mouse but it doesn't hurt to put in the extra effort to make them accessible by keyboard as well.

If anyone else has any other tips that are listed below feel free to post them, the main purpose of this post was to shed light on an small undocumented section of GS2.

1. Keyboard Shortcuts

For buttons you can make them more 'keyboard accessible' by placing an ampersand (&) before the letter you want it to be made the shortcut key. In Graal just pressing the letter will trigger the shortcut compared to other applications where you have to hold alt and the key.

Example:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
// Create Button with 'X' as Shortcut Key
  
new GuiButtonCtrl("ExitButton") {
    
100;
    
width height 100;
    
text "E&xit";
  }
}

function 
ExitButton.onAction() {
  
// Destroys Button
  // Depending on the GUI toggle visibility instead
  
ExitButton.destroy();
  
// Set Focus Back to Window/Graal
  
GraalControl.makefirstresponder(true);


There's also keyDown, keyUp and other events for controls so you can add custom functionality that way as well.

2. Set focus to the most appropriate control after an event

There isn't a control.setfocus() function for objects but you can accomplish roughly the same effect by using control.makefirstresponder(true);

When you open a window set focus to the most important control they're going to use. I.e: In Zodiac's skill menu it's the skill list control.

Also when you close a window make sure you set focus back to GraalControl (or even the previous window they were on) otherwise it may glitch and require the player to click the screen before they can move again.

iBeatz 12-06-2011 06:22 PM

Thanks for the ampersand explanation. I didn't know this was available in GScript.
I wondered what that was for when I was making a menu in C++.
Nice tutorial though. :)

Edit: Must spread some rep before giving it to you again...

Tricxta 12-06-2011 09:38 PM

what if you want to assign the button to a key in which the letter doesn't exist in the button text. Eg assigning apple to u

Crow 12-06-2011 11:07 PM

Quote:

Originally Posted by Tricxta (Post 1676643)
what if you want to assign the button to a key in which the letter doesn't exist in the button text. Eg assigning apple to u

You'd have to do it your own way then. Could also try creating an invisible button with the same functionality, mapped to U.

MattKan 12-07-2011 12:47 AM

MattKan's Mind: Okay, Gunderak, you're stupid threads aren't helping any- oh wait...

Fulg0reSama 12-07-2011 01:27 AM

Quote:

Originally Posted by MattKan (Post 1676656)
MattKan's Mind: Okay, Gunderak, you're stupid threads aren't helping any- oh wait...

Weird, this is what i was expecting...

http://www.buytumbleweednow.com/wp-c...ll-300x199.jpg

fowlplay4 12-07-2011 01:48 AM

Quote:

Originally Posted by Tricxta (Post 1676643)
what if you want to assign the button to a key in which the letter doesn't exist in the button text. Eg assigning apple to u

How will the player know to press U? To me that just comes off as bad design choice. If I really wanted it to be that way I would use:

text = "Apple [&U]";


All times are GMT +2. The time now is 12:04 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.