Unity Scopes API
|
A category renderer template in JSON format. More...
#include <unity/scopes/CategoryRenderer.h>
Public Member Functions | |
CategoryRenderer (std::string const &json_text=DEFAULT_RENDERER) | |
Creates a CategoryRenderer from a JSON string. More... | |
std::string | data () const |
Returns complete renderer template definition in JSON format. More... | |
Copy and assignment | |
Copy and assignment operators (move and non-move versions) have the usual value semantics. | |
CategoryRenderer (CategoryRenderer const &) | |
CategoryRenderer & | operator= (CategoryRenderer const &) |
CategoryRenderer (CategoryRenderer &&) | |
CategoryRenderer & | operator= (CategoryRenderer &&) |
virtual | ~CategoryRenderer () |
Static Public Member Functions | |
static CategoryRenderer | from_file (std::string const &path) |
Creates a CategoryRenderer from a text file. More... | |
A category renderer template in JSON format.
This class specifies how is a particular category rendered by Unity. Note that the data is likely to change between major versions of Unity, and therefore the definition isn't strongly typed and provided by a scope author as a JSON string.
A Category contains all the information needed by Unity to render results provided by a scope author (by handling unity::scopes::SearchQueryBase::run()) in a way that gives the user as much useful information as possible. When pushing results to the query originator (unity::scopes::SearchReply::push()), each result needs to have a category associated, and this association determines what will the result look like.
The most important part of a category definition is the unity::scopes::CategoryRenderer instance. If you use the default constructor CategoryRenderer(), the renderer will use the following definition:
{ "schema-version" : 1, "template" : { "category-layout" : "grid" }, "components" : { "title" : "title", "art" : "art" } }
As specified by the "category-layout"
key of the "template"
dictionary, Unity will render results associated with this category in a grid layout. The "components"
dictionary specifies which result fields are used by Unity. In case of this definition, each tile of the grid will map the "title" field from the result (set also by the call to unity::scopes::Result::set_title()) as title for the grid tile, and "art" field from the result (see unity::scopes::Result::set_art()) as the icon for the grid tile.
To sum up, the "template"
dictionary contains information to determine the correct renderer and its parameters, and the "components"
dictionary contains mapping specifying which fields of the results are used by the renderer, where keys of the dictionary are understood by Unity and values specify either field name of the results directly ({"title": "album_name"}
would mean that Unity will use result["album_name"]
as a title for the grid tile), or the value can specify extra hints for the renderer as well as the result field name ({"art": {"field": "icon", "aspect-ratio": 1.3}}
).
When using {"schema-version": 1}
, the following keys are understood:
category-layout
Specifies renderer type; possible values: "grid"
(default), "carousel"
, "organic-grid"
, "journal"
, "vertical-journal"
card-layout
Specifies layout of the individual result cards; possible values: "vertical"
(default), "horizontal"
card-size
Size of the result cards; possible values: "small"
, "medium"
(default), "large"
; when using "category-layout": "vertical-journal"
any integer between 12 and 38 overlay
Overlay text data on top of the art; boolean, default false collapsed-rows
Number of result rows displayed while the category is collapsed; possible values: 1 or 2 (only affects grid and journal) card-background
Background color for the cards; string; URI in the formatcolor:///#rrggbbor
color:///color_nameor
gradient:///#rrggbb/#rrggbbor an image URI (will be stretched)
title
Card title, string art
Card art (primary graphics), uri; can contain subkeys: "aspect-ratio"
(double specifying the aspect ratio of the graphics, default: 1.0) and "fill-mode"
("crop"
(default), or "fit"
) subtitle
Subtitle of a card, string mascot
Mascot (secondary graphics), uri emblem
Emblem, uri summary
Text summary, string background
Card background, can override the default specified in the card-background field of the template section, string (same URI format as for card-background) attribute-1
string attribute-2
string attribute-3
stringIn the following example a category named "Recommended" containing three components is created (title, art and subtitle), and a result providing values for these components is pushed.
Note that the scope is free to set any other extra result fields even if they are not used by the renderer (and therefore not specified in the "components"
dictionary), such fields will be preserved and available to the scope when handling result-specific methods (for example unity::scopes::ScopeBase::preview()).
|
explicit |
Creates a CategoryRenderer from a JSON string.
json_text | Renderer template in JSON format |
unity::InvalidArgumentException | if json_text cannot be parsed |
std::string unity::scopes::CategoryRenderer::data | ( | ) | const |
Returns complete renderer template definition in JSON format.
|
static |
Creates a CategoryRenderer from a text file.