imj-base-0.1.0.2: Game engine with geometry, easing, animated text, delta rendering.

Safe HaskellNone
LanguageHaskell2010

Imj.Graphics.Text.Alignment

Contents

Description

This module exports functions and types to handle text alignemnt.

Synopsis

Alignment

data AlignmentKind Source #

Specifies where the Text is w.r.t the reference coordinates.

Constructors

Centered

Centered on reference coordinates, favoring the RIGHT side in case of ambiguity:

  1
  12
 123
 1234
  ^
RightAligned

Left of the reference coordinates, including it:

   1
  12
 123
1234
   ^
LeftAligned

Right of the reference coordinates, including it:

1
12
123
1234
^

data Alignment Source #

Constructors

Alignment 

Fields

mkRightAlign Source #

Arguments

:: Coords Pos

The text will be written left of these coordinates.

-> Alignment 

mkCentered Source #

Arguments

:: Coords Pos

The text will be centered on these coordinates.

-> Alignment 

Helpers

toNextLine :: Alignment -> Alignment Source #

Moves the reference coordinate one line down.

Utilities

align Source #

Arguments

:: AlignmentKind 
-> Int

Count of characters

-> (Int, Direction) 

Given a number of characters and an alignment, returns the displacement that should be done relatively to the reference coordinates in order to find the first character Coords.

For Centered, when we have an even count of characters to draw, we (somewhat arbitrarily) chose to favor the RIGHT Direction, as illustrated here where ^ indicates where the reference Coords is:

   1
   12
  123
  1234
   ^

Note that this choice impacts the implementation of getSideCentersAtDistance.

align' Source #

Arguments

:: Alignment 
-> Int

number of characters to draw

-> Coords Pos 

Computes starting coordinates where from we should draw a series of characters of a given length, to meet the alignment constraint.