Archive 17/01/2023.

Quick reminder for the newbies subclassing from UI elements

throwawayerino

Calling SetStyleAuto() on a UI element is translated to SetStyle("ClassName") where ClassName is the name of the UI element’s class. It then searches for the name in the xml file set in SetDefaultStyle(). If you subclass from Button for example and call the new class MyButton, calling SetStyleAuto() will search for “MyButton” in the default style. If you don’t have a style set for it you’ll get a white rectangle or box.
A solution is to either to call SetStyle("Button") to get the parent’s style, or to define a style called “MyButton” in the xml and customize it

Also, in the RegisterObject() method (if you made one) calling URHO3D_COPY_BASE_ATTRIBUTES(ParentClassName) after registering it is important to make sure the editor knows how to handle it.

EDIT: wtf I just want to talk about UI

Modanung

Wouldn’t it make more sense if SetStyleAuto() were only to report the absense of any appropriate style, without clearing the element’s style, in cases where no suitable style is found?

Leith

Absolutely, I do not like obscurity in my game engine codebase. I would rather try to reduce or remove it.

weitjong

When the style is not applied then you get a naked UI-element. The SetStyleAuto() is just a shorthand for calling SetStyle() with the class name as parameter. It does not perform the “clearing” first.

Probably worth to mention that the style can be inherited in the stylesheet.

Leith

You missed your opportunity to explain all this, it was explained several posts ago, but thanks

Modanung

That seems to be the case. But don’t you think it would maybe make more sense for SetStyleAuto() to look more like this?

if (StyleExists(className))
    SetStyle(className);

…instead of style = noStyle.
When I’m out of clean clothes, I wear dirty clothes. I do not walk the streets naked. :vulcan_salute:t3:

weitjong

I haven’t looked at the code yet in the UI Subsystem, but in my view unless we have changed how the style is applied fundamentally, otherwise what you proposed with the extra if exists check would produce exactly the same thing. Except, when you also add another else logic to, say, trying to get the name of the parent class via some kind of reflection and use the style of the parent class name.

throwawayerino

You could have a template method like this:

template<class T>
void SetStyleAuto() {
	if(StyleExists(T))
		SetStyle(T)
	else
		SetStyle(T::BaseClassName)
}
weitjong

But why do we need to go that far to achieve this? When someone derives a new class from a base UI class, it is most likely he/she wants to add more attributes or logic, and that would mean the style of the base class is actually not fit for the derived class. Granted it will make the derived class get some base style applied when its user forget to define the derived style for the derived class in the stylesheet file. Isn’t it the easier solution would be to do something like:

<element type="MyButton" style="Button" auto="false">
    <attribute name="My Extra Attribute" value="true"/>
</element>
throwawayerino

That also works, but when you’re prototyping (or simply don’t know about this) it can act as a safeguard. But in the end your solution is the most optimal

Modanung

I wasn’t so much talking about subclassing actually. With little experience with Urho’s UI, my logic tells me it does not make sense to overwrite existing style settings with none as I imagine SetStyleAuto() would be most useful when iterating over a bunch of UIElements. One could make differently coloured themes that share a single base style that would always be loaded first. Elements without colour could be left out the settings for the coloured elements.

Leith

Urho’s gui is horrible, to be honest but we can mostly ignore it

Leith

dropping in a replacement gui rendering system is completely doable

Leith

dont let these guys make you think there are limits, they are not clearly stating there are, so the chances are good

weitjong

It almost sounded like you want to reimplement the “cascading style sheet”. :slight_smile:

Modanung

For now I’m dealing with Qt. :wink:
…which has its own minor flaws and some bugs that are reaching puberty.

Leith

does urho conform to css? lmao

throwawayerino

That would be a nightmare for everyone.

Leith

do what you need to do, ask what you need to ask, I for one will help you achieve it, but do not think for a second that urho is some kind of panacea - it hurts my head just asking about making moderate changes, let alone the harder ones. People around here are allergic to change, they think we carry in disease, they are closed of mind and their eyes are shaded, but this does not mean that I can not help you.

throwawayerino

real deep thoughts here

Modanung

@Leith I don’t think this is true at all. Apart from the fact that some changes should be resisted, more often progress is welcomed by the community but left unfinished by the loudmouth that bites off more than (s)he can chew.

Planning a journey is not the same as refusing to travel… also there’s no team in hitchhiking. :ghost::+1:

Leith

I’m an agent of (hopefully, positive) change, it is my nature to question the status quo, and find fault in the machine. I am a systems analyst among other titles, it’s hard not to apply that to everything that comes my way. So far I have issued a range of suggestions for improving Urho, but the only one that has been well-received is also the only one that could break existing projects. I don’t really know what to make of that :slight_smile:

Pencheff

You can always fork/branch and PR. Atomic went this way of changing too much, look at where it is now…

Modanung

Panta rhei is the status quo, although sometimes the flow may seem viscous to the point of asphalt. :volcano:

guk_alex

In some point when your changes gone radically different and you don’t want to fork - you can try to convince everybody else about major version update, 2.0, in this situation people can accept compatibility breaks without arguing too much. And it seems more reasonable instead of working on you own with your fork with the same kind of updates. But you need to convince the rest of active community to do that and make rough plans about the future.

Leith

Man, I have not made any game breaking changes. I would like you, or anyone, possibly an ass hat, to show me where I ever did. I have some changes in mind. I will offer them back. Free of charge.

Leith

thats not my intent, and heres some more character to meet the 20 character quota

weitjong

Closed as it has gone off topic.