WebBoxStyle
Package: Libraries.Web.Styles · Inherits from: Libraries.Language.Object, Libraries.Web.Styles.WebStyle
WebBoxStyle sets how an element looks as a box: its background, the space inside its edges, rounded corners, borders on its edges, and a shadow under it. A box can also hold a text style, for the words inside it, since an element has only one style. Anything not set writes nothing, so the box keeps the site's starting look for it. Sizes are in pixels.
Example Code
use Libraries.Web.Page.all
use Libraries.Web.Styles.WebBoxStyle
use Libraries.Web.Styles.WebColor
class Main is WebPage
action Main
WebColor white
white:SetColor(255, 255, 255)
WebBoxStyle card
card:SetBackground(white)
card:SetPadding(8, 24)
card:SetRoundedCorners(8)
Division division
SetStyle(division, card)
Include(division)
end
end
Variables
integer PICTURE_CONTAINinteger FLOATING_LAYERinteger LARGE_SHADOW: dialog, and above everything.integer NO_SHADOW: How deep a box's shadow is (SetShadowDepth).integer MEDIUM_SHADOWinteger PICTURE_COVER: How a picture fills its box (SetPictureFit).integer PICTURE_FILL: One turn a second, steadily, by the keyframes StyleSheet writes.integer POINTER_DEFAULT: (something to click), or a magnifying glass to zoom in or out.integer PAGE_LAYER: dialog, and above everything.integer POINTER_ZOOM_OUT: How a picture fills its box (SetPictureFit).integer DIALOG_LAYERinteger POINTER_ZOOM_INinteger TOP_LAYER: (something to click), or a magnifying glass to zoom in or out.integer SMALL_SHADOWinteger POINTER_HAND
Actions
Copy()
Returns a new box style with the same settings. Change the copy to give one element its own look without changing every element that shares this style. Its colors and text style are copied too.
Returns
Libraries.Web.Styles.WebBoxStyle: A copy of this style.
Generate()
Returns the stylesheet declarations for this box style, and its text style if it has one. WebSite calls this when it writes the stylesheet; people making pages don't.
Returns
text: The declarations for this style.
GetTextStyle()
Returns the style for the words inside the box, or undefined if it has none.
Returns
Libraries.Web.Styles.WebTextStyle: The text style, or undefined.
SetAnchor(boolean value)
Makes the box the one its floating boxes (SetFloating) are placed against, as a toolbar holds a menu that opens below it.
Parameters
valueboolean: True to place floating boxes against this box.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle toolbar
toolbar:SetAnchor(true)
SetBackground(Libraries.Web.Styles.WebColor color)
Sets the color behind the box's content.
Parameters
colorLibraries.Web.Styles.WebColor: The background color.
Example
use Libraries.Web.Styles.WebBoxStyle
use Libraries.Web.Styles.WebColor
WebColor white
white:SetColor(255, 255, 255)
WebBoxStyle box
box:SetBackground(white)
SetBorder(number pixels, Libraries.Web.Styles.WebColor color)
Draws a line around all four edges of the box.
Parameters
pixelsnumber: How thick the line is.colorLibraries.Web.Styles.WebColor: The line's color.
Example
use Libraries.Web.Styles.WebBoxStyle
use Libraries.Web.Styles.WebColor
WebColor paleBlue
paleBlue:SetColor(172, 209, 223)
WebBoxStyle chip
chip:SetBorder(1, paleBlue)
SetBottomBorder(number pixels, Libraries.Web.Styles.WebColor color)
Draws a line along the bottom edge of the box.
Parameters
pixelsnumber: How thick the line is.colorLibraries.Web.Styles.WebColor: The line's color.
Example
use Libraries.Web.Styles.WebBoxStyle
use Libraries.Web.Styles.WebColor
WebColor grey
grey:SetColor(114, 114, 114)
WebBoxStyle row
row:SetBottomBorder(1, grey)
SetBottomMargin(number pixels)
Sets the space below the box only, in pixels. It may be negative, to pull what follows up under it.
Parameters
pixelsnumber: The space below.
SetBottomOffset(number pixels)
Places a floating box this far up from the bottom edge of the box it is placed against.
Parameters
pixelsnumber: The distance, which may be negative.
SetBottomPadding(number pixels)
Sets the space inside the box below its content only, in pixels, on top of SetPadding.
Parameters
pixelsnumber: The space below the content.
SetBrowserGestures(boolean value)
Sets whether the browser's own touch gestures (panning and zooming) work on the box. Turn them off for a box with its own dragging, as an editor whose blocks are dragged.
Parameters
valueboolean: False to leave touch to the box's own script.
SetCenteredHorizontally(boolean value)
Centers the box in the width it is in, with equal space on its left and right. The box needs a width narrower than that (such as SetWidth, SetMaximumWidth or SetFitToContent).
Parameters
valueboolean: True to center the box.
SetClipContent(boolean value)
Sets whether anything inside the box that reaches past its edges is cut off, so its rounded corners round what is inside, too.
Parameters
valueboolean: True to cut off what reaches past the edges.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle table
table:SetRoundedCorners(8)
table:SetClipContent(true)
SetCoverAnchor(boolean value)
Makes the box cover the whole of the nearest box set with SetAnchor, over its content, as a shaded layer on a card or a dialog's backdrop inside a part of the page.
Parameters
valueboolean: True to cover the anchor.
SetCoverWindow(boolean value)
Sets whether the box covers the whole window, over everything else on the page, and stays there as the page scrolls, as for the shaded backdrop behind a dialog.
Parameters
valueboolean: True to cover the window.
SetDisplayed(boolean value)
Sets whether the box is shown at all. A box not shown takes no space and isn't read by screen readers. Set from a screen width (see WebPage's SetStyleFromWidth), this hides a box on small screens and shows it on wide ones.
Parameters
valueboolean: True to show the box, false to hide it.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle hiddenOnPhones
hiddenOnPhones:SetDisplayed(false)
SetEqualShare(boolean value)
Makes the box take an equal share of a row or stack with the other boxes set this way, whatever their content.
Parameters
valueboolean: True for an equal share.
SetFillScreenHeight(boolean value)
Sets whether the box is at least as tall as the window, as for a page whose footer should sit at the bottom even when the page is short.
Parameters
valueboolean: True to fill the window's height.
SetFitToContent(boolean value)
Sizes the box to what is inside it, as narrow and as short as its content allows, as for a button that shouldn't stretch. It also undoes a width or height set for smaller screens.
Parameters
valueboolean: True to fit the content.
SetFloating(boolean value)
Floats the box over the content around it, as a menu or a dialog over an editor, placed against the nearest box set with SetAnchor (SetTopOffset and SetRightOffset place it). It is drawn over the page, at the layer a box covering the window uses.
Parameters
valueboolean: True to float the box.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle menu
menu:SetFloating(true)
menu:SetTopOffsetPercent(100)
menu:SetRightOffset(8)
SetGrow(boolean value)
Sets whether the box grows to take up the room left over in a row or stack, such as a page's main content between its header and footer.
Parameters
valueboolean: True to grow.
SetHeight(number pixels)
Sets the box's height, in pixels, as for a console that keeps its size and scrolls (see SetScrollable).
Parameters
pixelsnumber: The height.
SetHeightPercent(number percent)
Sets the box's height as a share of the height it is in.
Parameters
percentnumber: The share, from 0 to 100.
SetInFlow(boolean value)
Puts the box back in the page's flow, where it would be without floating, covering or sticking, as for a menu that floats on phones but sits in a row on wider screens.
Parameters
valueboolean: True to put it back in the flow.
SetInline(boolean value)
Makes the box sit in a line of words, as a word does, while keeping its own padding, edges and size, as for a key, a badge or a small button inside a sentence.
Parameters
valueboolean: True to sit in the line.
SetInvisible(boolean value)
Hides the box while keeping the room it takes, so nothing around it moves, as for a message that appears in its place later. Screen readers skip it too.
Parameters
valueboolean: True to hide the box.
SetLayer(integer value)
Sets which boxes are drawn over which: a box on a higher layer is drawn over one on a lower layer. Use the layer constants: PAGE_LAYER, FLOATING_LAYER (menus, as SetFloating uses), DIALOG_LAYER and TOP_LAYER. It applies to boxes that float, cover or stick.
Parameters
valueinteger: The layer.
SetLeftBorder(number pixels, Libraries.Web.Styles.WebColor color)
Draws a line along the left edge of the box, as an accent.
Parameters
pixelsnumber: How thick the line is.colorLibraries.Web.Styles.WebColor: The line's color.
Example
use Libraries.Web.Styles.WebBoxStyle
use Libraries.Web.Styles.WebColor
WebColor blue
blue:SetColor(6, 149, 208)
WebBoxStyle box
box:SetLeftBorder(4, blue)
SetLeftMargin(number pixels)
Sets the space to the left of the box only, in pixels, as for an indented item.
Parameters
pixelsnumber: The space to the left.
SetLeftOffset(number pixels)
Places a floating or covering box this far in from the left edge of the box it is placed against.
Parameters
pixelsnumber: The distance, which may be negative.
SetLeftPadding(number pixels)
Sets the space inside the box to the left of its content only, in pixels, on top of SetPadding.
Parameters
pixelsnumber: The space to the left of the content.
SetMargin(number vertical, number horizontal)
Sets the space outside the box's edges, in pixels: one amount for the top and bottom, another for the left and right.
Parameters
verticalnumber: The space above and below.horizontalnumber: The space to the left and right.
SetMaximumHeight(number pixels)
Sets the tallest the box may be, in pixels; what doesn't fit scrolls if the box is scrollable (SetScrollable), or is cut off if it clips (SetClipContent).
Parameters
pixelsnumber: The tallest height.
SetMaximumHeightBelowWindow(number pixels)
Keeps the box no taller than the window, less a margin, scrolling what doesn't fit, as a dialog with a long list.
Parameters
pixelsnumber: The room to leave, in all, above and below.
SetMaximumHeightPercent(number percent)
Sets the tallest the box may be, as a share of the height it is in, as for a dialog that may fill the window but no more.
Parameters
percentnumber: The share, from 0 to 100.
SetMaximumWidth(number pixels)
Sets the widest the box may be, in pixels. It is narrower on screens too small for it.
Parameters
pixelsnumber: The widest width.
SetMaximumWidthPercent(number percent)
Sets the widest the box may be, as a share of the width it is in, as for a chart that should never be wider than its column.
Parameters
percentnumber: The share, from 0 to 100.
SetMinimumHeight(number pixels)
Sets the least height the box may have, in pixels. It grows past this when its content needs more.
Parameters
pixelsnumber: The least height.
SetMinimumWidth(number pixels)
Sets the narrowest the box may be, in pixels, as for a chart that should never shrink to nothing.
Parameters
pixelsnumber: The narrowest width.
SetOpacityPercent(number percent)
Sets how solid the box and everything in it is drawn, as a share: 100 is solid, 50 lets half of what is behind it show through, as for a button that can't be used yet.
Parameters
percentnumber: The share, from 0 to 100.
SetOutline(number pixels, Libraries.Web.Styles.WebColor color)
Draws a line around the box's outside that takes no room, as for showing where keyboard focus is (with WebPage:SetStyleOnKeyboardFocus).
Parameters
pixelsnumber: The line's thickness; 0 removes the browser's own.colorLibraries.Web.Styles.WebColor: The line's color.
SetOutlineOffset(number pixels)
Sets how far the outline sits outside the box's edge (SetOutline).
Parameters
pixelsnumber: The gap, which may be negative to draw it inside.
SetOwnAlignment(integer alignment)
Lines this box up on its own in a row or stack, instead of the way its layout lines up the others: across a stack, constants LEFT_ALIGN, CENTER_ALIGN, RIGHT_ALIGN or STRETCH_ALIGN; in a row, left means the top and right the bottom.
Parameters
alignmentinteger: One of StyleSheetConstants' alignment constants.
SetPadding(number vertical, number horizontal)
Sets the space between the box's edges and its content, in pixels: one amount for the top and bottom, another for the left and right.
Parameters
verticalnumber: The space at the top and bottom.horizontalnumber: The space at the left and right.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle box
box:SetPadding(8, 24)
SetPictureFit(integer value)
Sets how a picture fills a box of a set size: PICTURE_COVER fills it, cutting off what doesn't fit; PICTURE_CONTAIN shows all of it, leaving room around it; PICTURE_FILL stretches it. The picture stays centered. Set it on the picture itself.
Parameters
valueinteger: One of the picture constants.
SetPointer(integer value)
Sets the pointer shown over the box: POINTER_HAND, as over something to click, POINTER_ZOOM_IN or POINTER_ZOOM_OUT, as over a picture that zooms, or POINTER_DEFAULT, the browser's own. The "not allowed" pointer (SetShowsUnavailable) wins over it.
Parameters
valueinteger: One of the POINTER constants.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle zoomable
zoomable:SetPointer(zoomable:POINTER_ZOOM_IN)
SetRightBorder(number pixels, Libraries.Web.Styles.WebColor color)
Draws a solid line along the box's right edge, as between columns.
Parameters
pixelsnumber: The line's thickness.colorLibraries.Web.Styles.WebColor: The line's color.
SetRightMargin(number pixels)
Sets the space to the right of the box only, in pixels.
Parameters
pixelsnumber: The space to the right.
SetRightOffset(number pixels)
Places a floating box this far in from the right edge of the box it is placed against.
Parameters
pixelsnumber: The distance.
SetRightPadding(number pixels)
Sets the space inside the box to the right of its content only, in pixels, on top of SetPadding.
Parameters
pixelsnumber: The space to the right of the content.
SetRoundedBottom(number pixels)
Rounds the box's two bottom corners.
Parameters
pixelsnumber: How far the rounding reaches along each edge.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle body
body:SetRoundedBottom(8)
SetRoundedBottomLeft(number pixels)
Rounds the box's bottom left corner only.
Parameters
pixelsnumber: The corner's radius.
SetRoundedBottomRight(number pixels)
Rounds the box's bottom right corner only.
Parameters
pixelsnumber: The corner's radius.
SetRoundedCorners(number pixels)
Rounds all four corners of the box.
Parameters
pixelsnumber: How far the rounding reaches along each edge.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle box
box:SetRoundedCorners(8)
SetRoundedTop(number pixels)
Rounds the box's two top corners, as for a label sitting on top of another box.
Parameters
pixelsnumber: How far the rounding reaches along each edge.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle label
label:SetRoundedTop(8)
SetRoundedTopLeft(number pixels)
Rounds the box's top left corner only, as for the first of a row of tabs.
Parameters
pixelsnumber: The corner's radius.
SetRoundedTopRight(number pixels)
Rounds the box's top right corner only, as for the last of a row of tabs.
Parameters
pixelsnumber: The corner's radius.
SetScrollSideways(boolean value)
Lets what is too wide for the box scroll sideways inside it, as a row of buttons on a phone, without making the page wider.
Parameters
valueboolean: True to scroll sideways.
SetScrollable(boolean value)
Lets what doesn't fit in the box scroll inside it, in either direction, as a console.
Parameters
valueboolean: True to scroll.
SetShadow(boolean value)
Sets whether the box has a small, soft shadow under it.
Parameters
valueboolean: True for a shadow.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle card
card:SetShadow(true)
SetShadowColor(Libraries.Web.Styles.WebColor color)
Sets the color of the box's shadow, which is otherwise a faint black. A see-through color (WebColor:SetOpacity) looks softest.
Parameters
colorLibraries.Web.Styles.WebColor: The shadow's color.
SetShadowDepth(integer depth)
Sets how deep the shadow under the box is: NO_SHADOW, SMALL_SHADOW (as SetShadow), MEDIUM_SHADOW, for a box that stands further off the page, such as an editor or a menu, or LARGE_SHADOW, for a dialog over the page.
Parameters
depthinteger: One of this class's shadow constants.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle dialog
dialog:SetShadowDepth(dialog:LARGE_SHADOW)
SetShowsUnavailable(boolean value)
Shows the pointer as "not allowed" over the box, as over a button that can't be used yet.
Parameters
valueboolean: True to show it.
SetShrink(boolean value)
Sets whether the box may get narrower than its content to make room in a row. False keeps it at least as wide as its content, as for an icon beside words that wrap.
Parameters
valueboolean: False to never shrink.
SetShrinkBelowContent(boolean value)
Lets the box, in a row or stack, be narrower than the widest thing inside it, such as a long line of code, which then scrolls inside its own box instead of making the page wider than the screen.
Parameters
valueboolean: True to let the box narrow.
SetSidePaddingPercent(number percent)
Sets the space inside the box on its left and right as a share of the width it is in, so a wide section keeps the same proportions on every screen.
Parameters
percentnumber: The share on each side, from 0 to 50.
SetSpanAllColumns(boolean value)
Makes the box take a whole row of the grid it is in, across every column, as for a heading inside a grid of cards.
Parameters
valueboolean: True to span every column.
SetSpinning(boolean value)
Turns the box steadily, as a spinner while something works. Readers who ask their system for less motion see it still.
Parameters
valueboolean: True to spin.
SetStickyTop(number pixels)
Keeps the box in view as the page scrolls, this far from the top of the window, once it reaches there, as for a list of contents beside the text. The box is never taller than the window below that point; if its contents are, it scrolls on its own, so all of it can be reached.
Parameters
pixelsnumber: How far from the top of the window the box stays.
SetTextStyle(Libraries.Web.Styles.WebTextStyle style)
Sets how the words inside the box look.
Parameters
styleLibraries.Web.Styles.WebTextStyle: The text style for the box's words.
Example
use Libraries.Web.Styles.WebBoxStyle
use Libraries.Web.Styles.WebTextStyle
WebTextStyle words
words:SetBold(true)
WebBoxStyle label
label:SetTextStyle(words)
SetTopBorder(number pixels, Libraries.Web.Styles.WebColor color)
Draws a line along the top edge of the box.
Parameters
pixelsnumber: How thick the line is.colorLibraries.Web.Styles.WebColor: The line's color.
Example
use Libraries.Web.Styles.WebBoxStyle
use Libraries.Web.Styles.WebColor
WebColor grey
grey:SetColor(114, 114, 114)
WebBoxStyle row
row:SetTopBorder(1, grey)
SetTopMargin(number pixels)
Sets the space above the box only, in pixels. It may be negative, to pull the box up over what is above it.
Parameters
pixelsnumber: The space above.
SetTopOffset(number pixels)
Places a floating box this far below the top of the box it is placed against.
Parameters
pixelsnumber: The distance, which may be negative to place it above.
SetTopOffsetPercent(number percent)
Places a floating box a share of the way down the box it is placed against: 100 puts it just below that box.
Parameters
percentnumber: The share, from 0 to 100.
SetTopPadding(number pixels)
Sets the space inside the box above its content only, in pixels, on top of SetPadding.
Parameters
pixelsnumber: The space above the content.
SetVisuallyHidden(boolean value)
Sets whether the box is hidden from sight but still read by screen readers, such as a link to skip to the content, shown only when it has keyboard focus.
Parameters
valueboolean: True to hide the box from sight only; false to show it again.
Example
use Libraries.Web.Styles.WebBoxStyle
WebBoxStyle skipLink
skipLink:SetVisuallyHidden(true)
SetWidth(number pixels)
Sets the box's width, in pixels. It still narrows on screens too small for it if it may (see SetShrinkBelowContent).
Parameters
pixelsnumber: The width.
SetWidthPercent(number percent)
Sets the box's width as a share of the width it is in.
Parameters
percentnumber: The share, from 0 to 100.
SetWindowHeight(boolean value)
Makes the box exactly as tall as the window, as for a dialog's backdrop or a page that fills the screen.
Parameters
valueboolean: True for the window's height.