Clarified text.Imager's bound behavior

This commit clarifies text.Imager's (and therefore text.Avatarer's as
well) bound behaviors. Prior to this commit, it is unclear which end
bound an implementation should return. This commit clarifies that in
order for the image to be inlined, the start must overlap the end
bounds.

This clarification was needed in order to differentiate images to be
inlined with images to be associated with other contexts, such as
Mentioned. The inline check would therefore be very simple:

    if start == end {
        if imager := segment.AsImager(); imager != nil {
            log.Println("Segment has an inline image.")
        }
    }

Note that since there's now a way to explicitly define whether an image
is inlined or not, for implementations that can't display images, the
ImageText() should only be used if the image is actually inlined.
Therefore, the same check also applies to ImageText(). This also applies
to AvatarText().
This commit is contained in:
diamondburned 2020-10-13 17:26:46 -07:00
parent 76f5201a6f
commit 1dd36e0034
2 changed files with 27 additions and 9 deletions

View File

@ -131,11 +131,21 @@ var Main = Packages{
}, {
Comment: Comment{`
Imager implies the segment should be replaced with a (possibly
inlined) image. Unless the Imager segment covers something
meaningful, only the starting bound should matter, as images
must not substitute texts and only complement them. An example
of this would be having Imager cover the entire chunk that
Mentioner does.
inlined) image.
The Imager segment must return a bound of length zero, that is,
the start and end bounds must be the same, unless the Imager
segment covers something meaningful, as images must not
substitute texts and only complement them.
An example of the start and end bounds being the same would be
any inline image, and an Imager that belongs to a Mentioner
segment should have its bounds overlap. Normally,
implementations with separated Mentioner and Imager
implementations don't have to bother about this, since with
Mentioner, the same Bounds will be shared, and with Imager, the
Bounds method can easily return the same variable for start and
end.
For segments that also implement mentioner, the image should be
treated as a square avatar.

View File

@ -93,10 +93,18 @@ type Colorer interface {
}
// Imager implies the segment should be replaced with a (possibly inlined)
// image. Unless the Imager segment covers something meaningful, only the
// starting bound should matter, as images must not substitute texts and only
// complement them. An example of this would be having Imager cover the entire
// chunk that Mentioner does.
// image.
//
// The Imager segment must return a bound of length zero, that is, the start and
// end bounds must be the same, unless the Imager segment covers something
// meaningful, as images must not substitute texts and only complement them.
//
// An example of the start and end bounds being the same would be any inline
// image, and an Imager that belongs to a Mentioner segment should have its
// bounds overlap. Normally, implementations with separated Mentioner and Imager
// implementations don't have to bother about this, since with Mentioner, the
// same Bounds will be shared, and with Imager, the Bounds method can easily
// return the same variable for start and end.
//
// For segments that also implement mentioner, the image should be treated as a
// square avatar.