Changing Flex 4 theme (CSS+Skin) at run-time? - css

I have a Flex 4/Blaze/Java application and would like to provide my users with a way to switch between several pre-determined skins. Does anyone have a good example of how to do this?
Ideally, the list of themes would be provided by the server -- where the themes are stored. Or do I have to compile in all possible themes into the swf ahead of time?

Check out runtime loading of style sheets.
You can package each style sheet with its skin classes in a swf that can be dynamically loaded by your application at run time using styleManager.loadStyleDeclarations("yourTheme.swf");
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f8c.html

Related

How to use own icons in Flet

I can't find how to load my own icons in Flet.
I'm testing Flet with the intention of making a desktop app (pure desktop, not Internet needed), but I'm not able to use my own icons to begin with. I can only use the ones that come inside ft.icons, but I'd rather use my own by loading them from a folder similar to /assets/icons. Can I do that? How?
Thanks.
Currently, I don't see a way of doing this; however, you could use the Image class instead.
I would suggest you create an assets folder under your main project folder.
Let's assume you have the following folder structure on your project:
/assets
/icons/my-icon.png
main.py
When you are running your app, you should provide that folder to the initializer in the following way:
flet.app(target=YourApp(), assets_dir="assets")
Then you can access your images there directly and create an Image instance in the following way:
test_image = flet.Image(src="icons/my-icon.png", width=32, height=32, tooltip="Image Tooltip")
You can nest these Image controls inside of anything you want, so you have a lot of flexibility.
The only downside of doing it this way is if you are using light/dark themes on your app. Compared to the Icon class, you will have to specify the light/dark theme versions yourself and update them manually when you are switching your theme.
Here is the official documentation

How to edit the style of multiple Oracle Apex applications in a workspace

I want to edit the style of multiple applications inside my workspace with the less amout of effort. What I mean by "edit the style" is font size, background color, position, etc.
My idea was creating a CSS file at "Static Workspace Files" with the classes I want and applying them to the apex items needed. Applying this in a region for instance:
*.font16{
font-size: 16px;
}
The problem is: modal pages can't find the file, which is not a problem in nomral pages. I'm using the path '#WORKSPACE_IMAGES#styles.css' in the page "CSS > File URLs" setting.
I'm not sure if this is the right approach, maybe I should edit Themes or Templates, but since I'm pretty new to Apex I chose CSS for familiarity.
Application Express v20.1
That's what Static Workspace Files are meant for, files that can be used by multiple applications in the same workspace.
The easiest approach for this is to create a CSS, like what you've done.
You don't need to inlcude the file in every single page, which would become a maintenance nightmare eventually.
You can simply include the file at the application level:
In Share Components, go in the User Interface Attributes and include the file under Cascading Style Sheets.
I usually have one global.css file (as a static workspace file) for anything common to all my apps and one app.css per application (as a static application file) for things specific to the current application.
Note that application exports will contain the static application files, but they will not contain the static workspace files. You will need to export/import them yourself.
Did you try Theme Roller? Run the page, it is down in developer's toolbar.

Angular Material 2 themes - output single file or lazy load

Disclaimer: There are a few questions on SO regarding CSS and debates over a single or multiple CSS files but I think this is a bit different
I have a pretty big Angular 7 app using Angular Material 2 and I want to introduce themes. Each theme will be retrieved on user login (the theme is saved on the server and cannot be changed by the user).
The question is mainly regarding whether it would be best to export a single CSS file using top-level classes (body or app container) for each theme, replacing only classes that change for each theme or lazy load a new css file on top of the main css file with only the classes that are getting overwritten.
My biggest concern with the first option is getting a huge single CSS file. The current file is already around 300kb (unminified CSS is about 11k lines of code) and with themes ranging from 200-500 lines each and there could be 10+ themes, the file can easily get double or even triple that amount.
On the other hand, lazy loaded CSS might cause the user to download 2 smaller files but the implications might be worse. For example a lazy loaded CSS file needs to be exported with separate configs in Angular CLI and the name needs to be specific so it can be loaded from Angular on login which means caching might be an issue if something changes and also no versioning (eg. theme-blah-2.17.css) is also not possible in the name of the file. Possibly other implications that I cannot think of at the moment too.
Look at how material handles themes.
Also, take a look at how teradata Covalent handles themes.

Flex - how to switch to another SWC theme at run time?

