render

package
v0.0.0-...-4d984c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2015 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

The render package defines interfaces and functions to stylize a View's contents with colours, fonts and other metadata.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Colour

type Colour color.RGBA

Colour represented by a underlying color.RGBA structure

type ColourScheme

type ColourScheme interface {
	// Takes a ViewRegions pointer as input and uses the data contained in it
	// to determine the Flavour it should be rendered with.
	Spice(*ViewRegions) Flavour
}

type Flavour

type Flavour struct {
	Background Colour
	Foreground Colour
	Font       Font
	Flags      ViewRegionFlags
}

The Flavour struct contains the specific settings used to style a particular Region.

type Font

type Font struct {
	Name  string
	Size  float64
	Style FontStyle
}

type FontMeasurement

type FontMeasurement struct {
	Width, Height int
}

type FontMetrics

type FontMetrics interface {
	Measure(Font, []rune) FontMeasurement
}

type FontStyle

type FontStyle int
const (
	Italic FontStyle = (1 << iota)
	Bold
	Underline
)

type Recipe

type Recipe map[Flavour]text.RegionSet

The Recipe type groups text.RegionSets by their Flavour. The idea is to allow large groups of text be rendered as a single batch without any state changes inbetween the batches.

func Transform

func Transform(scheme ColourScheme, data ViewRegionMap, viewport text.Region) Recipe

Transform takes a ColourScheme, a ViewRegionMap and a viewport as input.

The viewport would be the text.Region of the current buffer that is visible to the user and any ViewRegions outside of this area are not forwarded for further processing.

The remaining ViewRegions are then passed on to the ColourScheme for determining the exact Flavour for which that RegionSet should be styled, adding Regions of the same Flavour to the same RegionSet.

Typically there are more ViewRegions available in a text buffer than there are unique Flavours in a ColourScheme, so this operation can be viewed as reducing the number of state changes required to display the text to the user.

The final output, the Recipe, contains a mapping of all unique Flavours and that Flavour's associated RegionSet.

func (Recipe) Transcribe

func (r Recipe) Transcribe() (ret TranscribedRecipe)

Transcribing the Recipe creates a linear step-by-step representation of it, which might or might not make it easier for Renderers to work with.

type RenderUnit

type RenderUnit struct {
	Flavour Flavour
	Region  text.Region
}

A RenderUnit is just a Flavour and an associated Region.

type Renderer

type Renderer interface {
	// Renders the given Recipe
	Render(Recipe)
}

type TranscribedRecipe

type TranscribedRecipe []RenderUnit

A TranscribedRecipe is a linear (in text.Regions) representation of a Recipe

func (*TranscribedRecipe) Len

func (r *TranscribedRecipe) Len() int

Just used to satisfy the sort.Interface interface, typically not used otherwise.

func (*TranscribedRecipe) Less

func (r *TranscribedRecipe) Less(i, j int) bool

Just used to satisfy the sort.Interface interface, typically not used otherwise.

func (*TranscribedRecipe) Swap

func (r *TranscribedRecipe) Swap(i, j int)

Just used to satisfy the sort.Interface interface, typically not used otherwise.

type ViewRegionFlags

type ViewRegionFlags int

Flags used to hint at how the region should be rendered.

const (
	DRAW_EMPTY              ViewRegionFlags = (1 << iota) // Draw a vertical line for an empty (zero area) region
	HIDE_ON_MINIMAP                                       // Don't draw this region in the minimap
	DRAW_EMPTY_AS_OVERWRITE                               // Rather than a vertical line, draw empty regions as a horizontal one
	DRAW_NO_FILL                                          // Don't draw the filling of the region
	DRAW_NO_OUTLINE                                       // Don't draw the outline of the region
	DRAW_SOLID_UNDERLINE                                  // Draw a solid underline under the whole region
	DRAW_STIPPLED_UNDERLINE                               // Draw a stippled underline under the whole region
	DRAW_SQUIGGLY_UNDERLINE                               // Draw a squiggly underline under the whole region
	PERSISTENT                                            // Region is saved with the session
	HIDDEN                                                // Region is not rendered
	SELECTION                                             // This Region is part of selected text
	HIGHLIGHT                                             // This Region is part of highlighted text
	DRAW_TEXT                                             // The actual text contained in the region should be rendered
	DEFAULT                 ViewRegionFlags = 0           // No flags at all, only draw the region itself and not the text
)

type ViewRegionMap

type ViewRegionMap map[string]ViewRegions

A set of ViewRegions associated by a string identifier key. The name of the key itself has no special meaning other than for being able set, retrieve and update *your* set of ViewRegions.

func (*ViewRegionMap) Cull

func (vrm *ViewRegionMap) Cull(viewport text.Region)

Calls Cull on each ViewRegions object contained in the map, removing all entries that are outside of the viewport.

type ViewRegions

type ViewRegions struct {
	// The Regions this ViewRegions object is relevant to.
	Regions text.RegionSet
	// The scope identifier is used to determine colour and other style options.
	Scope string
	// Gutter icon (displayed next to line numbers) URI.
	Icon string
	// Flags used to hint at how the region should be rendered.
	Flags ViewRegionFlags
}

The ViewRegions object contains information related to the rendering of a specific RegionSet and can be set both by a https://godoc.org/github.com/limetext/lime-backend/lib/parser#SyntaxHighlighter and from plugins via https://godoc.org/github.com/limetext/lime-backend/lib#View.AddRegions.

Turning this information into a concrete https://godoc.org/github.com/limetext/lime-backend/lib/render#Flavour is the job of the https://godoc.org/github.com/limetext/lime-backend/lib/render#ColourScheme interface.

func (*ViewRegions) Clone

func (vr *ViewRegions) Clone() *ViewRegions

Creates a copy of this ViewRegions object.

func (*ViewRegions) Cull

func (vr *ViewRegions) Cull(viewport text.Region)

Removes any regions that are outside of the given viewport, and clips the regions that are intersecting it so that all regions remaining are fully contained inside of the viewport.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL