Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add style inheritance for theme items #850

Closed
EricEzaM opened this issue May 18, 2020 · 15 comments
Closed

Add style inheritance for theme items #850

EricEzaM opened this issue May 18, 2020 · 15 comments

Comments

@EricEzaM
Copy link

Describe the project you are working on:
Basic project

Describe the problem or limitation you are having in your project:
I have styles for button normal, pressed, hover, etc. If I want to change 1 shared parameter (e.g. border color), I have to do it all manually on each of them. Kind of a problem if I decide I want a major UI style change for many controls.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Inheritable styles

Style A is the base style (StyleBoxFlat).
Style B (StyleBoxFlat) inherits Style A.
Changing a parameter on Style A also changes it on style B, unless it has been overriden.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
I tried doing this with GD Script with a custom inspector and an exported property. I could get the base style to work, and the child style to 'inherit' it... but the issue was that I could not update the child when the base was updated. There was no easy signal to connect to when the base was changed. I didn't go very far with this trial... Maybe it needs a custom type for both 'base' and 'inheritable' classes, but at this stage I would say it could be easier to implement natively.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Not sure - see above comments. Maybe it could... but useful to have it as native functionality.

Is there a reason why this should be core and not an add-on in the asset library?:
See comments above - this is debatable.

@bojidar-bg
Copy link

bojidar-bg commented May 18, 2020

While it is possible to make different stylebox classes/resources have a "parent"/"base" property which is the same-typed stylebox they inherit, this might be a bit of a mess.

Maybe, a system similar to scene inheritance but for resources could be nice?

(edit: bad close, I blame github for interpreting a key press as a click of the "Close and Comment" button)

@fire
Copy link
Member

fire commented May 18, 2020

As far as I know the current theme system is through a cascading styles system. The parent-most node theme properties are overriden by children nodes.

@bojidar-bg
Copy link

@fire I was thinking of the same, but check the issue carefully: The proposal is not to inherit the whole styleboxes, but to be able to override only part of a stylebox in another.

@EricEzaM
Copy link
Author

@fire Yes, you can place new themes on child nodes to change their styles. But still the problem that this proposal addresses is apparent.

Say you have 5 StyleBoxFlat's that you use for your buttons. You all have the same border width on them. Now, you want to change it. You have to go to all 5 resources and change it individually - which is annoying to find, and time consuming to do.

This proposal would address this by making the system similar to inheritable scenes.

All 5 StyleBoxFlats have a "Base" StyleBoxFlat. Now, if you want to change the border thickness, you can just go to the base style and set it there, and the children would update - just like scenes. You would of course be able to override properties in child styles.

@EricEzaM
Copy link
Author

EricEzaM commented Sep 1, 2020

Proof of concept:

Changing the borders in 3 different styles with one change in the base style:
inherit_styles_1

@EricEzaM
Copy link
Author

EricEzaM commented Sep 1, 2020

In this case, the green box has overridden the border width to 50, and so changes to the base class do not change it:

inherit_styles_2

@EricEzaM
Copy link
Author

EricEzaM commented Sep 2, 2020

Further examples, show real use case. Here I have 4 buttons with their own style.
image

Currently, I have only edited their "Base" which they all share, red_base.tres.

I can edit each individual stylebox as needed. I will make hover lighter, pressed darker, and disabled very dark:
image

Cool! However, later I come back and decide that I want the borders to be bigger. Jeez, what a pain! I need to go through each stylebox for Disabled, Hover, Normal and Pressed and change them all individually.

But thanks to the base style I don't have to!
inhert_styles_example

@Zireael07
Copy link

Yeppers, I have something similar in one of my games, several styles that only differ in details.
Currently the workaround is to have several .tres files, and create any more via Save As... button. This is not real inheritance, because if I change something in the first ("base") file, it's not reflected in the others, obviously.

@Calinou Calinou changed the title Inheritable styles Add style inheritance for theme items Sep 13, 2020
@YuriSizov
Copy link
Contributor

YuriSizov commented Jun 20, 2021

This is not true inheritance as this only allows to customize on top of the base class, but I think godotengine/godot#47544 covers this proposal. (Though UX may change a bit as reduz has some additional thoughts on the matter).

Oh, and editing related styleboxes is made easier with the new theme editor, where you can pin one stylebox of a type and edit its properties, and the changes would be propagated to the rest of the styleboxes that have the same type. (Can be seen in the last clip from #2505)

@YuriSizov
Copy link
Contributor

So, @EricEzaM, do you think that godotengine/godot#47544 and godotengine/godot#50169 reasonably cover this proposal or if something crucial is still missing?

Unfortunately, this is not portable to 3.x at the moment, so if you want to test it you need to build master.

@Calinou
Copy link
Member

Calinou commented Mar 24, 2022

Closing, as the original concern should be reasonably well addressed by godotengine/godot#47544 and godotengine/godot#50169 now.

godotengine/godot#57942 also backported type variations to Godot 3.5beta2 and later. godotengine/godot#49487 is a partial backport of godotengine/godot#47544 with breaking changes omitted.

@Calinou Calinou closed this as completed Mar 24, 2022
@Calinou Calinou added this to the 3.x milestone Mar 24, 2022
@Lamby777
Copy link

Closing, as the original concern should be reasonably well addressed by godotengine/godot#47544 and godotengine/godot#50169 now.

godotengine/godot#57942 also backported type variations to Godot 3.5beta2 and later. godotengine/godot#49487 is a partial backport of godotengine/godot#47544 with breaking changes omitted.

Unless I'm missing something, this doesn't solve it for styles because you can't actually inherit styles... You still need to make an entirely new variation with a duplicated style just to change 1 thing on the style, and then you get the same problem of it being annoying to edit 1 minor thing on all styles at once (in my case, trying to make a zero-margin version of a panel). Only marginally better than theme overrides since you can edit the style in one place, but that's not relevant to this specific issue of wanting to extend styles themselves. :/

@YuriSizov
Copy link
Contributor

@Lamby777 Indeed, the problem of overriding parts of styleboxes is not resolved yet. It's now tracked in #8094 I guess. Although the problem at its core is lack of resource/data inheritance, see #4089.

@hsandt
Copy link

hsandt commented May 9, 2024

Yeah, I just wanted to override the font size for a certain sub-menu, and found no way to do so. I tried Theme > Settings button > Base Type but I get this for Button because it's a native type:

image

There is no Inherited Resource system, but I suppose we could still implement it specifically just for themes, having an (override) theme refer to some base theme as a hardcoded field?

Should we reopen an issue for the broader problem of inheriting theme properties (including the "meta properties" of font and font sizes)?

@Calinou
Copy link
Member

Calinou commented May 12, 2024

Should we reopen an issue for the broader problem of inheriting theme properties (including the "meta properties" of font and font sizes)?

Yes, I'd say this warrants a separate proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants