Multiple GH_ComponentAttributes on Component

Hello,

I wrote some logic for custom GH_ComponentAttributes to add a group RadioButtons (left) OR a group of Checkboxes (right).

I use them both with success...


But now I want to combine them, for example, add a second group of RadioButtons, or even mix them...

The Layout they use is (or should be) based on the current size of the component, so I guess, doing them in a series should work just fine.


I had a research on this topic but did not find out how the adding should work...

This (needed?) line of code in CreateAttribute(), I guess, I don't fully understand

m_attributes = instanceOf_MyCustomAttribute;

I found the AppendToAttributeTree(), as a call and as an override. But in both cases 

I tried to set GH_ComponentAttributes.Parent in both directions.


So, somebody can enlight my on this topic?

I could imagine a workaround where a Wrapper redirects each (do make it fully compatible) override of GH_ComponentAttributes to each item in a collection of GH_ComponentAttributes.
But this would be a stupid work to do. And also timeconsuming in computing I guess...

Attached
- RadioButtonAttribute
- CheckboxAttribute


Greets
Mark

  • up

    David Rutten

    You can only have one attribute instance per component. The Attribute Tree is a data structure which combines all the attributes of the various elements that make up a component (i.e. the component itself and all the input/output parameters). You should not mess with the tree or the parent fields, that'll just break things.

    If you want to have re-usable UI on custom component attributes, you are going to have to design the class hierarchy yourself. For example you could create a single type of component attributes which has additional logic for a variable set of UI elements. That would mean you'd only have to write the logic once. It'll be a fairly complicated job, but then overriding component attributes always is.

    Imagine you have a single interface called IComponentUiElement which covers all the individual controls you'd like to add to components. There'd be two classes that implement this interface, let's call them ComponentCheckBox and ComponentOptionBox (you may want to add more later, ComponentComboBox, ComponentTextBox, ComponentNumberBox, ComponentSlider, ...).

    Each control must carry all the information it needs to function; what it's name is, how it knows what state it is in, what area represents the mouse-click-relevant-region, what should happen when the mouse is clicked etc.

    Then, your custom attributes will need the smarts to collect and maintain these controls. So your class CustomComponentAttributes will have a method AddCustomControl(IComponentUiElement). Then, within the CreateAttributes() method of each of your Components, you'll have to create this custom attribute class and populate it with the relevant controls.

    As you can see, even in English it adds up to quite a bit of text, expect to write several thousand lines of code...

    5
  • up

    Ortler Mark

    hey people,

    I'm successfully using custom attributes stacking them vertical.

    At the moment I try to implement someting like 'minWidth' in this stack, so the visuals fit nicely into the boundaries of the component. Therefor the component's width may have to be changed.

    Here comes the problem:
    The drawing on the canvas just looks fine but the Output-Paramters are drawn and are wired at/from the position they had before the width has changed.


    Someone has a tip?

    greets
    Mark

    5