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

Allow disabling elements; add :focused and :disabled states #10291

Closed
wants to merge 1 commit into from

Conversation

v-rob
Copy link
Member

@v-rob v-rob commented Aug 13, 2020

This PR allows formspec elements to be disabled with set_disabled[<name 1>,<name 2>,...] and styled with the :focused (last interacted with element) and :disabled style selectors.

Nearly all interactive elements can be disabled, with the effect of graying out the text for most of them (it all depends on what Irrlicht decides to do). Disabled buttons, by default, have gray text and a content_offset of 0 when pressed. The default button border also does not indent in the pressed state when disabled. This cannot be changed, but I doubt anyone would want such behaviour on a disabled button anyway.

The :focused selector takes lower precedence than everything except :default whereas :disabled takes highest precedence.

This screenshot shows all the features. The right elements are disabled elements, whereas the left are enabled. The bottom two buttons use the :focused and :disabled selectors combined with other selectors.

image

To do

This PR is Ready for Review.

How to test

Make sure disabled elements don't interact at all, especially buttons; check that selectors work properly, including combination. The above screenshot:

formspec_version[4]
size[9,13]

set_disabled[checkbox-2,button-2,image_button-2,item_image_button-2,table-2,textlist-2,dropdown-2,field-2,pwdfield-2,textarea-2,scrollbar-2,tabheader-2]

checkbox[1,0.5;checkbox-1;checkbox-1]
button[1,1;3,0.7;button-1;button-1]
image_button[1,2;3,0.7;air.png;image_button-1;image_button-1]
item_image_button[1,3;3,0.7;air;item_image_button-1;item_image_button-1]
table[1,4;3,0.7;table-1;table-1,-;1]
textlist[1,5;3,0.7;textlist-1;textlist-1,-;0]
dropdown[1,6;3,0.7;dropdown-1;dropdown-1,-;0]
field[1,7;3,0.7;field-1;field-1;field-1]
pwdfield[1,8;3,0.7;pwdfield-1;pwdfield-1]
textarea[1,9;3,0.7;textarea-1;textarea-1;textarea-1]
scrollbar[1,10;3,0.7;;scrollbar-1;scrollbar-1;0]
tabheader[1,11.7;3,0.7;tabheader-1;tabheader-1,-,-;1;;]

checkbox[5,0.5;checkbox-2;checkbox-2]
button[5,1;3,0.7;button-2;button-2]
image_button[5,2;3,0.7;air.png;image_button-2;image_button-2]
item_image_button[5,3;3,0.7;air;item_image_button-2;item_image_button-2]
table[5,4;3,0.7;table-2;table-2,-;1]
textlist[5,5;3,0.7;textlist-2;textlist-2,-;0]
dropdown[5,6;3,0.7;dropdown-2;dropdown-2,-;1]
field[5,7;3,0.7;field-2;field-2;field-2]
pwdfield[5,8;3,0.7;pwdfield-2;pwdfield-2]
textarea[5,9;3,0.7;textarea-2;textarea-2;textarea-2]
scrollbar[5,10;3,0.7;;scrollbar-2;scrollbar-2;0]
tabheader[5,11.7;3,0.7;tabheader-2;tabheader-2,-,-;1;;]
				
style_type[button:default;bgcolor=gray]

style_type[button:focused;bgcolor=red]
style_type[button:focused+hovered;bgcolor=orange]
style_type[button:focused+pressed;bgcolor=yellow]
set_focus[focus-style;true]
button[1,12;3,0.7;focus-style;Focused Styling]

style_type[button:disabled;bgcolor=green]
style_type[button:disabled+focused;bgcolor=violet]
style_type[button:disabled+hovered;bgcolor=cyan]
style_type[button:disabled+pressed;bgcolor=blue]
set_disabled[disable-style]
button[5,12;3,0.7;disable-style;Disabled Styling]

@Zughy
Copy link
Member

Zughy commented Aug 13, 2020

Great job as always :)
A few suggestions:

  • greying out item buttons and item image buttons. I mean the image, not just the text
  • greying out tables, tabheaders and textlists text too to make it consistent
  • greying out the background of fields, textareas and pwdfields

@v-rob
Copy link
Member Author

v-rob commented Aug 13, 2020

Sorry, but these aren't very feasible just yet:

  1. I'd rather not try image modifiers yet until/if we have an image modification property; otherwise, the image will be forced to be gray without any way for mods to change it. Better to let the mods desaturate it themselves for now (^[colorize might work).
  2. tabheaders don't have an setOverrideColor property, and I can't add it without absorbing it's entire code. tables have tableoptions which is certain to interfere with style, so I don't want to touch it either for now.
  3. Sorry, can't change the background color for these either. Irrlicht doesn't support it.

None of these are final. It's just that Irrlicht limitations don't make these possible on a short-term basis, so this PR in particular won't add them. Later, when we do styling revamps on other elements, these features will almost certainly be added.

@appgurueu
Copy link
Contributor

If I get you right, you are using focused as "not disabled" ?

I consider this to be misleading. Focused means the element is basically the "last selected element". The opposite of disabled is enabled

@v-rob
Copy link
Member Author

v-rob commented Aug 15, 2020

No, :focused is the last selected element, like you think it should be, and like CSS :focus. Was I unclear somewhere?

Also, forgot to mention, but (pwd)fields and textareas now have gray text when disabled by default.

@paramat paramat added Feature ✨ PRs that add or enhance a feature Formspec labels Aug 15, 2020
@appgurueu
Copy link
Contributor

No, :focused is the last selected element, like you think it should be, and like CSS :focus. Was I unclear somewhere?

Also, forgot to mention, but (pwd)fields and textareas now have gray text when disabled by default.

Sorry for the misunderstanding.

@v-rob v-rob added this to PRs: Highest priority on top in Formspec Priority List Aug 20, 2020
@SmallJoker SmallJoker added the Rebase needed The PR needs to be rebased by its author. label Dec 26, 2020
@v-rob
Copy link
Member Author

v-rob commented Jan 29, 2021

Closing all my inactive formspec PRs. There's little interest in them as of now and the formspec replacement is making fair progress, and I want to avoid causing more problems like #10083 due to my interests being divided between the replacement and extra features on the current system. If anyone really thinks that any of these are essential and gives a good reason why it really can't wait for the replacement (better than saying that one mod needs it), I'll reopen.

I know an argument might be put forth that there's no knowing when the formspec replacement will come out, but I really think that it will become a reality, although maybe not soon. I might not display my progress prominently, but it's moving along at a steady rate.

@kilbith
Copy link
Contributor

kilbith commented Jan 29, 2021

Formspecs will not be replaced anytime soon by modders, man.

@v-rob
Copy link
Member Author

v-rob commented Jan 29, 2021

True, but that doesn't mean that we have to keep adding features to them forever. As I said, I'll reopen them if there's enough interest, meaning multiple mods need it. ATM, I'm trying to focus my work without a lot of sidetracking (and get the PR count down a little). For instance, I left #8679 open because multiple people expressed how useful it would be, while the others I closed had no such modder support.

@rubenwardy rubenwardy moved this from PRs: Highest priority on top to Done in Formspec Priority List Nov 20, 2021
@rubenwardy rubenwardy added the Adoption needed The pull request needs someone to adopt it. Adoption welcomed! label Apr 11, 2023
@v-rob v-rob deleted the formspec-states branch January 27, 2024 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Adoption needed The pull request needs someone to adopt it. Adoption welcomed! Feature ✨ PRs that add or enhance a feature Formspec Rebase needed The PR needs to be rebased by its author.
Projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants