[litwindow-users] Implementing generic UI patterns (was Re: add/modify/delete pattern)
Status: Alpha
Brought to you by:
hajokirchhoff
From: Hajo K. <mai...@ha...> - 2004-11-15 14:05:11
|
Hi Jake, (this is a cross post from gmane.comp.lib.litwindow.user that hopefully is also of interest to the current GUI discussion on the boost list. The question was how to write a generic implementation for the add/modify/delete user interface pattern) Jake Skinner wrote: > I am having some difficulty getting my head around the RULE syntax and > what can be achieved. I am trying to implement the add/modify/delete > pattern which appears to have been catered for. > you are a bit ahead of the litwindow schedule here. I've put up a new article on the website (a correction of the few layout problems will appear later this day) http://www.litwindow.com/Library/Articles/rapidui_article_3.htm Here is what works: You can already handle the 'modify' part of the add/modify/delete pattern. Have a look at the RSS Reader tutorial, Step 3 and 4 in the documentation. Here is what does not yet work: Action rules have yet to be defined. So you cannot fire an action using the rules and that is the reason why the add/modify/delete rule has to be written yet. To implement Add you will have to intercept the event yourself. What you can do is write a generic algorithm to add a new element and show it. Here is the rough outline: void AddElement(RapidUI &r, string listBoxName) { // first get the aggregate object for the list box aggregate listbox=r.GetWindowAccessor(listBoxName).get_aggregate(); // next get a container object for the "Items" property // of the list box container items=listbox["Items"]; if (items.is_valid()==false) { lw_log() << "Cannot add! List box is not attached to a container."; return; } // now get an accessor to the currently selected element accessor element=listbox["Current"]; // this accessor will contain valid *type* information // even if no *current* element is selected // the next line will create a new object on the heap with 'new' // the new object will have the same type as 'Current' accessor newObject=create_object(element.get_type()); // insert it (copying it) at the first position into the container items.insert(items.begin(), newObject); // delete the temporary object since a copy of it is now contained // in the container newObject.destroy(); // finally tell RapidUI to update the UI // this will update the list box and the new element will // be shown at position 1 r.ValueChanged(items.get_accessor(), false, false); } This is a generic function, meaning that it will work - with any kind of container - with any type of elements contained in the container - with any list widget that knows "Items" and "Current" provided the appropriate data adapters have been created. Hope this helps and thank you for your interest. BTW, I am cc-ing this to the boost mailing list Regards Hajo Speed up GUI coding by a factor of 10x http://www.litwindow.com/library |