Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stars-one/icontextfx

a text control can use icon awesome font for javafx8/tornadofx 为JavaFx/Tornadofx实现的字体图标控件
https://github.com/stars-one/icontextfx

javafx-8 javafx-library kotlin kotlin-library tornadofx

Last synced: about 1 month ago
JSON representation

a text control can use icon awesome font for javafx8/tornadofx 为JavaFx/Tornadofx实现的字体图标控件

Awesome Lists containing this project

README

        

# IconTextFx
![](https://jitpack.io/v/Stars-One/IconTextFx.svg)

a control which extends Text and can use awesome font icon for JavaFx/Tornadofx

This liarbay includes the materical icon from [Material Design](https://github.com/Templarian/MaterialDesign),it has 5000+ icons.

You can download the `icon-preview.html` to see the icon.

[中文文档](https://github.com/Stars-One/IconTextFx/blob/master/readme_cn.md)

## Usage in TornadoFx
### 1.Import depdendency
**Maven:**

open the `setting.xml `file and add following code
```


jitpack.io
https://jitpack.io

```

add the dependency in your `pom.xml`

Input the late-version,**please look the jitpack picture to get the late version**
```

com.github.Stars-One
IconTextFx
late-version

```

**Gradle:**

**Step 1.** Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
**Step 2.** Add the dependency

```
dependencies {
implementation 'com.github.Stars-One:IconTextFx:late-version'
}
```

### 2.Use

There is 3 parmas for it.All of them is String.

|name |descption |example |
|-- |-- |-- |
|iconName |the name of icon |account,you can see more in the `icon-preview.html` file|
|size |the size of icon|accept number with unit,like 1px,1em...|
|color|the color of icon |accept hex color value or color name,like #f391c8,red... |

```
icontext("account","20px","red"){

}
```
## Use in JavaFx

### 1.import

click and download this jar

[IconTextFx-1.2-javafx.jar](https://github.com/Stars-One/IconTextFx/releases/download/v1.2/IconTextFx-1.2-javafx.jar)

### 2.Use
You can use the `MaterialDesignIconText` or `MaterialDesignIconTextFactory` to get the icon text control.

**like this:**
```
MaterialDesignIconText iconText = new MaterialDesignIconText("account");
//set the color
iconText.setColor("red");
//set the size
iconText.setSize("20px");
```

**The parameter is same as the above-mentioned table.**

## Advanced Usage
### MaterialDesignIconTextFactory

when you want to get more icon text,you can use this factory to get the icon text.

like this:

```
//want to get a icon by icon name
val icon = MaterialDesignIconTextFactory.getIconText("account")

//want to get icons with a list saving more icon name
val dataList = arraylistof("account","close")
val icons = MaterialDesignIconTextFactory.getIconTextList(dataList)

//want to get all icons
val icons = MaterialDesignIconTextFactory.getIconTextALL()

```
### IconText
you can use this to load your custom tff file and show the icon font.

```
val iconText = IconText(new FileInputStream(File("D:\\xx.ttf")),'\ue001')

val iconText = IconText("/ttf/xx.ttf),'\ue001')
```

**Note: the method of setColor and setSize are same as the above-mentioned table.**
## Main Code Analysis

How to accomlish a icon text?It's so easy.

1. load the tff file
2. get the unicode
3. set unicoe to the text control

**like following code:**
```
text {
font = loadFont("/ttf/MaterialDesignIconsDesktop.ttf", 20)
text = '\ue001'.toChar().toString()
style {
fontSize = 2.em
fill = c("red")
}
}
```

it's same as when you use javafx.

**Note:**

In fact,the most unicode value is a hex data.For example,'\ue001' mapping the hex data `0xe001`

## Thanks

- [Material Design](https://github.com/Templarian/MaterialDesign)
- [MaterialDesign-Font](https://github.com/Templarian/MaterialDesign-Font)
- [tornadofx](https://github.com/edvin/tornadofx)
- [fonteditor](https://github.com/ecomfe/fonteditor)