372 views
in GUI Development by

Hi,

I would like to create a componets with a view wiht an icon button. but when I create at run time the interface the slide have no effect.

I create an outline an I connect to the sliderHandler a slideTouchHandler.

I fill the outline with a slot:

var int32 i;
var Core::Group view2 = null;
for ( i = 0; i < 16; i = i + 1 )
{              
    var tmScreenMain::ItemSelectMenu itemView = new tmScreenMain::ItemSelectMenu;
    itemView.Caption = string(i);
    itemView.IconIndex = i; 
    if (i == 3)
      {
         itemView.OnAction = ShowSecretMenu;
      }
        else if (i == 4)
      {
         itemView.OnAction = ShowSecretMenu;
      }
       else
      {
       itemView.OnAction = ShowMainLevel;
      }
    view2             = itemView;
    view2.Embedded = true;

  if (i <= 2)
  {
  view2.Bounds.origin.x = i*120+49;
  view2.Bounds.origin.y = 33;
  } else if ((i >= 3) && (i<=6))
   {
  view2.Bounds.origin.x = i*120-316;
  view2.Bounds.origin.y = 131;
  } else
   {
  view2.Bounds.origin.x = 250;
  view2.Bounds.origin.y = 54;
  }
  Add( view2, 0 );
}

The ItemSelectMenu is a custom component and the size is 120X84. On this component the is also a simpleTouchHandler that is associated to an action by a slot.

The problem is that when I fill the outline the simple touch does not work the slideTouchHandler. Nell'temSelectMenu, I added one slot drag event with this code:

slot onDrag
  {
    var int32 delta = TouchHandler.CurrentPos.y - TouchHandler.HittingPos.y;

    if (( delta > 8 ) || ( delta < -8 ))
    {

      //How deflect the touch??

    }
  }

But it does not work how can I fix it?

Another problem is figuring out how to start when the application starts the slot that creates the interface.

I put the code on the UpdateViewState but it always fails..

1 Answer

0 votes
by

Hi,

regarding your first question. The problem is that when touch handler overlap, only the handler lying in front of the screen reacts to the touch events. Solution for such application cases is the 'deflection'. For this purpose the Core::Root class implements the methods DeflectCursor() and RetargetCursor(). In your application case you use the DeflectCursor() method. The following would be the approach:

1. First ensure that the 'Slide Touch Handler' is arranged behind all ItemSelectMenu components. The simplest would be to reorder it behind the 'Outline Box' itself.

2. In the implementation of the ItemSelectMenu component, adapt the onDrag slot method:
 

if (( delta > 8 ) || ( delta < -8 ))
{
  // The owner of the item is the menu itself where the 'Outline Box' and the 
  // 'Slide Touch Handler' are enclosed. Cast the generic 'Owner' to the specific
  // class of the menu component
  var TheClassOfYourMenuComponent menu = (TheClassOfYourMenuComponent)Owner;

  // Knowing the superior menu component, deflect the cursor events to the
  // 'Slide Touch Handler' embedded inside it.
  GetRoot().DeflectCursor( menu.SlideTouchHandler, <0,0>);
}

The effect of this implementation is: when the user taps a menu item, the 'Simple Touch Handler' gets the events first. When the user drags the finger more than 8 pixel up/down, the event handling is passed over to the 'Slide Touch Handler' in the superior menu component. From the menu item's point of view, the user interaction has finished. Therefore, if you implement some onRelease code in the menu item, evaluate the variable 'AutoDeflected' of the 'Simple Touch Handler' in order to distinguish whether the user has taped the menu item or the interaction has been deflected to the menu. In the second case, the menu item should ignore the release event:

if ( SimpleTouchHandler.AutoDeflected )
  return;

With the next version 8.10 we will provide an improvement of all touch handler. With it, it is no more necessary to deflect the cursors 'manually'. Instead, you can specify for every touch handler so-called 'retarget condition'. This can e.g. be a vertical movement. As soon as the specified gesture is detected, the touch handler takes care of the correct deflection to other handle. We plan to release 8.10 in few weeks.

Regarding your second question. You can override the inherited method Init() and implement there the desired startup code for the component.

Best regard

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

...