Advanced RapaGUI techniques

Discuss GUI programming with the RapaGUI plugin here
SamuraiCrow
Posts: 385
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Advanced RapaGUI techniques

Post by SamuraiCrow »

Screenshot time!

Image

If this works right, you should be able to click the image above and see the original 1024x768 screenshot!
I'm on registered MorphOS using FlowStudio.

User avatar
airsoftsoftwair
Posts: 4505
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Advanced RapaGUI techniques

Post by airsoftsoftwair »

Looking good!

SamuraiCrow
Posts: 385
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Advanced RapaGUI techniques

Post by SamuraiCrow »

Thanks Andreas! :D

Today I just discovered that saving a file and loading it back and saving it again caused the file to grow! I've now written a utility that dumps the fields of the file to a window. I discovered that Hollywood was saving my methods as well as my data!

Before:
Image

After:
Image

I had to replace all of my CopyTable() functions with the following wrapper function:

Code: Select all

/*
**	Clone Fields
**
**	Clone the non-method fields of a table only for save methods
*/
Function p_CloneFields(data)
	Local savebuf=CopyTable(data, True)
	; kill the invariant methods
	For k, v In Pairs(savebuf)
		If (#FUNCTION=GetType(v)) Then savebuf[k]=Nil
	Next
	savebuf["slot"]=Nil
	Return(savebuf)
EndFunction
Now a 10k file has been stripped down to 483 bytes!
I'm on registered MorphOS using FlowStudio.

SamuraiCrow
Posts: 385
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Advanced RapaGUI techniques

Post by SamuraiCrow »

Major update!
I've just got the preview window/dialog to work. In preview mode, the window XML generates a dialog box with the same specifications as the window and both windows and dialogs add a button at the end that allows the preview to close independently of the close gadget in case there isn't one.

Another change I've done is to add rectangles to column groups to make sure there is the correct number of gadgets inside using a clever use of RepeatStr() and the modulo operator. Also, adding a dialog or window will automatically add a group embedded in each of them. I'd put this off for some time and both techniques added 2 and 1 line of code respectively. "Much ado about nothing" pretty much describes the situation there.

Finally, all changes have been committed to the GitHub project listed in the first post in this thread. This includes the new FileDump utility that was used in the previous post to find the methods embedded in the file format.

For my next post and project will be a code cleanup and completion of the functionality of the editor. Currently the remove gadget button does nothing and double-clicking the gadgets' listview does nothing. I'd like to be able to add a gadget by double clicking its entry.
I'm on registered MorphOS using FlowStudio.

SamuraiCrow
Posts: 385
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Advanced RapaGUI techniques

Post by SamuraiCrow »

Yesterday I cleaned up the GUI significantly:
Image

Now double clicking the listview adds the item to the current node automatically. The remove button removes windows and dialogs just like it removes gadgets. The add, edit and remove button are now in the toolbox rather than the toolbar at the top. The close button in the toolbar works now (almost) by closing the current application. The close gadget on the window now checks if you want to save the documents just like the quit option in the menu bar. All these changes took place in one afternoon.

Every time I add a method to a gadget class I have to remember to add it back in to the table structure after loading a document back in. Likewise any changes in the fields of the tables affect the save format.

The only buttons left that don't function in the toolbar are the move up and move down buttons. I also have to ghost one or the other if they are invalid so I'll need to add a notification to the treeview gadget. Next time we'll get into that. If you have any questions about it be sure to ask.
I'm on registered MorphOS using FlowStudio.

SamuraiCrow
Posts: 385
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Advanced RapaGUI techniques

Post by SamuraiCrow »

I got the "move up" and "move down" buttons activated already and it only took a few hours. The centerpiece of it is the swapEntries function:

Code: Select all

Function p_swapEntries(first, second, parent)
	; swap entries
	Local content=treeitems[parent.UID].contents
	Local slot1=treeitems[first.UID].slot
	Local slot2=treeitems[second.UID].slot
	Local temp=content[slot2]
	content[slot2]=content[slot1]
	content[slot1]=temp
	content[slot2].slot=slot1
	content[slot1].slot=slot2
	; move GUI items
	moai.DoMethod("tree_hierarchy", "Remove", first.ID)
	If first.Node
		moai.DoMethod("tree_hierarchy", "InsertNode", first.ID, parent.ID, second.ID, Unpack(first.items))
	Else
		moai.DoMethod("tree_hierarchy", "InsertLeaf", first.ID, parent.ID, second.ID, Unpack(first.items))
	EndIf
	; refresh UID in treeitems
	Local newUID=moai.Get(first.ID, "UID")
	treeitems[newUID]=treeitems[first.UID]
	treeitems[UID1]=Nil
EndFunction
It's a bit trickier than I expected but there are three phases of switching. Switching the data structures themselves including the slot numbers stored in the child entries, deleting the first node item and reinserting it after the second and finally, refreshing the treeitems table with the new UID of the formerly first item so that the old key is no longer used and is ultimately assigned Nil to be garbage collected.

Now that all of the major GUI elements are functional, I'll have to give some serious consideration to adding templates. The template functionality will essentially use the PatternReplaceStr() function to do string substitutions on the templates to make reusable chunks of XML.
I'm on registered MorphOS using FlowStudio.

SamuraiCrow
Posts: 385
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Advanced RapaGUI techniques

Post by SamuraiCrow »

Just as I was posting my previous code snippet I noticed a major bug! When moving a node down, it had to be an empty node to work correctly! In order to make it work right I will need to implement clipboard functionality to cut and paste groups containing items.

Also, as I was contemplating adding locale support and templates, this 1500+ line of code Hollywood script can start getting ugly if I don't think things through. Among the problems are the fact that the snippets needed to substitute strings for templates require an entirely different form of editing. The catalog support added by Hollywood in recent releases requires UTF8 encoding so I may just drop the ISO support as well.

Here's where I need your comments. What should I do next? Should I...
  1. Implement clipboard support for groups
  2. Add catalog support in UTF8 only
  3. Make a separate snippet editor for creating reusable templates with
1 is probably required anyway for proper editing. 2 is simpler than 3 and still fairly easy. 3 is going to be tricky no matter how I do it. If I start a separate scratch-pad editor for creating templates with, that will probably have to integrate correctly in the current editor.

If you don't know what I mean by reusable templates, I have basically got to take the XML code from some string and use PatternReplaceStr() to change all of the id fields to make them unique, all while preserving the order of the enumerations used by the locale support.
I'm on registered MorphOS using FlowStudio.

User avatar
airsoftsoftwair
Posts: 4505
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Advanced RapaGUI techniques

Post by airsoftsoftwair »

I'd go for UTF-8 support first :)

SamuraiCrow
Posts: 385
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Advanced RapaGUI techniques

Post by SamuraiCrow »

I've added the choice gadget. This is the first gadget that has had events other than "OK' and "Cancel" buttons needing special care. To handle this I've planned ahead by allowing the local handler() function to override the default p_handler() procedure.

Code: Select all

Function choice.handler(msg, len)
	Local suffix$=UnRightstr(msg.id, len)
	Switch suffix$
		Case "add":
			Local item$=moai.Get("ch_item", "Text")
			moai.DoMethod("ch_list", "Insert", "Bottom", item$)
		Case "remove":
			moai.DoMethod("ch_list", "Remove", "Active")
		Case "up":
			Local pos=moai.Get("ch_list", "Active")
			If pos>0
				moai.DoMethod("ch_list", "Move", pos-1, pos)
				moai.Set("ch_list", "Active", pos-1)
			EndIf
		Case "down":
			Local pos=moai.Get("ch_list", "Active")
			If pos<>-1 And pos<moai.Get("ch_list", "Entries")-1
				moai.DoMethod("ch_list", "Move", pos+1, pos)
				moai.Set("ch_list", "Active", pos+1)
			EndIf
		Case "ok"
			choice.copyback()
			ModalUserData.application.saved=False
			choice.editorDone()
			ModalUserData=nil
		Case "cancel":
			choice.editorDone()
			ModalUserData=nil
		Default:
			DebugPrint("id="..msg.id.." is unhandled")
	EndSwitch	
EndFunction
This allows the four buttons to manipulate the listview gadget entries.
Image
I'm on registered MorphOS using FlowStudio.

SamuraiCrow
Posts: 385
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Advanced RapaGUI techniques

Post by SamuraiCrow »

Once I started adding the radio gadget, I noticed some of my changes had broken the save routines. In this case the table of strings in both the choice gadget and radio gadget couldn't be saved because the save routine was only doing a shallow copy of the outer table. The solution required a small amount of work involving adding a second parameter to the save function to allow the unmodified outer table to be passed in as a second parameter. Now the save routines of radio and choice gadgets can add a shallow copy of the itemlist$ string array with that.

I've decided to postpone adding of locale support because the file format of the saves would have to be changed too much. I'll add it at a later date once I've got the automated search/parse/replace routine support installed for implementing templates. Having an abstract template functionality will be much more powerful than merely supporting locale but will add reusable snippets of XML processing as well. All this will have to come after the gadgets are added in their entirety (with the possible exceptions of listview and/or tree gadgets).
I'm on registered MorphOS using FlowStudio.

Post Reply