Package text to use asserters; colors now RGBA
This commit regenerates package text to use asserters instead of manually asserting structs. This is to both bring consistency to the interfaces and prepare it for the incoming IPC additions. This commit also changed the Colorer interface to require returning a 32-bit RGBA color. Before, backends could return 24-bit RGB OR 32-bit RGBA, but there wasn't a good way to distinguish between the two. Now, backends must set the alpha bits to 0xFF if it's 24-bit only.
This commit is contained in:
parent
25980eb794
commit
9a64b50703
|
@ -8,6 +8,13 @@ var Main = Packages{
|
|||
MakePath("text"): {
|
||||
Comment: Comment{`
|
||||
Package text provides a rich text API for cchat interfaces to use.
|
||||
|
||||
Asserting
|
||||
|
||||
Although interfaces here contain asserter methods similarly to
|
||||
cchat, the backend should take care to not implement multiple
|
||||
interfaces that may seem conflicting. For example, if Avatarer is
|
||||
already implemented, then Imager shouldn't be.
|
||||
`},
|
||||
Enums: []Enumeration{{
|
||||
Comment: Comment{`
|
||||
|
@ -86,6 +93,14 @@ var Main = Packages{
|
|||
{Name: "end", Type: "int"},
|
||||
},
|
||||
},
|
||||
AsserterMethod{ChildType: "Colorer"},
|
||||
AsserterMethod{ChildType: "Linker"},
|
||||
AsserterMethod{ChildType: "Imager"},
|
||||
AsserterMethod{ChildType: "Avatarer"},
|
||||
AsserterMethod{ChildType: "Mentioner"},
|
||||
AsserterMethod{ChildType: "Attributor"},
|
||||
AsserterMethod{ChildType: "Codeblocker"},
|
||||
AsserterMethod{ChildType: "Quoteblocker"},
|
||||
},
|
||||
}, {
|
||||
Comment: Comment{`
|
||||
|
@ -94,8 +109,7 @@ var Main = Packages{
|
|||
hyperlink, similarly to the anchor tag with href being the URL
|
||||
and the inner text being the text string.
|
||||
`},
|
||||
Name: "Linker",
|
||||
Embeds: []EmbeddedInterface{{InterfaceName: "Segment"}},
|
||||
Name: "Linker",
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{Name: "Link"},
|
||||
|
@ -107,9 +121,11 @@ var Main = Packages{
|
|||
Imager implies the segment should be replaced with a (possibly
|
||||
inlined) image. Only the starting bound matters, as images
|
||||
cannot substitute texts.
|
||||
|
||||
For segments that also implement mentioner, the image should be
|
||||
treated as a square avatar.
|
||||
`},
|
||||
Name: "Imager",
|
||||
Embeds: []EmbeddedInterface{{InterfaceName: "Segment"}},
|
||||
Name: "Imager",
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{
|
||||
|
@ -150,9 +166,11 @@ var Main = Packages{
|
|||
Comment: Comment{`
|
||||
Avatarer implies the segment should be replaced with a
|
||||
rounded-corners image. This works similarly to Imager.
|
||||
|
||||
For segments that also implement mentioner, the image should be
|
||||
treated as a round avatar.
|
||||
`},
|
||||
Name: "Avatarer",
|
||||
Embeds: []EmbeddedInterface{{InterfaceName: "Segment"}},
|
||||
Name: "Avatarer",
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{
|
||||
|
@ -186,6 +204,28 @@ var Main = Packages{
|
|||
Returns: []NamedType{{Type: "string"}},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Comment: Comment{`
|
||||
Colorer is a text color format that a segment could implement.
|
||||
This is to be applied directly onto the text.
|
||||
|
||||
The Color method must return a valid 32-bit RGBA color. That
|
||||
is, if the text color is solid, then the alpha value must be
|
||||
0xFF. Frontends that support 32-bit colors must render alpha
|
||||
accordingly without any edge cases.
|
||||
`},
|
||||
Name: "Colorer",
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{
|
||||
Comment: Comment{`
|
||||
Color returns a 32-bit RGBA color.
|
||||
`},
|
||||
Name: "Color",
|
||||
},
|
||||
Returns: []NamedType{{Type: "uint32"}},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Comment: Comment{`
|
||||
Mentioner implies that the segment can be clickable, and when
|
||||
|
@ -197,8 +237,7 @@ var Main = Packages{
|
|||
that user. This would allow frontends to flexibly layout the
|
||||
labels.
|
||||
`},
|
||||
Name: "Mentioner",
|
||||
Embeds: []EmbeddedInterface{{InterfaceName: "Segment"}},
|
||||
Name: "Mentioner",
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{
|
||||
|
@ -214,71 +253,12 @@ var Main = Packages{
|
|||
}},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Comment: Comment{`
|
||||
MentionerImage extends Mentioner to give the mentioned object an
|
||||
image. This interface allows the frontend to be more flexible
|
||||
in layouting. A Mentioner can only implement EITHER
|
||||
MentionedImage or MentionedAvatar.
|
||||
`},
|
||||
Name: "MentionerImage",
|
||||
Embeds: []EmbeddedInterface{{InterfaceName: "Mentioner"}},
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{
|
||||
Comment: Comment{`
|
||||
Image returns the mentioned object's image URL.
|
||||
`},
|
||||
Name: "Image",
|
||||
},
|
||||
Returns: []NamedType{{Name: "url", Type: "string"}},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Comment: Comment{`
|
||||
MentionerAvatar extends Mentioner to give the mentioned object
|
||||
an avatar. This interface allows the frontend to be more
|
||||
flexible in layouting. A Mentioner can only implement EITHER
|
||||
MentionedImage or MentionedAvatar.
|
||||
`},
|
||||
Name: "MentionerAvatar",
|
||||
Embeds: []EmbeddedInterface{{InterfaceName: "Mentioner"}},
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{
|
||||
Comment: Comment{`
|
||||
Avatar returns the mentioned object's avatar URL.
|
||||
`},
|
||||
Name: "Avatar",
|
||||
},
|
||||
Returns: []NamedType{{Name: "url", Type: "string"}},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Comment: Comment{`
|
||||
Colorer is a text color format that a segment could implement.
|
||||
This is to be applied directly onto the text.
|
||||
`},
|
||||
Name: "Colorer",
|
||||
Embeds: []EmbeddedInterface{{InterfaceName: "Mentioner"}},
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{
|
||||
Comment: Comment{`
|
||||
Color returns a 24-bit RGB or 32-bit RGBA color.
|
||||
`},
|
||||
Name: "Color",
|
||||
},
|
||||
Returns: []NamedType{{Type: "uint32"}},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Comment: Comment{`
|
||||
Attributor is a rich text markup format that a segment could
|
||||
implement. This is to be applied directly onto the text.
|
||||
`},
|
||||
Name: "Attributor",
|
||||
Embeds: []EmbeddedInterface{{InterfaceName: "Mentioner"}},
|
||||
Name: "Attributor",
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{Name: "Attribute"},
|
||||
|
@ -293,8 +273,7 @@ var Main = Packages{
|
|||
|
||||
This interface is equivalent to Markdown's codeblock syntax.
|
||||
`},
|
||||
Name: "Codeblocker",
|
||||
Embeds: []EmbeddedInterface{{InterfaceName: "Segment"}},
|
||||
Name: "Codeblocker",
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{Name: "CodeblockLanguage"},
|
||||
|
@ -311,8 +290,7 @@ var Main = Packages{
|
|||
typically by an actaul quoteblock or with green arrows prepended
|
||||
to each line.
|
||||
`},
|
||||
Name: "Quoteblocker",
|
||||
Embeds: []EmbeddedInterface{{InterfaceName: "Segment"}},
|
||||
Name: "Quoteblocker",
|
||||
Methods: []Method{
|
||||
GetterMethod{
|
||||
method: method{
|
||||
|
|
67
text/text.go
67
text/text.go
|
@ -1,6 +1,14 @@
|
|||
// DO NOT EDIT: THIS FILE IS GENERATED!
|
||||
|
||||
// Package text provides a rich text API for cchat interfaces to use.
|
||||
//
|
||||
//
|
||||
// Asserting
|
||||
//
|
||||
// Although interfaces here contain asserter methods similarly to cchat, the
|
||||
// backend should take care to not implement multiple interfaces that may seem
|
||||
// conflicting. For example, if Avatarer is already implemented, then Imager
|
||||
// shouldn't be.
|
||||
package text
|
||||
|
||||
// Attribute is the type for basic rich text markup attributes.
|
||||
|
@ -40,16 +48,15 @@ type Rich struct {
|
|||
// Attributor is a rich text markup format that a segment could implement. This
|
||||
// is to be applied directly onto the text.
|
||||
type Attributor interface {
|
||||
Mentioner
|
||||
|
||||
Attribute() Attribute
|
||||
}
|
||||
|
||||
// Avatarer implies the segment should be replaced with a rounded-corners image.
|
||||
// This works similarly to Imager.
|
||||
//
|
||||
// For segments that also implement mentioner, the image should be treated as a
|
||||
// round avatar.
|
||||
type Avatarer interface {
|
||||
Segment
|
||||
|
||||
// AvatarText returns the underlying text of the image. Frontends could use this
|
||||
// for hovering or displaying the text instead of the image.
|
||||
AvatarText() string
|
||||
|
@ -66,25 +73,26 @@ type Avatarer interface {
|
|||
//
|
||||
// This interface is equivalent to Markdown's codeblock syntax.
|
||||
type Codeblocker interface {
|
||||
Segment
|
||||
|
||||
CodeblockLanguage() (language string)
|
||||
}
|
||||
|
||||
// Colorer is a text color format that a segment could implement. This is to be
|
||||
// applied directly onto the text.
|
||||
//
|
||||
// The Color method must return a valid 32-bit RGBA color. That is, if the text
|
||||
// color is solid, then the alpha value must be 0xFF. Frontends that support
|
||||
// 32-bit colors must render alpha accordingly without any edge cases.
|
||||
type Colorer interface {
|
||||
Mentioner
|
||||
|
||||
// Color returns a 24-bit RGB or 32-bit RGBA color.
|
||||
// Color returns a 32-bit RGBA color.
|
||||
Color() uint32
|
||||
}
|
||||
|
||||
// Imager implies the segment should be replaced with a (possibly inlined)
|
||||
// image. Only the starting bound matters, as images cannot substitute texts.
|
||||
//
|
||||
// For segments that also implement mentioner, the image should be treated as a
|
||||
// square avatar.
|
||||
type Imager interface {
|
||||
Segment
|
||||
|
||||
// ImageText returns the underlying text of the image. Frontends could use this
|
||||
// for hovering or displaying the text instead of the image.
|
||||
ImageText() string
|
||||
|
@ -99,8 +107,6 @@ type Imager interface {
|
|||
// that the segment should be replaced with a hyperlink, similarly to the anchor
|
||||
// tag with href being the URL and the inner text being the text string.
|
||||
type Linker interface {
|
||||
Segment
|
||||
|
||||
Link() (url string)
|
||||
}
|
||||
|
||||
|
@ -111,39 +117,15 @@ type Linker interface {
|
|||
// Mentioner highlighted to be the display name of that user. This would allow
|
||||
// frontends to flexibly layout the labels.
|
||||
type Mentioner interface {
|
||||
Segment
|
||||
|
||||
// MentionInfo returns the popup information of the mentioned segment. This is
|
||||
// typically user information or something similar to that context.
|
||||
MentionInfo() Rich
|
||||
}
|
||||
|
||||
// MentionerAvatar extends Mentioner to give the mentioned object an avatar.
|
||||
// This interface allows the frontend to be more flexible in layouting. A
|
||||
// Mentioner can only implement EITHER MentionedImage or MentionedAvatar.
|
||||
type MentionerAvatar interface {
|
||||
Mentioner
|
||||
|
||||
// Avatar returns the mentioned object's avatar URL.
|
||||
Avatar() (url string)
|
||||
}
|
||||
|
||||
// MentionerImage extends Mentioner to give the mentioned object an image. This
|
||||
// interface allows the frontend to be more flexible in layouting. A Mentioner
|
||||
// can only implement EITHER MentionedImage or MentionedAvatar.
|
||||
type MentionerImage interface {
|
||||
Mentioner
|
||||
|
||||
// Image returns the mentioned object's image URL.
|
||||
Image() (url string)
|
||||
}
|
||||
|
||||
// Quoteblocker represents a quoteblock that behaves similarly to the blockquote
|
||||
// HTML tag. The quoteblock may be represented typically by an actaul quoteblock
|
||||
// or with green arrows prepended to each line.
|
||||
type Quoteblocker interface {
|
||||
Segment
|
||||
|
||||
// QuotePrefix returns the prefix that every line the segment covers have. This
|
||||
// is typically the greater-than sign ">" in Markdown. Frontends could use this
|
||||
// information to format the quote properly.
|
||||
|
@ -159,4 +141,15 @@ type Quoteblocker interface {
|
|||
// Mentioner may also implement Colorer.
|
||||
type Segment interface {
|
||||
Bounds() (start int, end int)
|
||||
|
||||
// Asserters.
|
||||
|
||||
AsColorer() Colorer // Optional
|
||||
AsLinker() Linker // Optional
|
||||
AsImager() Imager // Optional
|
||||
AsAvatarer() Avatarer // Optional
|
||||
AsMentioner() Mentioner // Optional
|
||||
AsAttributor() Attributor // Optional
|
||||
AsCodeblocker() Codeblocker // Optional
|
||||
AsQuoteblocker() Quoteblocker // Optional
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue