Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Change GadgetID dynamically

 Post Reply Post Reply
Author
Message
C4DS View Drop Down
Member
Member


Joined: 2015 Dec 01
Online Status: Online
Posts: 234
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Topic: Change GadgetID dynamically
    Posted: 2018 Apr 20 at 2:40am

User Information:

Cinema 4D Version:   R19 
Platform:   Windows  ;   
Language(s):     C++  ;   

---------

Hello,

I've looked into the documentation, but cannot seem to find details related to this topic.
I have a GeDialog which I populate dynamically with buttons. To know which button gets pressed by the user I use a base ID + index value.
Let's say button 1 has ID 1000, button 2 has ID 1000 + 1, etc ...

This way, in the GeDialog::Command I simply need to subtract 1000 from the incoming ID to know which button got pressed and react accordingly.
Additionally, the user can remove buttons. This would introduce gaps in the index, if I simply remove the button, so I would like to adjust the ID of the remaining buttons (after the one being removed) in order to avoid an index gap.

I thought of simply removing all buttons from the one being removed till the last one, and re-adding the buttons with re-indexed values.
But if it's possible to simply change the gadgets' IDs I'd be happier to do so.



Back to Top
C4DS View Drop Down
Member
Member


Joined: 2015 Dec 01
Online Status: Online
Posts: 234
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 20 at 3:53am
Well, I guess we can close this topic since it doesn't make much sense.

Working on the rest of the implementation for the dialog, I encounter a much bigger problem.
The buttons I dynamically create are part of a group in the dialog.
I can remove a button without problem, but I cannot simply add a button to that group, as it gets added as the last item in the dialog. Which means the new buttons get added after the last gadgets of the dialog.

I assumed I could simple set the the focus to the group by calling Activate(groupid), and continue adding gadgets to that group. But that's apparently not the way things work.

So, instead I need to flush the whole group and add all items again.
Which, from one point of view, is good since then I don't need to update the IDs of the gadgets. Now I simply recreate them all over again ... with updated index.

Back to Top
MohamedSakr View Drop Down
Member
Member
Avatar

Joined: 2012 Sep 17
Location: Egypt
Online Status: Offline
Posts: 577
Post Options Post Options   Quote MohamedSakr Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 21 at 1:12am
if removing buttons is simple and your problem is only IDs, use std::map at the start and your life will be easier :)
cheers,
Mohamed Sakr
Back to Top
C4DS View Drop Down
Member
Member


Joined: 2015 Dec 01
Online Status: Online
Posts: 234
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 21 at 8:50am
What I meant was that dynamically removing a button from a group is possible, but not adding one. So the whole idea behind updating the IDs is of no use.

Back to Top
MohamedSakr View Drop Down
Member
Member
Avatar

Joined: 2012 Sep 17
Location: Egypt
Online Status: Offline
Posts: 577
Post Options Post Options   Quote MohamedSakr Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 21 at 9:11am
I think you can hide them dynamically (but they remain there, not drawn).
cheers,
Mohamed Sakr
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1848
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 23 at 7:40am
Hi,

just chiming in to add a few links.

It's correct, in order to add to a group the correct way is to flush (LayoutFlushGroup()) and then rebuild it.

The Activate() function changes the focus for the user. So, it activates a certain widget, which can then for example directly be controlled by keyboard input. It's not meant as "programmatic focus". Let me know, if you think, we should improve the docs here.

And finally the inevitable manual link: GeDialog manual (Groups)

Cheers,
Andreas
SDK Support Engineer
Back to Top
C4DS View Drop Down
Member
Member


Joined: 2015 Dec 01
Online Status: Online
Posts: 234
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Apr 23 at 11:50am
Thanks Andreas,
Documents are clear as they are.
I understand the Activate() function was only meant to set the focus for the user, but I just hoped that it did (behind the scenes) allow for "programmatic focus". It was worth a shot trying.

Also, thank you Mohamed for trying to help out. It seems I didn't mention an important point in my introductory message. I needed the user to allow to remove buttons, but forgot to mention the user also should be able to add buttons. And all this in a non-particular order.
So while the RemoveElement() function is available (at any point in time), there is no way to add an element somewhere in particular (an Addxxx() is always added at the end of the GeDialog).

Topic can be closed
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.