Howto make a tabbed widget in GFA Basic

GFA BASIC-related articles in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

oehansen
Captain Atari
Captain Atari
Posts: 291
Joined: Tue Apr 17, 2012 12:05 pm

Howto make a tabbed widget in GFA Basic

Postby oehansen » Wed Jan 06, 2016 11:24 pm

I want to make a tabbed widget, in GFA ... basically I want to do it this way.

One RSC file, with a few forms. One form holds radio buttons for the tab control, and below an empty box of w,y size. Then other forms, holds boxes of same size with the actual data inside it.

Now, what I want to do is to display box from tree 1, as the box in tree 0. How would I go about to do that ... any ideas?

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Howto make a tabbed widget in GFA Basic

Postby Mikefulton » Thu Jan 07, 2016 7:03 am

This is non-trivial but possible.

First question is, why radio buttons for the tabs? Behavior makes sense but not appearance. Regular buttons might make more sense here. Setting the TOUCHEXIT flag will give you control when they're clicked so you can manipulate the tab pages.

Second thing is, this will be easier with one form, not multiple. Multiple forms would require you to significantly manipulate the resource tree structure and this idea is far more prone to problems.

I think the easiest way to do this is to design a single form with an oversized main box containing everything, such that all of your tab pages will fit side by side, or stacked. Then at runtime, what you need to do is adjust the size of the main box so that it shows just one of the pages under the buttons.

As new tabs are selected, you'll adjust the position of the new tab page to put it under the buttons. Inactive tab pages are reset to original positions. You might also want to set the HIDETREE flag for inactive tab pages and clear it for the current one.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Howto make a tabbed widget in GFA Basic

Postby Mikefulton » Wed Jan 13, 2016 3:15 am

The more I thought about this, the more I thought a sample program demonstrating this idea would be a good way to make sure I've got my dev tools setup properly and that I haven't forgotten too much. So, I've written a simple program that illustrates one method of doing a tabbed dialog box.

I didn't make the dialog box too complicated, but it demonstrates the basic ideas involved. You can see each of the three different tab pages in the sample pic below.

tabbed-gem-dialog.png


The titles are buttons. The first two are sized to be two pixels less wide than normal character-width snapping would do. Without this, you sometimes get glitches with the line between two of them being missing when you switch tabs. The tab pages go underneath the titles.

The tab pages are G_BOXCHAR objects without any character specified. Using a G_BOX should be OK too and in fact is prefered. I just wasn't paying that much attention when I created the resource or I would have done it that way in the first place, and after I did it with G_BOXCHAR I was too lazy to fix it.

There is a two pixel gap between the bottom of the button/titles and the box/tabpage but the borders fill that in. Look carefully at the resource and don't be afraid to tweak things around when you create your own.

My example is in C, not GFA BASIC, but it should be fairly easy to move it over to any other language. The main.c contains all the actual code. The first function is showSampleDialog and it has all of the dialog box code. The rest of the program is just your basic program initialization and GEM event handling.

The showSampleDialog is reasonably commented. Anybody generally familiar with manipulating GEM object trees shouldn't have a problem with figuring it out.

The attached ZIP archive contains the sources, resource file, and executable. There is a LATTICE C project file. I didn't try it with any other compiler but other than maybe changing the header file includes, I'd expect it to require few changes for anything else.

TABBED.zip
You do not have the required permissions to view the files attached to this post.


Social Media

     

Return to “GFA BASIC”

Who is online

Users browsing this forum: No registered users and 4 guests