About Store Forum Documentation Contact



Post Reply 
func() on _List
Author Message
Tottel Offline
Member

Post: #1
func() on _List
Hello Esenthel,

After Setting func(Function, T) while creating an object of type _List, that function is not called when selecting elements in the list.

Thanks!
12-08-2015 09:51 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #2
RE: func() on _List
(12-08-2015 09:51 AM)Tottel Wrote:  Hello Esenthel,

After Setting func(Function, T) while creating an object of type _List, that function is not called when selecting elements in the list.

Thanks!
Neither is funcPre
12-08-2015 02:22 PM
Find all posts by this user Quote this message in a reply
SamNainocard Offline
Member

Post: #3
RE: func() on _List
I think, the only way right now is to detect it manually.
I used something like this.

Code:
List<TYPE>list;

void update()  // put it into main update (Game.Update or other suitable)
{
   if(Gui.ms()==&list)
   {
        if(TYPE * clicked=list()) // is valid
        {
            if(Ms.bp(0))
            {
               clickFunc();
            }
        }
   }
}

void clickFunc();
{
   LogN(S+"Clicked on Element: "+list.cur);
}
12-09-2015 08:41 AM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #4
RE: func() on _List
Sam: Sure, but I don't want to do that if there is a clean one-line solution that is supposed to work. grin
12-09-2015 08:57 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #5
RE: func() on _List
Hi,

Right now func and funcPre work only for the List.sel selection, which is processed only when LIST_MULTI_SEL is enabled in List.flag
They will be called every time List.sel changes.

Code:
_List& func(void (*func)(Ptr   user), Ptr   user=null);                                            // set function called when list 'sel' selection has changed, with 'user' as its parameter
   T1(TYPE) _List& func(void (*func)(TYPE *user), TYPE *user     ) {return T.func((void(*)(Ptr))func,  user);} // set function called when list 'sel' selection has changed, with 'user' as its parameter
   T1(TYPE) _List& func(void (*func)(TYPE &user), TYPE &user     ) {return T.func((void(*)(Ptr))func, &user);} // set function called when list 'sel' selection has changed, with 'user' as its parameter

            _List& funcPre(void (*func)(Ptr   user), Ptr   user=null);                                               // set function called when list 'sel' selection is about to change, with 'user' as its parameter
   T1(TYPE) _List& funcPre(void (*func)(TYPE *user), TYPE *user     ) {return T.funcPre((void(*)(Ptr))func,  user);} // set function called when list 'sel' selection is about to change, with 'user' as its parameter
   T1(TYPE) _List& funcPre(void (*func)(TYPE &user), TYPE &user     ) {return T.funcPre((void(*)(Ptr))func, &user);} // set function called when list 'sel' selection is about to change, with 'user' as its parameter

If you want to detect clicks on List elements, then I recommend doing what SamNainocard suggested smile
12-10-2015 08:36 AM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #6
RE: func() on _List
Hi Esenthel,

Isn't a list without the LIST_MULTI_SEL flag just a list with a max List.sel of 1? pfft
I don't understand why func and funcPre would not work without multi-selection, because you would really expect it to work consistently.

Thanks!
(This post was last modified: 12-10-2015 09:28 AM by Tottel.)
12-10-2015 09:28 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #7
RE: func() on _List
Hi,

List.cur is always valid (it's the keyboard cursor position)
List.sel is valid only with LIST_MULTI_SEL enabled, if it's not enabled then 'sel' will always be empty.

The comments on 'func' and 'funcPre' mention that the functions are called only when 'sel' changes.

When LIST_MULTI_SEL is disabled, then List.sel is not used at all, only List.cur is used.
12-10-2015 09:39 AM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #8
RE: func() on _List
I see,

Thanks Esenthel, I will use the solution from Zervox and Sam then! smile
12-10-2015 09:45 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #9
RE: func() on _List
Next version will have:
'func' renamed to 'selChanged'
and a new:
'curChanged' method added
03-25-2016 12:29 AM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #10
RE: func() on _List
Works perfectly and it's much cleaner. smile

Thanks!
04-06-2016 04:24 PM
Find all posts by this user Quote this message in a reply
Post Reply