[ManiaScript] Data Attributes on FrameInstances

Talk about ManiaLink development in this forum

Moderator: NADEO

Post Reply
zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

[ManiaScript] Data Attributes on FrameInstances

Post by zocka » 07 Aug 2016, 15:03

I understand framemodels are more or less just copy-pasted into the spots of their frameinstance elements, creating a frame which gets most attributes from the frameinstance.

Appearently this does not include class- and data-attributes.


Usecase:
Personally I am fond of creating elements from markup rather than manually enriching them with ManiaScript. For that the data-attributes are great. To individualize instances, class- and data-attributes should be merged on the resulting instance frame.


Example:
Envision a framemodel 'button_with_icon' having a quad for the background, a quad as shadow, a label for the text and a quad as icon. It makes sense to bundle this in a framemodel, if you want to re-use that, as it consists of quite some code you don't want to duplicate.

Normally I would need to get the frame, get the label, set the text. Get the background, set a background color, e.g. considering a normal or primary button. Get the icon, set a style/substyle or image. Either manually for each occurance or I'd have to introduce some data structure for that. Either in ManiaScript or with a element referenced via naming convention which will then be deleted xD

The following could be completely sufficient in combination with some BWI_Init() to set the provided values.

Code: Select all

<frameinstance modelid="button_with_icon" data-bwi-style="Icons128x128_1" data-bwi-substyle="Create" data-bwi-label="awesum!" />
We could be pretty close to self-sufficient xml files providing custom elements - markup and a ManiaScript API . Just Include them and use it :thumbsup:
Although I don't see to big of an audience for that :(
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka

User avatar
noyranea
Nadeo
Nadeo
Posts: 173
Joined: 29 Apr 2014, 14:50
Location: Paris, France

Re: [ManiaScript] Data Attributes on FrameInstances

Post by noyranea » 08 Aug 2016, 10:39

Hello Zocka !

I agree with the fact that some attributes common to many Manialink controls (such as id, pos, rot, scale, class, data attributes, hidden and maybe others in the future) should be set for the frameinstance itself rather than for any instance of a given framemodel.
Fortunately, this issue could be addressed while improving some other features of the Manialink language, so you'll be able to set class et data attributes (which were the only 2 missing) for each frameinstance independantly, for both the current and future versions of Manialinks.

Have a nice day,

-- noyranea

User avatar
Nerpson
Translator
Translator
Posts: 1385
Joined: 27 Sep 2013, 18:02
Location: France
Contact:

Re: [ManiaScript] Data Attributes on FrameInstances

Post by Nerpson » 08 Aug 2016, 13:57

If i have a <framemodel id="test" scale="2">...</framemodel>

and a <frameinstance modelid="test" scale="3" /> Will the scale attribute be overridden? Setting the scale to 3 instead of the default 2?
ImageImageImageImage

User avatar
noyranea
Nadeo
Nadeo
Posts: 173
Joined: 29 Apr 2014, 14:50
Location: Paris, France

Re: [ManiaScript] Data Attributes on FrameInstances

Post by noyranea » 08 Aug 2016, 14:25

There is actually no override in any way : the "frame" attributes are read from the "frameinstance" tag, and the content of the frame is that of the framemodel.
In your example, the scale of the frameinstance will be 3, and hadn't you set the scale in the frameinstance, it would've been the default x1 scale.

zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: [ManiaScript] Data Attributes on FrameInstances

Post by zocka » 08 Aug 2016, 14:56

noyranea wrote:[...] some attributes [...] should be set for the frameinstance itself rather than for any instance of a given framemodel. [...]
Just to be clear: e.g. the class values are merged instead of just taken from the frameinstance I hope?

Code: Select all

// I deem data attributes on the model optional, but it might be better to
// have most attributes on models and overwrite them if needed
<framemodel id="md-input" class="md-input" data-mdi-color="defaultValue" >...</framemodel>

// we don't want to replicate the class every time we use a frameinstance
<frameinstance modelid="md-input" class="input-settings" data-mdi-placeholder="Placeholder Text" data-mdi-color="f0f" />

Void MDInput_Init() {
  // expects a certain class, as we can't determine the model otherwise
  Page.GetClassChildren(Page.MainFrame, "md-input", True);
  ...
}

// I'd expect the resulting element to behave like that:
<frame class="md-input input-settings" data-mdi-placeholder="Placeholder Text" data-mdi-color="f0f" >...</frame>
noyranea wrote:There is actually no override in any way : the "frame" attributes are read from the "frameinstance" tag, and the content of the frame is that of the framemodel.
In your example, the scale of the frameinstance will be 3, and hadn't you set the scale in the frameinstance, it would've been the default x1 scale.
I guess we would really mostly create elements that are internally transformed (like quads etc. rotated/scaled themselves or wrapped in a transformed frame) and not on their framemodel container.
We might end up in wrapping the complete model's content in another frame to apply transformations or clipping. :?
If I were to choose, I'd prefer overriding model attributes in the instance rather than ignoring them.
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka

User avatar
noyranea
Nadeo
Nadeo
Posts: 173
Joined: 29 Apr 2014, 14:50
Location: Paris, France

Re: [ManiaScript] Data Attributes on FrameInstances

Post by noyranea » 08 Aug 2016, 15:30

The problem seems to be more complex than treating every frame attributes the same way.

Since the class & data attributes are really just a collection of tags / key + values and adding / changing them has no indirect consequence (like changing the size of the frame's content), I agree those should be set by adding the instance values to the model's ones.

As far as I know, the pos / rot / scale / hidden from the model have never been applied to the instance, but we could add this and say that any pos / rot / scale / hidden that has been set by the model can be overriden by the instance.
This would allow to instanciate a rotated or scaled frame without having to add the "rot" or "scale" attribute to each and every instance.

Do we agree on the fact that this is the ideal framemodel vs frameinstance attributes behavior ?

zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: [ManiaScript] Data Attributes on FrameInstances

Post by zocka » 08 Aug 2016, 15:47

Sounds excellent to me :thumbsup:
I believe the special cases are very limited to class and data (except there is a lot more coming with MP4 :o )
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka

Post Reply

Return to “ManiaLink”

Who is online

Users browsing this forum: No registered users and 2 guests