From 1dd36e00347cf0b0411fd653eaee1fb34f6f4198 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Tue, 13 Oct 2020 17:26:46 -0700 Subject: [PATCH] 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(). --- repository/main.go | 20 +++++++++++++++----- text/text.go | 16 ++++++++++++---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/repository/main.go b/repository/main.go index 591b384..4ebe050 100644 --- a/repository/main.go +++ b/repository/main.go @@ -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. diff --git a/text/text.go b/text/text.go index c58f376..213d373 100644 --- a/text/text.go +++ b/text/text.go @@ -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.