43 views
in GUI Development by

Hello,

I have a GUI application where I have a linked list that stores text data on a line-by-line basis. I am using a Vertical List to show the data where each entry is a line of text. The data source for the Vertical List is the linked list of data. The list is finite and the user is able to scroll through the data. When new data is added to the list, the vertical list is refreshed and the list is forced to the bottom to show the newest data. Each entry in the list is a widget that holds a string and makes all of the entries a consistent size and contains an example string as a placeholder that gets overwritten as the Vertical List loads the text data from the Linked List. 

We had an issue where at one point while a user was scrolling through the list, there was an extra entry in the Vertical List and showed the default string that should have been overwritten by data from the Linked List. When the user logged out and logged back in, which dismissed and re-built the dialog that contains the Vertical List, the errant line was gone. What could have caused this issue and is there any errors in our vertical list implementation.

VerticalList.OnLoaditem:


// Get the number of the item to load. The list component takes care of the
// creation of the corresponding item view. Just access it ...
var uint32       itemNo   = (uint32)VerticalList.Item;
var Wgt::SystemActivityTextItem itemView = (Wgt::SystemActivityTextItem)VerticalList.View;


if ( itemView == null ) {
  trace "itemView is null - vertical list could not cast properly";
  return;
}

if (pure EventList != null && (itemNo < pure EventList.Count)) {
  var Data::SysActivityLinkedItem item = (Data::SysActivityLinkedItem)pure EventList.GetItem( itemNo );
  
  itemView.String = item.ActivityString;

} else {
  //tracestack;
}

// Ensure that the item has correct size. The position of the item will be
// managed by the list component.
//trace "itemView.Bounds.size = ", point( VerticalList.Bounds.w, VerticalList.ItemHeight );
itemView.Bounds.size = point( VerticalList.Bounds.w, VerticalList.ItemHeight );

VerticalList.OnUpdate:

// Get the boundary area of the Vertical List
var rect viewRect    = VerticalList.Bounds;

// Get the complete area enclosing all list items
var rect contentRect = VerticalList.GetItemsArea( 0, VerticalList.NoOfItems - 1 );
var int32 y1 = 0;
var int32 y2 = 0;

if (contentRect.h > 0) {
  // From the proportion between the both areas calculate the relative position
  // of the upper and lower end of the scrollbar. The max. height of the scrollbar
  // is the height of the Vertical List itself (viewRect.h).
  y1 = (( viewRect.y1 - contentRect.y1 ) * viewRect.h ) / contentRect.h;
  y2 = (( viewRect.y2 - contentRect.y1 ) * viewRect.h ) / contentRect.h;
}

// Limit the upper end of the scrollbar
if ( y1 < 0 ) {
  y1 = 0;
}

// Limit the lower end of the scrollbar
if ( y2 > viewRect.h )
  y2 = viewRect.h;

// Arrange the scrollbar, so it appears on the right hand side of the Vertical List
// with 10 pixel margin. The scrollbar itself is 10 pixel wide.
ScrollbarRect.Bounds = rect( viewRect.x2 - 10, y1 + viewRect.y1,
                         viewRect.x2, y2 + viewRect.y1 );

Slot called when Linked List is updated:

if (EventList != null) {
  VerticalList.NoOfItems = (int32)pure EventList.Count;
} else {
  VerticalList.NoOfItems = 0;
}


VerticalList.InvalidateItems( 0,(int32) pure EventList.Count - 1);

var Application::DlgMainMenu main_menu = (Application::DlgMainMenu)this.Owner;
if(main_menu != null && !main_menu.SystemActivityPaused )
{
  var rect area = VerticalList.GetItemsArea( 0, VerticalList.NoOfItems - 1 );

  VerticalList.ScrollOffset = point(0, VerticalList.Bounds.h-(area.h)).y;
}

Vertical List item widget:

1 Answer

0 votes
by

Hello Leo,

at first glance I don't see any issues with the implementation expect two parts:

- Code in the LinkedList update method where EventList is tested agains null but later it is accessed. This, however, would cause an access violation exception and not produced the described behavior.

- The if condition in the OnLoad method testing itemNo agains EventList.Count. If the condition is false, no item reload is performed.

Since we had no similar issues reported in the past, I suppose the problem is probably somewhere in your implementation. You could try to narrow down it using the trace statement. If you can't find the issue, I can take a look at it. In this case please reduce the application to a very simple example demonstrating the issue only.

Best regards

Paul Banach

 

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...