Write phase 3 articles#8
Conversation
…e 4 and Phase 5 articles
| title: Alternative Frameworks | ||
| description: Learn about alternative frameworks that you can use to build your Gameface projects. | ||
| sidebar: |
There was a problem hiding this comment.
| title: Alternative Frameworks | |
| description: Learn about alternative frameworks that you can use to build your Gameface projects. | |
| sidebar: | |
| title: Alternative Frameworks | |
| draft: true | |
| description: Learn about alternative frameworks that you can use to build your Gameface projects. | |
| sidebar: |
|
|
||
| Gameface's internal layout engine is highly optimized and incredibly fast. However, the environment it runs in is extremely demanding. If a game targets 60 frames per second, the entire game engine has exactly <Highlight>16.6 milliseconds</Highlight> to render a single frame. The UI is usually allocated only a tiny fraction of that time (often 1-2ms). | ||
|
|
||
| In a standard web browser, a 15ms layout recalculation goes completely unnoticed. In a game engine, it blows your entire frame budget. To ensure your UI runs at peak performance and leaves plenty of CPU room for the game itself, we need to architect our layouts following a few core rules. |
There was a problem hiding this comment.
Maybe? :D Using architect is fine but for me is kind of weird when reading the text. You can also use build, develop or other word.
| In a standard web browser, a 15ms layout recalculation goes completely unnoticed. In a game engine, it blows your entire frame budget. To ensure your UI runs at peak performance and leaves plenty of CPU room for the game itself, we need to architect our layouts following a few core rules. | |
| In a standard web browser, a 15ms layout recalculation goes completely unnoticed. In a game engine, it blows your entire frame budget. To ensure your UI runs at peak performance and leaves plenty of CPU room for the game itself, we need to design our layouts following a few core rules. |
|
|
||
| ## High-Performance Layout Rules | ||
|
|
||
| Before we look at the screen structure, here are the practical "Do's and Don'ts" for styling your elements in Gameface. |
There was a problem hiding this comment.
| Before we look at the screen structure, here are the practical "Do's and Don'ts" for styling your elements in Gameface. | |
| Before we look at the screen structure, here are the practical "Good" and "Bad" practices for styling your elements in Gameface. |
|
|
||
| Before we look at the screen structure, here are the practical "Do's and Don'ts" for styling your elements in Gameface. | ||
|
|
||
| ### Define explicit dimensions |
There was a problem hiding this comment.
For the next headings you can add badges for "Good" and "Bad" or add X and checkmark emojis so the reader knows which is bad and which is good before starting to read the section.
For example:
| ### Define explicit dimensions | |
| ### [Good badge/checkmark icon] Define explicit dimensions |
or
| ### Define explicit dimensions | |
| ### Define explicit dimensions [Good badge/checkmark icon] |
|
|
||
| Try to use `align-items: center` or `flex-start` and rely on explicit dimensions instead. | ||
|
|
||
| :::danger[Default property] |
There was a problem hiding this comment.
IMO this should be marked as caution and not danger
|
|
||
| This algorithm can only be used inside `<p>` elements and is enabled by adding the special `cohinline` attribute. | ||
|
|
||
| Here is how you use `cohinline` to resolve the issuue mentioned above: |
There was a problem hiding this comment.
| Here is how you use `cohinline` to resolve the issuue mentioned above: | |
| Here is how you use `cohinline` to resolve the issue mentioned above: |
|
|
||
| However, `cohinline` handles vertical space differently than a web browser, which often leads to misaligned icons if you aren't expecting it. | ||
|
|
||
| ### The Problem: Ignored Image Heights |
There was a problem hiding this comment.
| ### The Problem: Ignored Image Heights | |
| ### Image heights are ignored |
|
|
||
|  | ||
|
|
||
| ### The Solution: Explicit Line Heights |
There was a problem hiding this comment.
| ### The Solution: Explicit Line Heights | |
| ### Setting explicit line heights to fit the image |
There was a problem hiding this comment.
I am suggesting these changes because personally I don't like the The problem and The solution texts :D
| **Actionable Rule:** Always explicitly define a base `font-size` on the element that is as close to the expected final rendering size as possible. This minimizes the iterations required by the engine's calculation loop. | ||
|
|
||
| ```css title="optimized-fit.css" ins="font-size: 24px;" | ||
| .button-text { | ||
| coh-font-fit-mode: shrink; | ||
| coh-font-fit-min-size: 14px; | ||
|
|
||
| /* Providing a starting point near the expected final size minimizes calculation overhead */ | ||
| font-size: 24px; | ||
| } | ||
| ``` |
|
|
||
| ## The Asset Format Problem | ||
|
|
||
| In a browser prototype, it is common to pick an image format based mainly on visual quality and file size. In a gameface UI, that decision also affects how much work the UI layer performs during layout, rendering, and invalidation. |
There was a problem hiding this comment.
I am confused about the In a gameface UI what exactly means? Is it the Gameface UI or not? :D
Maybe just In Gameface is enough?
|
|
||
| ### Practical Format Rules | ||
|
|
||
| For most Gameface UI work, the format decision can be made with a few direct rules: |
There was a problem hiding this comment.
| For most Gameface UI work, the format decision can be made with a few direct rules: | |
| Making a decision which format fits the best for your UI in Gameface you can follow these rules: |
There was a problem hiding this comment.
Or something else but different from the original text because it does not make sense written in that way.
| * Use **JPEG** only when the asset does not need transparency and compression artifacts are acceptable, such as some large background images (although the use case is very rare). | ||
|
|
||
| :::caution[SVG Usage Gotcha] | ||
| Avoid converting complex painted art into SVG only to make it scalable. If the SVG contains many paths, the visual flexibility may not justify the rendering cost |
There was a problem hiding this comment.
| Avoid converting complex painted art into SVG only to make it scalable. If the SVG contains many paths, the visual flexibility may not justify the rendering cost | |
| Avoid converting complex painted art into SVG only to make it scalable. If the SVG contains many paths, the visual flexibility may not justify the rendering cost. |
|
|
||
| #### `<img>` element | ||
|
|
||
| Use when the SVG is meaningful to the content or needs to participate in layout like an image. For example, as a button with an Xbox A glyph icon. |
There was a problem hiding this comment.
Use when the SVG is meaningful to the content - what does this mean? :D
|
|
||
| #### CSS `background-image` | ||
|
|
||
| Use when the SVG is purely decorative and part of the component's styles. For example, a panel frame with a border. |
There was a problem hiding this comment.
Maybe we can simplify both sections here for the external SVGs. Instead of explaining the differences between img and background-image, we can just list both as valid approaches. The only strict rule we need to highlight is that external SVGs are for graphics that won't be manipulated at runtime, regardless of how they are used.
|
|
||
| Changing `viewBox` on a complex SVG can still trigger redraw work. This is usually appropriate for controlled interactions, such as opening a map | ||
| screen or dragging a minimap, but you should avoid unnecessary **per-frame** updates on very large SVG maps. If the SVG contains many moving paths, | ||
| labels, and decorative layers, <Highlight>profile the interaction in the target UI</Highlight>. |
There was a problem hiding this comment.
Maybe? Or something similar? profile the interaction in the target UI is kind of weird for me :D
| labels, and decorative layers, <Highlight>profile the interaction in the target UI</Highlight>. | |
| labels, and decorative layers, <Highlight>make sure to profile the performance of the UI</Highlight>. |
| rules (`opacity: 1; transform: translateY(0)`). Because a `transition` is declared on both properties, the engine | ||
|
|
||
| <Highlight>interpolates between them</Highlight>, producing a smooth fade and slide with no JavaScript animation code. |
There was a problem hiding this comment.
| rules (`opacity: 1; transform: translateY(0)`). Because a `transition` is declared on both properties, the engine | |
| <Highlight>interpolates between them</Highlight>, producing a smooth fade and slide with no JavaScript animation code. | |
| rules (`opacity: 1; transform: translateY(0)`). Because a `transition` is declared on both properties, the engine <Highlight>interpolates between them</Highlight>, producing a smooth fade and slide with no JavaScript animation code. |
| :::caution[Other Limitations] | ||
|
|
||
| - `@starting-style` does not work with out-of-line SVGs. | ||
| - Custom expressions are not supported inside `@starting-style` rules. ::: |
There was a problem hiding this comment.
| :::caution[Other Limitations] | |
| - `@starting-style` does not work with out-of-line SVGs. | |
| - Custom expressions are not supported inside `@starting-style` rules. ::: | |
| :::caution[Other Limitations] | |
| - `@starting-style` does not work with out-of-line SVGs. | |
| - Custom expressions are not supported inside `@starting-style` rules. | |
| ::: |
| - `@starting-style` does not work with out-of-line SVGs. | ||
| - Custom expressions are not supported inside `@starting-style` rules. ::: | ||
|
|
||
| ## Controlling Animations with JavaScript |
There was a problem hiding this comment.
I am no sure if this is the place but maybe it is good to add a short example/topic of controlling something with transtionend and transitionstart because they are not documented but are useful in some scenarios
| Not all CSS properties work on SVG child elements the way they do on HTML elements. Properties like `filter` (e.g., `drop-shadow`) and `box-shadow` | ||
|
|
||
| <Highlight>will not produce any visible effect</Highlight> when applied directly to a `<path>`, `<rect>`, or other SVG shape. The declaration is |
There was a problem hiding this comment.
| Not all CSS properties work on SVG child elements the way they do on HTML elements. Properties like `filter` (e.g., `drop-shadow`) and `box-shadow` | |
| <Highlight>will not produce any visible effect</Highlight> when applied directly to a `<path>`, `<rect>`, or other SVG shape. The declaration is | |
| Not all CSS properties work on SVG child elements the way they do on HTML elements. Properties like `filter` (e.g., `drop-shadow`) and `box-shadow` <Highlight>will not produce any visible effect</Highlight> when applied directly to a `<path>`, `<rect>`, or other SVG shape. The declaration is |
| The `mask-image` variant flips the relationship between shape and color. Instead of the sprite sheet carrying the finished visual, it carries only | ||
|
|
||
| <Highlight>silhouette frames</Highlight> that define which pixels are visible. The actual color comes from `background-color` on the same element. |
There was a problem hiding this comment.
| The `mask-image` variant flips the relationship between shape and color. Instead of the sprite sheet carrying the finished visual, it carries only | |
| <Highlight>silhouette frames</Highlight> that define which pixels are visible. The actual color comes from `background-color` on the same element. | |
| The `mask-image` variant flips the relationship between shape and color. Instead of the sprite sheet carrying the finished visual, it carries only <Highlight>silhouette frames</Highlight> that define which pixels are visible. The actual color comes from `background-color` on the same element. |
No description provided.