Skip to content

css preset cleanup

Jonathan Wilkes requested to merge css-preset-cleanup into master

@aggraef I believe you mentioned something about going down a rabbithole with preset cleanups. Here's one such rabbit hole.

Check out the code added in function skin-- I have to do that because we need to parse the stylesheet in order to fetch the relevant styles to apply to the svg background image. HTML5 lets you switch out the value of the href, and doing so does the right thing by loading the new external stylesheet and re-applying the styles.

But-- it doesn't give you any event callback to know when the new stylesheet has finished loading! So a subsequent call to parse the stylesheet will race.

The workaround is to create a new link element, populate it with the new href attr, set an onload callback for it, then switch it out for the old link. Mutating the dom to add the new link element will trigger the load callback, which we then use to parse the stylesheet once it's ready.

I make fun of HTML5 a lot, but honestly-- this was a matter of reading an actual spec, looking at various stackoverflow workarounds, and choosing this path which-- while dumb-- does indeed work. I'm sure Juce and Qt and Gtk 4 look beautiful. But I'd bet there is close to 0% chance that every wonky thing we'd want to do in Purr could be done using the nice-and-easy API they ship and write tutorials about. As much as I dislike fudging around with Javascript, I simply wouldn't contribute any code at all if I was required to drop down to C++ and do business outside the common, documented set of widgets.

Also note-- this fix adds some jank to changing presets in the dropdown menu. I guess the replaceChild method somehow triggers a relayout after removing the first stylesheet, and then relayout again after loading the new one. I couldn't find a pattern of adding/removing link elements that got rid of the jank, so I guess we're stuck with it.

Anyway:

  • fixed new_object_textentry background respect the current GUI preset
  • got the little svg lock styled to match GUI presets
  • fixed background for broken object text
  • removed CSS that's no longer used
Edited by Jonathan Wilkes

Merge request reports