My goal is to have more themes for my application and if possible, bundle them with the application itself, not load them at runtime using IStyleManager.loadStyleDeclarations().
Using the theme command-line option, you can have more than one "compile-time theme" bundled with your application according to docs:
theme filename [...] Specifies a list of theme files to use with this application. Theme files can be SWC files with CSS files inside them or CSS files.
However, I wasn't able to find an example how to actually do that (use the += syntax on command line?) and switch between those themes at runtime. What API should I use?
Using the theme command-line option, you can have more than one
"compile-time theme" bundled with your application according to docs:
Yes, You can add additional themes using the += in your command line.
I do exactly this for the Flextras mobile demos; including both the generic Spark theme with the Mobile theme to create the app.
However, both themes will be attempted to be used. I believe the second takes precedence. That means for every class where you want to use the "other theme" you have to specify that theme be used manually. This could get pretty complex very quickly; and you'll have to re-create a lot of spark skins in your application. I've done some work for a client around this who wanted to use our mobile DropDownList in both their normal application and in a mobile application from the same code base. I think the appropriate skin is conditionally applied at runtime using CSS; however we had to create a skin for the "non-mobile use" that explicitly specified the non-mobile skins for the individual elements (Such as the scroll bars)

Flex External Stylesheet Conventions

I know that there are questions regarding this same topic, but for HTML. What are some good conventions in regards to using external stylesheets in a Flex app.? How would you break up the stylesheets (names of stylesheets and what they include)?
Flex compiles the external CSS file when you publish your project.
There is a way to load CSS at runtime using Flex; it can be done by compiling CSS files into SWF files and load them at runtime using StyleManager.loadStyleDeclarations.
See the LiveDocs on Stylesheets at Run Time for more info.
Some conventions we use in organizing stylesheets:
Have one main.css stylesheet that holds all of the data for skinning the base application.
Have one fonts.css stylesheet to store all of the fonts in the main app, because these can get quite messy.
The main.css stylesheet is included in the main swf via the <mx:Style source="main.css"/> tag. We load our app with as little as possible, and once everything is loaded, if we need to immediately show some text (sometimes we just have a video playing if it's an advertising site), we fade/tween in the main elements and load the fonts.css via StyleManager.loadStyleDeclarations at runtime.
If we have an admin panel, we have an admin.css stylesheet which we load at runtime because the main app doesn't need it.
We don't need to divide up the CSS anymore than that because we usually create a whole set of skins in a Theme, so the stylesheet is just applying those skins to components and is pretty lean (using Flex 4). I tend not do divide stylesheets into anything smaller (like "pages.css", "comments.css", "popups.css", or even "controls.css", etc.) because it would be overkill and too much to manage for little in return. That's common with HTML, but that's because HTML requires CSS for nice presentation; Flex could do without CSS entirely.
When developing, one of us usually develops most of the skin right away (having a default wireframe setup, like those found on ScaleNine as they do the photoshop/flash/after-effects. There's no way to not have to recompile the css swf if you make changes. But if it is loaded at runtime, you only have to recompile the css file and not the main swf, which is useful but not really useful during hardcore skin development.
I tried keeping the main stylesheet separate during development (in a custom Theme), and it made development a LOT harder, because I had to recompile the css separately every time I made a change and sometimes I had to recompile the main app too, and there were strange and hard-to-track-down bugs, etc. Then I was compiling two different apps. So I recommend keeping the main css file part of the main app.
If you wanted runtime css without having to recompile anything, try Ruben's CSS Loader and check out the source. But that would come at a runtime performance cost.
Flex is not something I've dealt with, but I did some research. It looks like the code to call a remote stylesheet is this:
<mx:Style source="com/example/assets/stylesheet.css" />
Flex Quick Start: Building a simple user interface: Styling your components says this:
Note: You should try to limit the
number of style sheets used in an
application, and set the style sheet
only at the top-level document in the
application (the document that
contains the tag). If
you set a style sheet in a child
document, unexpected results can
occur.
The implication of this seems to be that multiple stylesheets are not really possible. It sounds like what you want to do is organize your stylesheets, check out Organizing Your Stylesheets and Architecting CSS for some ideas for approaches. It looks like you have classes and basic tags, but the W3C stylesheet specifications are different from the Flex stylesheet specification.
As a non-Flex developer, Namespaces looks interesting as a way to organize namespaces: How to use the new CSS syntax in Flex 4.

Resources