Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » [NEON] Inclusion of additional icons from font-awesome
[NEON] Inclusion of additional icons from font-awesome [message #1722599] Sat, 06 February 2016 11:24 Go to next message
Samuel   is currently offline Samuel Friend
Messages: 22
Registered: January 2012
Junior Member
Dear all,

Scout provides some icons in the class "AbstractIcons". However, I want to use additional icons in my application.

As I have seen, Scout uses an icon font ("font-awesome") to display icons.
The font is stored in a file "scoutIcons.woff" and contains Scout-specific icons and some (but not all) icons from "font-awesome".
I want to use more icons from "font-awesome".

I have tried the following: I downloaded "font-awesome", renamed it to "scoutIcons.woff" and saved it to the HTML project below "WebContent/res".
After that, the icons from "font-awesome" were available, however the Scout specific icons (as e.g. the folder and the smartfield magnifying glass) were no longer available.

What is the preferred way to include "font-awesome" into my application without losing the Scout specific icons?

Regards, Samuel
Re: [NEON] Inclusion of additional icons from font-awesome [message #1722703 is a reply to message #1722599] Mon, 08 February 2016 12:20 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 205
Registered: November 2010
Senior Member
Hi Samuel

The scoutIcons.woff file contains some custom icons that are not included in Font Awesome, e.g. the magnifying glass used in the smart fields. If you simply replace the default font file without adding the SVGs in org.eclipse.scout.rt.ui.html/src/icons, the corresponding icons will be missing in the UI.

Because it is much simpler, we recommend that projects contribute their own icons in a separate file. Here is how to do it:


  1. Add the *.woff File to your.project.ui.html/src/main/resources/WebContent/res
  2. Create a custom CSS (LESS) macro:

    1. your.project.ui.html/src/main/js/your-project/style/fonts.css
      @font-face {
        font-family: awesomeIcons;
        font-weight: normal;
        src: url('fontAwesome.woff') format('woff');
      }
      
      .font-awesomeIcons {
        font-family: awesomeIcons, @font-default-family;
      }

      The first rule is a CSS font-face definition which makes the font from "fontAwesome.woff" available in CSS as "awesomeIcons". The second rule is used when specifying an iconId from the scout model (the font name prefixed with "font-").
    2. your.project.ui.html/src/main/js/your-project-all-module.css
      //@include("your-project/style/fonts.css")

      Your own module only consists of one file (yet).
    3. your.project.ui.html/src/main/resources/WebContent/res/your-project-all-macro.css
      //@include("scout-module.css")
      //@include("your-project-module.css")
      

      The first line includes all default CSS definitions from Scout, the second adds your own new custom rule set.

  3. Change your *.html files to use the new macro instead of the default one. Open all *.html files in your.project.ui.html/src/main/resources/WebContent/res and replace
        <scout:stylesheet src="res/scout-all-macro.css" />
    with
        <scout:stylesheet src="res/your-project-all-macro.css" />

  4. Use the new font icons as follows

    • In CSS (for hard-coded UI icons):
      .my-widget::before {
          content: '\F0FC';
          font-family: awesomeIcons, scoutIcons, @font-default-family;
      }

    • In Scout model code (Java):
      // Your own icon constants class
      public class MyIcons extends AbstractIcons {
        // Pattern: "font:<CssFontName> \u<Unicode>"
        public static final String Beer = "font:awesomeIcons \uF0FC";
      }
      
      getMyWidget().setIconId(MyIcons.Beer);
      

Regards,
Beat

[Updated on: Tue, 09 February 2016 08:02]

Report message to a moderator

Re: [NEON] Inclusion of additional icons from font-awesome [message #1722749 is a reply to message #1722703] Mon, 08 February 2016 19:57 Go to previous messageGo to next message
Samuel   is currently offline Samuel Friend
Messages: 22
Registered: January 2012
Junior Member
Dear Beat,

Thank you very much for your very detailed explanations. I finally got it to work.
There was a little intricacy with respect to the directories in which the files must be created.
For some reason, the framework searches the files "myProject-all-module.css" and "myProject-all-macro.css" in different directories (see the methods "getMacroFileLookup(...)" and "getModuleFileLookup(...)" in class "ScriptFileLocator") .

To make things clear, let me clarify the steps (1) and (2) from your explanation above.

(1) Copy the file "fontawesome.woff" to "/myProject.ui.html/src/main/resources/WebContent/res".
(2.a) Create the file "fonts.css" (content: see above) and copy it to "/myProject.ui.html/src/main/js/accounting/style".
(2.b) Create the file "myProject-all-module.css" (content: see above) and copy it to "/myProject.ui.html/src/main/js".
(2.c) Create the file "myProject-all-macro.css" (content: see above) and copy it to "/myProject.ui.html/src/main/resources/WebContent/res".

Thanks, Samuel
Re: [NEON] Inclusion of additional icons from font-awesome [message #1722793 is a reply to message #1722749] Tue, 09 February 2016 08:14 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 205
Registered: November 2010
Senior Member
Hi Samuel

Yes, you are right, not all files reside in the same directory. I have fixed a small typo in my instructions (location of fonts.css).

The macro is the file referenced in your *.html files, therefore it needs to be in the WebContent/res order. It does not necessarily need to include custom code, e.g. you could write a macro that includes the "scout-module.js" and the "third-party-module.js".

The module is the code of a single software module. By convention, we place all module files on the root of the classpath, therefore the name needs to be unique (that's why we use the "your-project-" prefix). However, you might also place your module in /src/main/js/your-project/ and simply call it "module.css".

To ease development, not all code must be contained in a single file. Instead, many small files can be included in the module. They can even be other modules. To avoid filename collisions, we use a single directory as prefix, e.g. scout/style/fonts.css is different from your-project/style/fonts.css. This is similar to Java's packages, but shorter ("org/eclipse/scout/rt/ui/html" vs. "scout").

It works alike for *.js files.
Re: [NEON] Inclusion of additional icons from font-awesome [message #1828148 is a reply to message #1722599] Tue, 02 June 2020 15:23 Go to previous messageGo to next message
Jerome HolbeinFriend
Messages: 13
Registered: June 2020
Junior Member
Dear All,

This procedure to add additional FontAwesome Icons to a scout project must have changed with the release of Scout 10. I tried the points Beat provided and then translating those through the Migration Guide but somehow failed miserably.
How can I accomplish this using Scout 10, if my starting point is also a .woff file?

Thank you and best regards,

Jerome
Re: [NEON] Inclusion of additional icons from font-awesome [message #1828153 is a reply to message #1828148] Tue, 02 June 2020 17:12 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 205
Registered: November 2010
Senior Member
Hi Jerome

Yes, the Scout-specific method to build frontend resources at runtime was replaced by a build-time process powered by webpack. There are no more xyz-module and xyz-macro files. Instead, the entire application is bundled together from a few entry points defined in your project's webpack.config.js. When you generate a new Scout project, these files should be created for you. All that remains to do, is to add the webfont files and the font face definition.

Maybe it helps the most to compare your project with a working example!
The "Contacts" demo app also includes FontAwesome icons, so this should be exactly what you want. Have a look at the code here:
https://github.com/BSI-Business-Systems-Integration-AG/org.eclipse.scout.docs/tree/releases/10.0/code/contacts/org.eclipse.scout.contacts.ui.html

  • Font files: src/main/resources/WebContent/fonts
  • Font definitions: src/main/js/style/fonts.less
  • Include font definitions in build: src/main/js/index.less

Regards,
Beat
Re: [NEON] Inclusion of additional icons from font-awesome [message #1828189 is a reply to message #1828153] Wed, 03 June 2020 13:16 Go to previous messageGo to next message
Jerome HolbeinFriend
Messages: 13
Registered: June 2020
Junior Member
Hi Beat,

Thank you very much for your swift reply. Worked like a charm.

Best regards

Jerome
Re: [NEON] Inclusion of additional icons from font-awesome [message #1830700 is a reply to message #1722599] Fri, 31 July 2020 18:45 Go to previous message
Samuel   is currently offline Samuel Friend
Messages: 22
Registered: January 2012
Junior Member
Hi Beat,

What a nice coincidence. I recently migrated my project from Scout 7 to Scout 10. The last thing that I was going to fix were the fonts. Then I stumbled across this forum post that I opened a few years ago to learn about how this works in Scout 7. Nicely enough, I also found the answer of how this works in Scout 10.

I can confirm that your instructions worked like a charm.

Many thanks, Samuel
Previous Topic:SSL support & integration
Next Topic:Scout 10 HelloWorld sample application Maven build issue
Goto Forum:
  


Current Time: Tue Apr 23 11:53:09 GMT 2024

Powered by FUDForum. Page generated in 0.04257 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top