Liberty BASIC Community Forum
« Toggle doesn't work with single click »

Welcome Guest. Please Login or Register.
Sep 21st, 2017, 7:56pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Toggle doesn't work with single click  (Read 265 times)
MKnarr
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 430
xx Toggle doesn't work with single click
« Thread started on: Dec 2nd, 2015, 2:29pm »

This snippet is to show the toggle doesn't work with a singleclickselect.

The idea is I have 10 data points that are possible to do something with. But the user has the ability to select one or more data points for example 3 to 5. They might also want to use say only 3 as the starting point and 3 as the ending point.

If they are using double click, the default, a double click on 3 will set 3 as the starting data and a second double click on 3 sets it as the ending data. However if I unremark the "singleclickselect" line for the list box, a single click on 3 selects it as the starting point but I must still actually double click on 3 again to select it as the ending data. But if I choose to select 3 as the starting data and 5 as the ending data, then single clicking works. So this example only doesn't work with single clicking if you try to select the same number twice.

Code:
    nomainwin
    WindowWidth = 550
    WindowHeight = 410
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    for x=1 to 10
        array$(x)=str$(x)
    next

    listbox #main.lb1, array$(, [selectdata],    5,  12, 230, 285
    statictext #main, "Starting data", 275,  32, 108,  20
    statictext #main.st1, "", 375,  32, 108,  20
    statictext #main, "Ending data", 275, 102, 108,  20
    statictext #main.st2, "", 375, 102, 108,  20
    startdata$=str$(1)
    enddata$=str$(10)

    open "untitled" for window as #main
    print #main, "font ms_sans_serif 10 bold"
    '#main.lb1, "singleclickselect" 'Unremark this line and selecting 3 twice doesn't work.
    #main.st1,startdata$
    #main.st2,enddata$
    flag=0
    wait

    [selectdata]  'This is basically a toggle to select a start and end data.
    #main.lb1,"selection? data$"
    if flag=0 then
        startdata$=data$
        #main.st1, startdata$
        flag=1
    else
        enddata$=data$
        #main.st2, enddata$
        flag=0
    end if
    wait
 


Any ideas?
« Last Edit: Dec 2nd, 2015, 2:30pm by MKnarr » User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2278
xx Re: Toggle doesn't work with single click
« Reply #1 on: Dec 2nd, 2015, 2:59pm »

Don't know if this is a Windows design or an LB design, but it appears that single-clicking to select an option doesn't work if the option is already selected.


I added a notice to the [selectdata] branch to pop up when the code ran, and the click event doesn't even fire.
User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
Jim Hiley
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 202
xx Re: Toggle doesn't work with single click
« Reply #2 on: Dec 2nd, 2015, 3:48pm »

You might have to cheat a bit.
As soon as the first item is selected, reset the listbox to the default:
Code:
dim array$(11)
 nomainwin
    WindowWidth = 550
    WindowHeight = 410
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    array$(1)="Choose value..."
    for x=1 to 10
        array$(x+1)=str$(x)
    next

    listbox #main.lb1, array$(, [selectdata],    5,  12, 230, 285
    statictext #main, "Starting data", 275,  32, 108,  20
    statictext #main.st1, "", 375,  32, 108,  20
    statictext #main, "Ending data", 275, 102, 108,  20
    statictext #main.st2, "", 375, 102, 108,  20
    startdata$=str$(1)
    enddata$=str$(10)

    open "untitled" for window as #main
    print #main, "font ms_sans_serif 10 bold"
    #main.lb1, "singleclickselect" 'Unremark this line and selecting 3 twice doesn't work.
    #main.st1,startdata$
    #main.st2,enddata$
    flag=0
    wait

    [selectdata]  'This is basically a toggle to select a start and end data.
    #main.lb1,"selection? data$"
    #main.lb1, "selectindex "; 1
    if flag=0 then
        startdata$=data$
        #main.st1, startdata$
        flag=1
    else
        enddata$=data$
        #main.st2, enddata$
        flag=0
    end if
    wait
 


Jim
User IP Logged

MKnarr
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 430
xx Re: Toggle doesn't work with single click
« Reply #3 on: Dec 2nd, 2015, 5:15pm »

Jim I found a similar fix. I'm not sure why it works but it does.

Code:
nomainwin
    WindowWidth = 550
    WindowHeight = 410
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    for x=1 to 10
        array$(x)=str$(x)
    next

    listbox #main.lb1, array$(, [selectdata],    5,  12, 230, 285
    statictext #main, "Starting data", 275,  32, 108,  20
    statictext #main.st1, "", 375,  32, 108,  20
    statictext #main, "Ending data", 275, 102, 108,  20
    statictext #main.st2, "", 375, 102, 108,  20
    startdata$=str$(1)
    enddata$=str$(10)

    open "untitled" for window as #main
    print #main, "font ms_sans_serif 10 bold"
    #main.lb1, "singleclickselect" 'Unremark this line and selecting 1 twice doesn't work.
    #main.st1,startdata$
    #main.st2,enddata$
    flag=0
    wait

    [selectdata]  'This is basically a toggle to select a start and end data.
    #main.lb1,"selection? data$"
    if flag=0 then
        startdata$=data$
        #main.st1, startdata$
        flag=1
    else
        enddata$=data$
        #main.st2, enddata$
        flag=0
    end if
    '#main.lb1, "reload"
    #main.lb1, "selectindex 0"
    wait

 


