Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added TextFormatter classes #1720

Merged
merged 36 commits into from
Jun 27, 2022
Merged

Conversation

st-pasha
Copy link
Contributor

Description

  • A TextFormatter is a class that can take a string of text and convert it into a TextElement.
  • A TextElement is an object that encapsulates a text string prepared for rendering. This object knows its own dimensions (layout), and is able to render itself on a canvas.

A TextFormatter is different from the current TextRenderer in one crucial respect: whereas TextRenderer takes a string of text and draws it onto the canvas directly (performing the layout and measurement internally), the TextFormatter creates an object that encapsulates the information necessary for rendering.

Thus, TextFormatter's output can be used to prepare the text once, and then render multiple times. In addition, since each TextElement knows its own layout, -- these individual layouts can be collected, manipulated, and arranged into a larger text body necessary for rich text rendering.

In addition, this PR:

  • Implements a debug version of the standard text renderer, which draws rectangles instead of text;
  • Re-enables the skipped golden test for the TextBoxComponent (hopefully it'll work this time);
  • Refactors existing TextRenderers to use the new TextFormatters under the hood.

This PR is a WIP for the Rich Text functionality (#1627).

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • [-] I have updated/added relevant examples in examples.

Breaking Change

  • [-] Yes, this is a breaking change.
  • No, this is not a breaking change.

Related Issues

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just docs and an example missing otherwise it looks good!

@spydon spydon requested a review from a team June 11, 2022 09:21
@st-pasha
Copy link
Contributor Author

Re-enables the skipped golden test for the TextBoxComponent (hopefully it'll work this time);

It actually did work this time!

st-pasha and others added 9 commits June 18, 2022 13:40
The "basic" gesture detectors widget was creating a RawGestureDetector underneath, which resulted in two nested RawGestureDetectors, each with its own gesture arena.

This refactor combines the two gesture detectors into a single one.
Since Flutter 3.0.0 we can use Melos feature for modifying the pubspec_overrides.yaml files instead of hacking around with the pubspec.lock files.
…#1726)

- In Component, we will now avoid adoption queue when setting parent to the same as the current;
- The ButtonComponent avoids swapping button and buttonDown components if buttonDown is null;
Since our documentation is fairly complex, we need to have a document which describes how various parts of it work. This PR adds such documentation.
st-pasha and others added 6 commits June 18, 2022 13:40
…#1715)

Implement drag events that dispatch using the componentsAtPoint mechanism.
* chore(release): publish packages

 - [email protected]

* fix: flame_audio should not have upper Flutter bound
Pub gives a warning when using ^3.0.0 since that also implies less than 4.0.0, which your Flutter dependency shouldn't be.
With >= it is an open range instead.
)

This PR adds a getter to the FlameBlocListenable mixin. This getter will allow to use FlameBlocListenable as a standalone mixin to react to new states via onNewState(), access the current state, and also add events to the listenable Bloc via the bloc property.
Currently a workaround to give components this functionality is to use FlameBlocListenable and FlameBlocReader in parallel.
…ne#1736)

The return type of GameWidget docs should be Widget instead of void
@st-pasha
Copy link
Contributor Author

Just docs and an example missing otherwise it looks good!

My thinking was that first we develop the rich text functionality, over the course of several PRs, and only then add the proper documentation. Otherwise we'd likely have to rewrite the documentation when the rest of the pieces are developed.

@spydon spydon requested a review from a team June 19, 2022 18:31
/// Helper class that stores dimensions of a single glyph for a spritesheet-
/// based font.
class GlyphInfo {
double srcLeft = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some dart doc on each attribute? Some of them I can infer their meaning from the name, but not all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rst* attributes are used in the rstTransforms argument for the canvas.drawRawAtlas function.

We do need to have proper documentation for them, but I was thinking of leaving that for later, since we still need to merge GlyphData and GlyphInfo classes, plus there would be some reorganization of this class to support non-monospace fonts.

@spydon spydon enabled auto-merge (squash) June 27, 2022 18:00
@spydon spydon merged commit c44272b into flame-engine:main Jun 27, 2022
@st-pasha st-pasha deleted the ps/text-formatters branch June 27, 2022 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants