@lightningjs/blits 1.7.1 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.8.1
4
+
5
+ _29 oct 2024_
6
+
7
+ - Fixed issue with array based props not triggering reactivity
8
+ - Upgraded renderer to 2.5.1
9
+
10
+
11
+ ## v1.8.0
12
+
13
+ _22 oct 2024_
14
+
15
+ - Refactored TypeScript definitions to give better autocompletion and general TS support for business logic
16
+ - Added option for custom characters in MSDF generated fonts
17
+ - Added export for symbols
18
+ - Upgraded renderer to 2.4.0
19
+ - Added transition progress event
20
+
21
+
3
22
  ## v1.7.1
4
23
 
5
24
  _14 oct 2024_
@@ -32,6 +32,40 @@ The Text-tag accepts the following attributes:
32
32
  - `contain` - the strategy for containing text within the bounds, can be `none` (default), `width`, or `both`. In most cases, the value of this attribute will automatically be set by Blits, based on the other specified attributes
33
33
  - `textoverflow` - the suffix to be added when text is cropped due to bounds limits, defaults to `...`
34
34
 
35
+ ## Text dimensions
36
+
37
+ When you want to center your Text element, or properly position other Elements around your text, it is useful know the exact dimensions of your text.
38
+
39
+ Similar to the Image element (i.e. an Element with a `src`), Text elements also accept the `@loaded` attribute. This event is called, as soon as the text is rendered, and passes in the dimensions of the generated text texture.
40
+
41
+ The example below shows how to use the `@loaded`-attribute to position an Element as an underline, under a piece of text.
42
+
43
+ ```js
44
+ export default Blits.Component('MyComponent', {
45
+ template: `
46
+ <Element>
47
+ <Text :content="$myText" @loaded="$textLoaded" />
48
+ <!-- gray underline -->
49
+ <Element :w="$w" h="2" y="$y" color="#333" />
50
+ </Element>
51
+ `,
52
+ props: ['myText'],
53
+ state() {
54
+ return {
55
+ w: 0,
56
+ y: 0,
57
+ }
58
+ },
59
+ methods: {
60
+ textLoaded(dimensions) {
61
+ console.log(`The text has a width of ${dimensions.w} and a height of ${dimensions.h}`)
62
+ // set the underline width to the exact width of the text
63
+ this.w = dimensions.w
64
+ // position the underline 8px below the text
65
+ this.y = dimensions.h + 8
66
+ }
67
+ }
68
+ ```
35
69
 
36
70
  ## SDF and Canvas2d
37
71
 
@@ -49,7 +83,7 @@ When you create a new Blits app using the available [getting started boilerplate
49
83
 
50
84
  But of course, you can also use any custom font that you want, to give your App the unique look and feel that fits with the design.
51
85
 
52
- Adding is custom font to a Blits App is quite straightforward. First, you'll need to place a `.ttf` version of your font in the `public` folder (i.e. `public/fonts/comic-sans.ttf`).
86
+ Adding is custom font to a Blits App is quite straightforward. First, you'll need to place a `.ttf`, `.woff` or `.otf` version of your font in the `public` folder (i.e. `public/fonts/comic-sans.ttf`).
53
87
 
54
88
  Then you'll need to register the custom font in the Launch settings of your app (in `src/index.js`). The `fonts`-key in the settings is an `Array` that specifies all available fonts in your App.
55
89
 
@@ -73,3 +107,21 @@ From this moment on you'll be able to use the font `ComicSans` anywhere in your
73
107
  <Text font="ComicSans" content="I'm Comic Sans font!" />
74
108
  ```
75
109
 
110
+ ### Custom characters
111
+
112
+ For MSDF font, a font atlas is created. By default this atlas includes all printable main ASCII characters. If you know before hand that you won't need certain characters, it would be more optimal to generate only those characters that are actually needed.
113
+
114
+ Similarly, if you need characters outside of the default set, like accents or other special characters, then these will need to be included in the generated font atlas.
115
+
116
+ In order to control which characters are generated for a specific font, you can add a _font config file_ per font inside the `assets/fonts` folder. Its name should match the name of the font file, like so: `myfont.config.json`.
117
+
118
+ The config file should look something like this:
119
+
120
+ ```json
121
+ {
122
+ "charset": "0123456789éåaü"
123
+ }
124
+ ```
125
+ With the configuration above, only numbers and the specified letters with accents will be generated (i.e. the default character set is overwritten).
126
+
127
+ > Please note that only special characters and accents that are part of the original font can be added to the generated font atlas. Other characters will show up as a `?`.
@@ -104,7 +104,7 @@ Besides a reference to the `value`, you can also use dynamic values for the othe
104
104
 
105
105
  ## Listening to transition events
106
106
 
107
- Sometimes you may want to perform an action when a transition ends or when it starts.
107
+ Sometimes you may want to perform an action when a transition _ends_ or when it _starts_.
108
108
 
109
109
  You can easily hook into these transition events by adding a `start` and `end` key to the transition object. Both values should be a function (or a reference to a `method` on your component).
110
110
 
@@ -128,3 +128,23 @@ export default Blits.Component('Gold', {
128
128
  }
129
129
  ```
130
130
 
131
+ It is also possible to keep track of the entire progress of a transition. Every frametick during a transition (ideally once every 1.6ms), the renderer reports the progress of the transition. You can hook into this event by specifying a `progress` key on the transition configuration object, with a function to excute.
132
+
133
+ This function is executed _every_ frametick, and receives the current progress and the previous progress as its arguments. The progress is indicated as a value between `0` and `1`, where 0 means start and 1 means finished.
134
+
135
+ ```js
136
+ export default Blits.Component('Gold', {
137
+ template: `
138
+ <Element color="gold" w="100" h="100"
139
+ :x.transition="{value: $x, progress: $transitionProgress}"
140
+ />
141
+ `,
142
+ ///
143
+ methods: {
144
+ transitionprogress(progress, previousProgress) {
145
+ if(progress >= 0.5 && previousProgress < 0.5) {
146
+ // halfway through the transition
147
+ }
148
+ },
149
+ }
150
+ ```