B4J Question XUI_Touch event: how to consume it after processing ?

peacemaker

Expert
Licensed User
Longtime User
Hi, All

Is it possible to consume this event cross-platformly after processing ?
When processing is finished - it needs to prevent passing it to the container(-s).
 
Last edited:
Solution
In B4j: Pane has a Touch event but I assume you want to use the mouse for 'touching' the desktop screen.
(correct me if you really have a touch screen for the windows machine)

In the Touch event 3 different actions are handled:
- Pane1.TOUCH_ACTION_DOWN, the user touches the screen - similar to MousePressed
- Pane1.TOUCH_ACTION_MOVE, the user moves the finger without leaving the screen - similar to MouseDragged
- Pane1.TOUCH_ACTION_UP, the user leaves the screen - similar to MouseReleased

Each of MousePressed, MouseDragged, MouseReleased has a (EventData As MouseEvent) as argument
EventData has .Consume method

peacemaker

Expert
Licensed User
Longtime User
The test project is here: "b4xVectEdit_v0.21_xScrollView.zip"
Here video of work: scrolling container scrolls the internal objects OK, when to click it at a free point.
But when i need to just move the internal object (drag it by mouse) - the scrolling is also working and movement is chaotic.

I guess, it can be prevented in this event of each internal object:

B4X:
#if B4A
Private Sub mRoot_Touch (o As Object, ACTION As Int, x As Float, y As Float, motion As Object) As Boolean
#else
Private Sub mRoot_Touch (Action As Int, X As Float, Y As Float)
#end if

    If Action = mRoot.TOUCH_ACTION_DOWN Then
        'mRoot.BringToFront
        Dragging = True
        DownX = X
        DownY = Y
        DraggingStart = DateTime.Now
        Check_LongClick    'checking if LongTap was made
    Else If Action = mRoot.TOUCH_ACTION_UP Then
        Dragging = False
        MouseClickTimer.Enabled = False    'no LongTap
    Else If Dragging And Action = mRoot.TOUCH_ACTION_MOVE Then
        #if B4A
            If InternalView Then Return True
        #else
            If InternalView Then Return
        #end if
  
        MouseClickTimer.Enabled = False    'no LongTap
        'mRoot.Left = ApplyGrid(Max(0, Min(mRoot.Parent.Width - mRoot.Width, mRoot.Left + X - DownX)))  'limited
        'mRoot.Top = ApplyGrid(Max(0, Min(mRoot.Parent.Height - mRoot.Height, mRoot.Top + Y - DownY)))  'limited
        mRoot.Left = ApplyGrid(mRoot.Left + X - DownX)
        mRoot.Top = ApplyGrid(mRoot.Top + Y - DownY)
    End If

    #if B4A
    Return True
    #end if
End Sub


 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Hmm....

playing with those:

B4X:
    Editor.PanelWidth = 500dip
    Editor.PanelHeight = 450dip


Seems somehow better (something height-50px width-10px of window)... from the other hand may is SD_xuiscrollview2D setting or must ask changing something to the code of lib... like adding an option to disable auto-moving from the region...

* Didn't know about xuiscrollview2D - very nice... StarDust Rulez! :)
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
an option to disable auto-moving from the region...
Yes, i tried https://www.b4x.com/android/forum/t...code-add-disabledscrolling-as-boolean.160861/
Didn't know about xuiscrollview2D - very nice
Yes! I also found after long forum search...
... or must ask changing something to the code of lib... like adding

Issue is that legally the lib code manipulations are forbidden by the auther, @Star-Dust.
And the views work differently.

But wait - this topic is about the _Touch event consumation. Is it really ?
 
Last edited:
Upvote 0

Magma

Expert
Licensed User
Longtime User
Issue is that legally the lib code manipulations are forbidden by the auther, @Star-Dust.
And the views work differently.
It has the right as the "creator" of code to ask that..

Did you tried that i ve said?... i think if you have editor.PanelWidth formwidth-5 or -10 dip and editor.panelheight formheight - 25 or -30dip - the code will work like you want...

Try it without maximizing windows... if you need to manipulate window need some xtra things... will talk about then..
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Editor.PanelWidth = 500dip Editor.PanelHeight = 450dip

Where do you mean to set so ?

Try this with zoom = b4xVectEdit_v0.23_xScrollView.zip
 

Attachments

  • b4xVectEdit_v0.23_xScrollView.zip
    9.2 KB · Views: 12
Upvote 0

Magma

Expert
Licensed User
Longtime User
here

B4X:
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
  
    Editor.PanelWidth = 585dip
    Editor.PanelHeight = 550dip
  
    'Editor.VerticalBar=False
    'Editor.HorizontalBar=False
  
    Generate_Diagram
  
    'SavePicture(File.DirApp, "pic.png", Editor.Panel.Snapshot)
End Sub

ps: Remember dont maximize window - for test.... until for now.. - no prob... maximize it ...
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Thanks, @Magma, for tests.
Try version with the zoom above 0.23, and see the logged coordinates of the draggable objects - they are jumping.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
not jumping... autoscrolling...
It's OK, if to drag without zoom and accurately one object by one. If to drag one over another - all is jumping.

This is version of the standard ScrollView - it's work more correctly than version with XUIScrollView view for moving, but in xScrollView - Labels are not visible, no idea why.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
XUIScrollView
  • Events:
    • ScrollChanged (X As Float, Y As Float)

Well, seems not having _FocusChanged (HasFocus As Boolean)
but do not know if this, will help too....

And my problem was keypressing... because scrollview always listening first...

I think if asking from "StartDust", adding a feature like autoscroll (false,true) - some time (if having the time) will add it...

Sorry... can't think something more..
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
But what about the topic subject ?
Strongly saying - the trouble is - jumping object's coordinates during dragging.

Under Android _Touch event can be consumable, but how to consume _Touch of B4Xview ?
 
Last edited:
Upvote 0

Magma

Expert
Licensed User
Longtime User
But what about the topic subject ?

... You mean .. every time moving your objects/created on view/pane - the mroot with edit the position against automatic-scrollview... The thing at those is the timing... which of these will run first or second (from compiler? - who knows - so jump will exist)

I am thinking other trick

What about the time of clicking/dragging object when moving:

1. at first click take a snap of editor.panelwidth at one variable and the editor.panelheight at other...
2. set at panelwidth and and height at formheight / widths - the difference dips (titilebar, top from view, vertical scrollbar width, etc)
3. move without jumping
4. when user not clicking/dragging - set again the right values for panelwidth/height

understand ?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
jumping objects
...ok...

let's split the jobs... of a scrollview... (I can understand what you mean - i had the same questions)

1) Scrollview is just a window that you can see outside (views)

2) At your example the difference of top,left of one object with other top,left object changing with the move/jumping of scrollview (without dragging the items/objects) ?
 
Upvote 0
Top