I just added a selecindex at the end of the toggle.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Toggle doesn't work with single click
« Reply #4 on: Dec 3rd, 2015, 02:07am »

I have always just accepted that the listbox event is telling me when the selection CHANGES. That's why the force it to default solution repeatedly tells you of every click, because then it is always changing.
User IP Logged

MKnarr
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 430
xx Re: Toggle doesn't work with single click
« Reply #5 on: Dec 3rd, 2015, 09:50am »

I've now found out that my solution doesn't work. It works when the users single clicks but if the user double clicks, the code goes haywire. So it back to double clicking only to make the two selections.
User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2278
xx Re: Toggle doesn't work with single click
« Reply #6 on: Dec 3rd, 2015, 10:09am »

on Dec 3rd, 2015, 09:50am, MKnarr wrote:
I've now found out that my solution doesn't work. It works when the users single clicks but if the user double clicks, the code goes haywire. So it back to double clicking only to make the two selections.


The double-click is still sent to the program. You need to account for both 1) the double-click event, and 2) the clear that comes from the selectindex(at least, I think that's where it's coming from)

Code:
nomainwin
    dblClickTime = GetDoubleClickTime()  'Get the number of milliseconds that two clicks have to arrive within to
                                         'be considered a double-click.  This is a user-configured system setting.
    oldTime = 0
    newTime = time$("ms")

    WindowWidth = 550
    WindowHeight = 410
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    for x=1 to 10
        array$(x)=str$(x)
    next

    listbox #main.lb1, array$(, [selectdata],    5,  12, 230, 285
    statictext #main, "Starting data", 275,  32, 108,  20
    statictext #main.st1, "", 375,  32, 108,  20
    statictext #main, "Ending data", 275, 102, 108,  20
    statictext #main.st2, "", 375, 102, 108,  20
    startdata$=str$(1)
    enddata$=str$(10)

    open "untitled" for window as #main
    print #main, "font ms_sans_serif 10 bold"
    #main.lb1, "singleclickselect" 'Unremark this line and selecting 1 twice doesn't work.
    #main.st1,startdata$
    #main.st2,enddata$
    flag=0
    wait

    [selectdata]  'This is basically a toggle to select a start and end data.
    oldTime = newTime
    newTime = time$("ms")
    #main.lb1,"selection? data$"

    'If two clicks arrive within the double-click period, ignore the second click, ONLY
    'if the second click is on the same item.
    '
    'The reason for the check on 'data$ = ""' is because, with the current code,
    'when you double click, the first click clears the selection, and when the code
    'runs again for the double-click, it gets a blank selection.
    '
    'Therefore, if we got two clicks within the double-click timeframe with a blank selection,
    'it was a double-click on the same item and should be dropped.
    if (((newTime - oldTime) < dblClickTime) AND (data$ = "")) then [dropDoubleClick]

    if flag=0 then
        startdata$=data$
        #main.st1, startdata$
        flag=1
    else
        enddata$=data$
        #main.st2, enddata$
        flag=0
    end if
    '#main.lb1, "reload"
    #main.lb1, "selectindex 0"
    [dropDoubleClick]
    wait

Function GetDoubleClickTime()
    CallDLL #user32, "GetDoubleClickTime",_
    GetDoubleClickTime as ulong
End Function 

User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Toggle doesn't work with single click
« Reply #7 on: Dec 3rd, 2015, 11:19am »

Can we get a short code sample? Basically if the handlers are the same for single and double click you should be able to manage this.

The traditional problem is that a double click is always preceded by a single click.

Chris is showing that a timer allows you to discern between single and double clicking, but it might be simpler than that.

You want click low, click high? But what about click high click low and change high or low? how is the final event triggered?

A skeleton of the code might get better answers.
User IP Logged

Jim Hiley
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 202
xx Re: Toggle doesn't work with single click
« Reply #8 on: Dec 3rd, 2015, 1:53pm »

If you just want to ignore the double click, send the double click to a dummy routine.
This works for me:
Code:
listbox     #MMF.MMlist1, List1$(), [MMlist1a], 5, 165, 245, 335
#MMF.MMlist1 "singleclickselect [MMlist1]"
  
.....
  
[MMlist1a]

wait
    
MMlist1]
#MMF.MMlist1, "selection? MMSelected$"
..... 


Jim
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls