How to make the difference between single click and double click on a uiListbox

Home Forums General Programming How to make the difference between single click and double click on a uiListbox

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #68769
    goodweather
    Participant
      • Topics: 45
      • Replies: 550
      • Total: 595
      • ★★★

      I’d like to know how to make the difference between single click and double click on a listbox.
      Creating a method reacting on MouseDown and on DoubleClick gives the same initial syntax with event as second parameter.

      What are the different values of event (and where should I have found that) so I can build a test in the method to separate single click and double click events?

      Thx!

      #68781
      Carl Licroy
      Participant
        • Topics: 3
        • Replies: 28
        • Total: 31

        Hi goodweather!

        Maybe a solution is to create a variable when your method starts like

        process = "doubleclick"

        Or

        process = "singleclick"

        Then you can test the value of your variable in your methods.

        if process == doubleclick then
            -- your code here
        end
        #68789
        goodweather
        Participant
          • Topics: 45
          • Replies: 550
          • Total: 595
          • ★★★

          Hi Carl!
          Thx, I have indeed been thinking to this solution (classical programming one, as I’m doing 🙂 ) and I’ll use it if I don’t get an answer.
          However, as we have the event object as variable, I suppose it is also exposing the different event types. I will look at this today. Must be hidden somewhere in the Juce documentation, I guess.

          Complementary request to above question:
          In fact, I would like to track right-click versus left-click in the OnMouseDown method (or more precisely for WhenItemIsClicked method of an uiListBox)

          #68791
          goodweather
          Participant
            • Topics: 45
            • Replies: 550
            • Total: 595
            • ★★★

            As often, found it by myself after more than one hour searching (and trying to understand) in Juce API and Ctrlr classes.
            As there was nothing on the forum about this, I’m posting the result here.

            In a OnMouseDown method, the second arg is event. You can use it as follows:

            console("Click at X="..tostring(event.x))
            console("Click at Y="..tostring(event.y))
            if event.mods:isLeftButtonDown() then console("Left button pressed") end
            if event.mods:isRightButtonDown() then console("Right button pressed") end
            

            Several other tests are available. Look at https://www.juce.com/doc/classModifierKeys

            Pro2 librarian on its way 🙂

            #68886
            goodweather
            Participant
              • Topics: 45
              • Replies: 550
              • Total: 595
              • ★★★

              One problem solved, next problem araising… 🙂

              In fact the solution above works for the “When the Mouse is down on the component” method.
              For uiListbox, there are two other methods related to the clicked item: “When the item is clicked” and “When the item is double-clicked”.
              Those 2 methods do not provide the event as argument and thus I don’t know how to test.
              Moreover, when you double click, both methods are run (obviously, a double click is made of a single click first).

              Shouldn’t those 2 event trackings be separate? Double click method executed ONLY on double click and single click method executed ONLY on single click?

              Thx to look at this or to provide some workaround…

            Viewing 5 posts - 1 through 5 (of 5 total)
            • The forum ‘Programming’ is closed to new topics and replies.
            There is currently 0 users and 123 guests online
            No users are currently active
            Forum Statistics
            Threads: 2,495, Posts: 17,374, Members: 77,605
            Most users ever online was 12 on January 22, 2019 3:47 pm
            Ctrlr