Theming and scopes

Posted on
  • I have noticed that if I initiate a menu, once returning to my normal screen render, text is offset slightly on the y axis. I assume this is due to the menu setting up some font settings.

    Is theming always global?

    If it is, has there been any discussion about making it scope specific? So if you have a function and you set the forecolour or font etc within that function, anything rendered to screen from that scope (the function and sub functions) uses that theming.

    This seems like a sensible approach to me as as I build up my app and have "renderSomeThing" type methods, if I have scope specific colouring I either have to make sure every single render method sets the theme, which makes it hard to make compiler safe code. Or every method which changes something needs to call a theme reset at the end.

  • Is theming always global?

    Well, Graphics state is always global - you should always get in the habit of calling g.reset() before you start rendering in a function where you're not 100% sure of the graphics state it's called from.

    If you just do g.drawString then font, alignment, color, etc could be set to anything.

    The current solution is just a sensible compromise of complexity and memory usage... I guess potentially we could have a way to 'clone' a graphics instance into a variable where state for that var is kept separately - but I think the end result is it'd end up getting used pretty lazily and we'd end up storing loads of different graphics states for things that really didn't need it.

  • I agree that actually implementing it in practice would be difficult. I can actually do this with typescript using transformers by using custom decorators at the top of methods (eg @themed({themeOptions}. Which could inject lines at the top of method to set theme options and lines at the bottom to reset when compiling.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Theming and scopes

Posted by Avatar for charlie @charlie