WebTextStyle

Package: Libraries.Web.Styles · Inherits from: Libraries.Language.Object, Libraries.Web.Styles.WebStyle

WebTextStyle sets how an element's text looks: its size, the height of each line, whether it is bold or italic, its color, underlining, capitals, and how it lines up. Anything not set writes nothing, so the text keeps the site's starting look for it. Sizes are in pixels, as in Quorum's games.

Example Code

use Libraries.Web.Page.all
use Libraries.Web.Styles.WebTextStyle

class Main is WebPage
    action Main
        WebTextStyle title
        title:SetFontSize(30)
        title:SetLineHeight(36)
        title:SetBold(true)

        Section section
        Heading heading = section:AddHeading("Welcome", 1)
        SetStyle(heading, title)
        Add(section)
    end
end

Actions

AlignCenter()

Centers the text.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle style
style:AlignCenter()

AlignLeft()

Lines the text up on the left. Without an alignment, text lines up as the element it is in does by default.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle style
style:AlignLeft()

AlignRight()

Lines the text up on the right.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle style
style:AlignRight()

Copy()

Returns a new text style with the same settings. Change the copy to give one element its own look without changing every element that shares this style.

Returns

Libraries.Web.Styles.WebTextStyle: A copy of this style.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle heading
heading:SetFontSize(24)
WebTextStyle larger = heading:Copy()
larger:SetFontSize(30)

Generate()

Returns the stylesheet declarations for this text style. WebSite calls this when it writes the stylesheet; people making pages don't.

Returns

text: The declarations for this style.

GetColor()

Returns the color of the text, or undefined if it isn't set.

Returns

Libraries.Web.Styles.WebColor: The text's color, or undefined.

GetFontSize()

Returns the size of the text, in pixels, or -1 if it was never set.

Returns

number: The text size, or -1.

GetLineHeight()

Returns the height of each line, in pixels, or -1 if it was never set.

Returns

number: The line height, or -1.

IsBold()

Returns true if the text was set to be bold.

Returns

boolean: Whether the text is bold.

IsItalic()

Returns true if the text was set to be italic.

Returns

boolean: Whether the text is italic.

SetBold(boolean value)

Sets whether the text is bold.

Parameters

  • value boolean: True for bold text, false for normal text.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle style
style:SetBold(true)

SetBreakLongWords(boolean value)

Lets a word too long for its space break onto the next line, instead of reaching past the edge, as in a narrow table column.

Parameters

  • value boolean: True to break long words.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle cell
cell:SetBreakLongWords(true)

SetCapitalized(boolean value)

Shows the first letter of each word as a capital, as in a title, without changing the words themselves.

Parameters

  • value boolean: True for capitals.

SetColor(Libraries.Web.Styles.WebColor value)

Sets the color of the text.

Parameters

Example

use Libraries.Web.Styles.WebTextStyle
use Libraries.Web.Styles.WebColor

WebColor white
white:SetColor(255, 255, 255)
WebTextStyle style
style:SetColor(white)

SetEllipsis(boolean value)

Keeps the words on one line and ends a line too long for its box with "...", as for a long file name in a list. The whole text stays in the page for screen readers.

Parameters

  • value boolean: True to cut long lines off.

SetFont(text name)

Sets the font, by name, such as "Montserrat". If a reader's browser doesn't have it, the browser uses its own plain font without serifs.

Parameters

  • name text: The font's name.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle page
page:SetFont("Montserrat")

SetFontSize(number pixels)

Sets the size of the text, in pixels.

Parameters

  • pixels number: The text size. It must be more than 0.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle style
style:SetFontSize(24)

SetItalic(boolean value)

Sets whether the text is italic (slanted).

Parameters

  • value boolean: True for italic text, false for upright text.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle style
style:SetItalic(false)

SetKeepSpaces(boolean value)

Keeps the text's spaces and line breaks as they are, still wrapping long lines, as a console showing a program's output.

Parameters

  • value boolean: True to keep spaces and line breaks.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle console
console:SetKeepSpaces(true)

SetKeepWordsWhole(boolean value)

Keeps each word whole when a line wraps, even in languages that may break between any two characters.

Parameters

  • value boolean: True to keep words whole.

SetLetterSpacing(number pixels)

Sets extra space between letters, in pixels, as for a heading in capitals. It may be negative, to set letters closer.

Parameters

  • pixels number: The extra space.

SetLineHeight(number pixels)

Sets the height of each line of text, in pixels, including the space above and below the letters.

Parameters

  • pixels number: The line height. It must be more than 0.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle style
style:SetFontSize(24)
style:SetLineHeight(32)

SetSelectable(boolean value)

Sets whether a reader can select the words, as to copy them. Turn it off only for controls that are dragged or pressed often, such as a button in an editor; never for content.

Parameters

  • value boolean: False to stop selection.

SetSemibold(boolean value)

Sets whether the text is a little bold (semibold), between normal and bold, as for a button's label. Bold text stays bold.

Parameters

  • value boolean: True for semibold text.

SetUnderline(boolean value)

Sets whether the text is underlined. Links are underlined unless this says otherwise.

Parameters

  • value boolean: True to underline.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle quietLink
quietLink:SetUnderline(false)

SetUppercase(boolean value)

Sets whether the text is shown in capital letters. The words stay as written, so a screen reader reads them normally.

Parameters

  • value boolean: True for capital letters.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle label
label:SetUppercase(true)

SetWeight(integer value)

Sets how heavy the letters are, as a number from 100 (thinnest) to 900 (heaviest): StyleSheetConstants names LIGHT_FONT_WEIGHT, NORMAL_FONT_WEIGHT, MEDIUM_FONT_WEIGHT, SEMIBOLD_FONT_WEIGHT and BOLD_FONT_WEIGHT. It takes the place of SetBold and SetSemibold. The font must have the weight, or the nearest one is shown.

Parameters

  • value integer: The weight, from 100 to 900.

Example

use Libraries.Web.Styles.WebTextStyle
use Libraries.Web.Styles.StyleSheetConstants

StyleSheetConstants constants
WebTextStyle label
label:SetWeight(constants:MEDIUM_FONT_WEIGHT)

SetWrapping(boolean value)

Sets whether the text may wrap onto more lines. Text that may not stays on one line, as a short label under an icon or a button's words in a row that scrolls sideways.

Parameters

  • value boolean: False to keep the text on one line.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle label
label:SetWrapping(false)

UseCodeFont(boolean value)

Shows the text in a code font, one where every letter has the same width, as a console or anything that shows code outside a code block.

Parameters

  • value boolean: True for a code font.

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle console
console:UseCodeFont(true)

UseSurroundingFont()

Uses the same font as the text around it, instead of a font the browser or the site's reset would pick for this kind of element (such as a code font for program output).

Example

use Libraries.Web.Styles.WebTextStyle

WebTextStyle style
style:UseSurroundingFont()

UsesSurroundingFont()

Returns true if the text uses the same font as the text around it.

Returns

boolean: Whether the surrounding font is used.

Inherited Actions

3 actions from Libraries.Language.Object