Skip to content

ui ​

原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793488866/FIN+5.3.1+ui 中文整理基于 FIN 5.3.1

导读: Fresco 用户界面框架

以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。


目录(导读) ​

  • classes
  • Slot Details
    • addButton
    • icon
    • info
    • make
    • msg
    • onAction
    • onBeforeOpen
    • width
    • eval
    • addButtonGap
    • aux
    • button
    • content
    • height
    • defs
    • dialog
    • makeInput
    • modified
    • rec
    • save
    • session
    • grid
    • gridModel
    • onMouseDown
    • onNav
    • selRows
    • colWidth
    • cols
    • isVisibleDef
    • item
    • navCols
    • numCols
    • numRows
    • onCell
    • onHeader
    • prefWidth
    • rowHeight
    • sortCompare
    • color
    • onParent
    • outline
    • resize
    • solid
    • def
    • load
    • makeForDef
    • makeForTag
    • onLoad
    • onModify
    • onRO
    • onSave
    • ro
    • addTab
    • onBeforeTab
    • selIndex
    • tabs
    • invoke
    • meta
    • updateView
    • view
    • attestKey
    • key
    • proj
    • user
    • anchorElem
    • asyncMenu
    • closest
    • containedIn
    • encodeUri
    • errTrace
    • fandocParse
    • fandocToElem
    • fandocToHtml
    • fontBlack
    • fontBold
    • fontLight
    • helpButton
    • hsep
    • iconCss
    • iconUri
    • itemToElem
    • makeAbsBox
    • makeCenterBox
    • makeEmptyBox
    • makeSpinnerBox
    • menuSep
    • sanitizeUri
    • tableCellIcons
    • action
    • actions
    • data
    • fireSelect
    • onSelect
    • onUpdate
    • sel
    • update
    • var
    • layoutWithContent

概述(中译) ​

@Js 类 AlertDialog : Dialog

警告对话框通知用户事件,并允许他们采取行动来决定如何进行。

构造函数

字段

方法

插槽详情

这个 addButton(Str key, Str? dis := null, Bool def := false)

向对话框添加一个操作按钮。如果 dis 为 null,则使用 key 作为本地化键查找显示名称。


API 正文(英文) ​

icon ​

Icon? icon := null

Icon to display in dialog.


info ​

Str info := ""

Optional informational text to display below message.


make ​

new make()

Constructor.


msg ​

Str msg := ""

Primary message text in dialog.


onAction ​

Void onAction(|Str->Bool| f)

Callback when dialog is closed, where key is the button used to dismiss the dialog. Return true to close dialog or false prevent close and keep dialog open.


onBeforeOpen ​

protected virtual override Void onBeforeOpen()


width ​

Str? width := null

Width of content in CSS length, or null for default.


AlertSheet ​

@Js class AlertSheet : Sheet

Alert sheets inform the user of an event and allow them to take action of how to proceed.

Constructors

makeConstructor.

Fields

iconIcon to display in sheet.
infoOptional informational text to display below message.
msgPrimary message text in sheet.

Methods

addButtonAdd an action button to sheet.
onActionCallback when sheet is closed, where key is the button used to dismiss the sheet.
onBeforeOpen

Slot Details ​


addButton ​

This addButton(Str key, Str? dis := null, Bool def := false)

Add an action button to sheet. If dis is null, then lookup display name using key as the locale key.


icon ​

Icon? icon := null

Icon to display in sheet.


info ​

Str info := ""

Optional informational text to display below message.


make ​

new make()

Constructor.


msg ​

Str msg := ""

Primary message text in sheet.


onAction ​

Void onAction(|Str->Bool| f)

Callback when sheet is closed, where key is the button used to dismiss the sheet. Return true to close sheet or false prevent close and keep sheet open.


onBeforeOpen ​

protected virtual override Void onBeforeOpen()


AsyncContentDialog ​

@Js class AsyncContentDialog : ContentDialog

AsyncContentDialog extends ContentDialog with async content loading.

Constructors

makeConstructor.

Methods

evalOpen dialog and evalute the given axon expression using UiSession and pass results to callback function.

Slot Details ​


eval ​

Void eval(UiSession session, Str expr, |ContentDialog,Grid| onComplete)

Open dialog and evalute the given axon expression using UiSession and pass results to callback function.


make ​

new make()

Constructor.


ContentDialog ​

@Js class ContentDialog : Dialog

Content dialogs display content with a standard button bar across the bottom of the dialog.

Constructors

makeConstructor.

Fields

auxAuxiliary content is displayed below content to the left of the action buttons.
contentContent of dialog
heightHeight of content in CSS length, or null for default.
widthWidth of content in CSS length, or null for default.

Methods

addButtonAdd an action button to dialog.
addButtonGapAdd a button gap to dialog.
buttonGet button instance for key.
onActionCallback when dialog is closed, where key is the button used to dismiss the dialog.
onBeforeOpen

Slot Details ​


addButton ​

This addButton(Str key, Str? dis := null, Bool def := false)

Add an action button to dialog. If dis is null, then lookup display name using key as the locale key.


addButtonGap ​

This addButtonGap()

Add a button gap to dialog.


aux ​

Elem? aux

Auxiliary content is displayed below content to the left of the action buttons.


button ​

Button button(Str key)

Get button instance for key.


content ​

Elem? content

Content of dialog


height ​

Str? height := null

Height of content in CSS length, or null for default.


make ​

new make()

Constructor.


onAction ​

Void onAction(|Str->Bool| f)

Callback when dialog is closed, where key is the button used to dismiss the dialog. Return true to close dialog or false prevent close and keep dialog open.


onBeforeOpen ​

protected virtual override Void onBeforeOpen()


width ​

Str? width := null

Width of content in CSS length, or null for default.


Form ​

@Js abstract class Form : Box

Form edits a list of ValDefs.

Constructors

makeIt-block constructor.

Fields

defsList of ValDefs to edit.
recOriginal rec instance.
sessionUiSession instance.

Methods

dialogCreate a dialog for this form.
makeInputMake an Input instance for given ValDef.
modifiedHas form been modified?
saveSave form and return changes, or throw Err if failed to save.

Slot Details ​


defs ​

ValDef[] defs

List of ValDefs to edit.


dialog ​

virtual ContentDialog dialog()

Create a dialog for this form.


make ​

new make(|This| f)

It-block constructor.


makeInput ​

protected Input makeInput(ValDef def)

Make an Input instance for given ValDef.


modified ​

abstract Bool modified()

Has form been modified?


rec ​

const Dict rec

Original rec instance.


save ​

abstract Dict save()

Save form and return changes, or throw Err if failed to save.


session ​

const UiSession session

UiSession instance.


GridTable ​

@Js class GridTable : Table

GridTable provides specialized visualization for a Grid

Constructors

make

Methods

gridGrid for this table.
gridModelGridTableModel for this table.
onMouseDownCallback when a table cell is pressed.
onNavCallback when GridTableModel.navCols column is clicked in a table row.
selRowsConvenience to get selected rows as Dict[].

Slot Details ​


grid ​

Grid grid()

Grid for this table.


gridModel ​

GridTableModel gridModel()

GridTableModel for this table.


make ​

new make()


onMouseDown ​

virtual Void onMouseDown(TableEvent e)

Callback when a table cell is pressed.


onNav ​

Void onNav(|Str,Dict| f)

Callback when GridTableModel.navCols column is clicked in a table row.


selRows ​

Dict[] selRows()

Convenience to get selected rows as Dict[].


GridTableModel ​

@Js class GridTableModel : TableModel

GridTableModel for GridTable

Constructors

makeConstructor.

Fields

navColsColumns that display as navigation colums.
sessionUiSession

Methods

colWidth
colsColumns for this table.
gridGrid this table is modeling.
isVisibleDef
item
numCols
numRows
onCell
onHeader
prefWidthGet preferred width of column.
rowHeight
sortCompare

Slot Details ​


colWidth ​

virtual override Int colWidth(Int c)


cols ​

Col[] cols()

Columns for this table. Defaults to all columns in grid.


grid ​

Grid grid()

Grid this table is modeling.


isVisibleDef ​

virtual override Bool isVisibleDef(Int col)


item ​

virtual override Obj item(Int row)


make ​

new make(UiSession session, Grid grid, Str[]? cols := null)

Constructor.


Str[] navCols := Str[,]

Columns that display as navigation colums. A nav column is represnted with an arrow on the right side of the cell. When this arrow is pressed, the GridTable.onNav callback is invoked with the given column name and row.


numCols ​

virtual override Int numCols()


numRows ​

virtual override Int numRows()


onCell ​

virtual override Void onCell(Elem cell, Int c, Int r, TableFlags flags)


onHeader ​

virtual override Void onHeader(Elem header, Int c)


prefWidth ​

virtual Int prefWidth(Col col)

Get preferred width of column.


rowHeight ​

virtual override Int rowHeight()


session ​

const UiSession session

UiSession


sortCompare ​

virtual override Int sortCompare(Int c, Int row1, Int row2)


Icon ​

@Js class Icon : Elem

Icon displays an SVG icon using a <img> node.

Constructors

makeConstruct a new Icon instance.

Methods

colorConvenience for make(name, "color", null)
onParent
outlineConvenience for make(name, "outline", color)
resizeResize icon.
solidConvenience for make(name, "solid", color)

Slot Details ​


color ​

static Icon color(Str name)

Convenience for make(name, "color", null)


make ​

new make(Str name, Str style, Str? color)

Construct a new Icon instance.


onParent ​

protected virtual override Void onParent(Elem p)


outline ​

static Icon outline(Str name, Str color := "#333")

Convenience for make(name, "outline", color)


resize ​

This resize(Str size)

Resize icon.


solid ​

static Icon solid(Str name, Str color := "#333")

Convenience for make(name, "solid", color)


Input ​

@Js abstract class Input : Elem

Input is a user interface field to display and input values. See Fantom

Constructors

makeSub-class constructor

Fields

defValue type definition
modifiedHas this field been modified since last load or save.
roIs this field set to readonly or editable.
sessionUiSession

Methods

loadLoad tag value into field.
makeForDefConstruct input field for given definition and value
makeForTagConstruct the best input to use for the tag name and value.
onLoadOverride callback to load value.
onModifyCallback when field has been modified.
onROOverride callback when ro is changed.
onSaveOverride callback to save value.
saveSave current field input to new tag value.

Slot Details ​


def ​

const ValDef def

Value type definition


load ​

This load(Obj val)

Load tag value into field.


make ​

new make()

Sub-class constructor


makeForDef ​

static Input makeForDef(UiSession session, ValDef def, Obj val)

Construct input field for given definition and value


makeForTag ​

static Input makeForTag(UiSession session, Str name, Obj val)

Construct the best input to use for the tag name and value.


modified ​

Bool modified := false { protected set }

Has this field been modified since last load or save.


onLoad ​

protected abstract Void onLoad(Obj val)

Override callback to load value.


onModify ​

Void onModify(|Input| f)

Callback when field has been modified.


onRO ​

protected abstract Void onRO()

Override callback when ro is changed.


onSave ​

protected abstract Obj onSave()

Override callback to save value.


ro ​

Bool ro := false

Is this field set to readonly or editable.


save ​

Obj save()

Save current field input to new tag value.


session ​

const UiSession session

UiSession


TabBox ​

@Js class TabBox : CardBox

TabBox extends CardBox to create tab buttons that can be used to display a given card. The tab buttons are not mounted inside this element, so it's the caller's responsibility to parent them in the desired layout.

Fields

selIndexIndex of currently selected tab.

Methods

addTabAdd a new card for tab name.
onBeforeTabCallback before a tab changes.
tabsGet tab widget.

Slot Details ​


addTab ​

This addTab(Str name, Elem card, |ToggleButton|? f := null)

Add a new card for tab name.


onBeforeTab ​

Void onBeforeTab(|TabBox,Int->Bool| f)

Callback before a tab changes. Return true to change the tab, or false to remain on the current tab.


selIndex ​

virtual override Int? selIndex

Index of currently selected tab.


tabs ​

Elem tabs()

Get tab widget.


UiAction ​

@Js class UiAction : Obj

UiAction is the user interface component of an action.

Fields

viewParent view.

Methods

buttonCreate a new Button to invoke this action.
invokeInvoke this action.
metaAction meta data
updateView

Slot Details ​


button ​

Button button()

Create a new Button to invoke this action.


invoke ​

Void invoke(Obj? args := null)

Invoke this action.


meta ​

Dict meta()

Action meta data


updateView ​

Void updateView(Str:Obj changes := [:])


view ​

UiView view { private set }

Parent view.


UiSession ​

@Js const class UiSession : Session

UiSession is the top level API for modeling the UI session to a server

Fields

attestKeyAttestation session key used as secondary verification of cookie key
userUser account for authenticated session

Methods

keySession key
projConvenience for space.proj(false)

Slot Details ​


attestKey ​

virtual const override Str attestKey

Attestation session key used as secondary verification of cookie key


key ​

virtual override Str key()

Session key


proj ​

ProjDef? proj()

Convenience for space.proj(false)


user ​

virtual const override User user

User account for authenticated session


UiUtil ​

@Js class UiUtil : Obj

Fresco utilities

Fields

fontBlackInline CSS style for black font weight.
fontBoldInline CSS style for bold font weight.
fontLightInline CSS style for light font weight.

Methods

anchorElemMake anchor element for user defined URI with security checks
asyncMenuCreate an Menu that displays a Spinner until content is loaded.
closestFind the closest ancestor of given elem that is of type type, or null if none found.
containedInReturn true if elem is contained in a parent of type type.
encodeUriEncode URI with security checks
errTraceCreate a elem to display the given err with trace.
fandocParseParse fandoc
fandocToElemGet HTML for fandoc source an elem
fandocToHtmlGet HTML for fandoc source Str text.
helpButtonCreate the standard "help" button to display a help fandoc.
hsepCreate a horizontal separator element with optional padding.
iconCssConvenience to wrap iconUri inside a url(...) CSS property string.
iconUriGet SVG icon URI for given style and color.
itemToElemPimItem to element
makeAbsBoxCreate an absolutely positioned Box that defaults left/top to 0px and width/height to 100%
makeCenterBoxWrap content in an element that centers content both horizontally and vertically in parent.
makeEmptyBoxCreate an empty bordered Box.
makeSpinnerBoxCreate an empty bordered Box with a Spinner instance.
menuSepCreate a separator element for use in menus.
sanitizeUriSanity URI already encoded
tableCellIconsConfigure given table cell node to use given left/right aligned Icons as background images.
tabsCreate a ButtonGroup to function as tab bar.

Slot Details ​


anchorElem ​

static Elem anchorElem(Uri uri, Str dis)

Make anchor element for user defined URI with security checks


asyncMenu ​

static Menu asyncMenu(Menu? menu := null)

Create an Menu that displays a Spinner until content is loaded.


closest ​

static Elem? closest(Elem elem, Type type)

Find the closest ancestor of given elem that is of type type, or null if none found.


containedIn ​

static Bool containedIn(Elem elem, Type type)

Return true if elem is contained in a parent of type type.


encodeUri ​

static Str encodeUri(Uri uri)

Encode URI with security checks


errTrace ​

static Elem errTrace(Grid err)

Create a elem to display the given err with trace.


fandocParse ​

static Doc fandocParse(Str s)

Parse fandoc


fandocToElem ​

static Elem fandocToElem(Str text)

Get HTML for fandoc source an elem


fandocToHtml ​

static Str fandocToHtml(Str text)

Get HTML for fandoc source Str text.


fontBlack ​

const static Str fontBlack := "font-weight:700"

Inline CSS style for black font weight.


fontBold ​

const static Str fontBold := "font-weight:500"

Inline CSS style for bold font weight.


fontLight ​

const static Str fontLight := "font-weight:300"

Inline CSS style for light font weight.


helpButton ​

static Button helpButton(Str fandoc)

Create the standard "help" button to display a help fandoc.


hsep ​

static Elem hsep(Str padding := "10px 0")

Create a horizontal separator element with optional padding.


iconCss ​

static Str iconCss(Str name, Str style, Str? color)

Convenience to wrap iconUri inside a url(...) CSS property string. See iconUri.


iconUri ​

static Uri iconUri(Str name, Str style, Str? color)

Get SVG icon URI for given style and color. The style value may be any of "color", "solid", or "outline". If color is non-null outline and solid icons will be colorized. The color field has no effect on color style.


itemToElem ​

static Elem itemToElem(PimItem item, Dict opts := Etc.emptyDict())

PimItem to element


makeAbsBox ​

static Box makeAbsBox()

Create an absolutely positioned Box that defaults left/top to 0px and width/height to 100%


makeCenterBox ​

static Elem makeCenterBox(Elem content)

Wrap content in an element that centers content both horizontally and vertically in parent.


makeEmptyBox ​

static Box makeEmptyBox()

Create an empty bordered Box.


makeSpinnerBox ​

static Box makeSpinnerBox()

Create an empty bordered Box with a Spinner instance.


static Elem menuSep()

Create a separator element for use in menus.


sanitizeUri ​

static Str sanitizeUri(Str uri)

Sanity URI already encoded


tableCellIcons ​

static Void tableCellIcons(Elem cell, Uri[]? left, Uri[]? right, TableFlags flags)

Configure given table cell node to use given left/right aligned Icons as background images.


tabs ​

static ButtonGroup tabs(Str[] names)

Create a ButtonGroup to function as tab bar.


UiView ​

@Js abstract class UiView : Box

UiView is the web browser implementation for a ViewNode. See Fantom.

Constructors

makeConstructor.

Fields

actionsActions for this view.
sessionSession instance.

Methods

actionLookup an action by name
dataGet grid data for given name, or first grid if name is null.
fireSelectFire onSelect callback to indicate selection updated.
onSelectCallback when sel is updated.
onUpdateCallback when either new data is available or a var has been modified.
selThe selected records or empty list if none selected or not applicable.
updateUpdate view with given state.
varReturn the variable value for the given name, or return null if name not found.

Slot Details ​


action ​

UiAction? action(Str name, Bool checked := true)

Lookup an action by name


actions ​

UiAction[] actions { private set }

Actions for this view.


data ​

Grid? data(Str? name := null, Bool checked := true)

Get grid data for given name, or first grid if name is null. If data cannot be found and checked is true throws Err, otherwise returns null.


fireSelect ​

protected Void fireSelect()

Fire onSelect callback to indicate selection updated.


make ​

new make()

Constructor.


onSelect ​

Void onSelect(|This| f)

Callback when sel is updated.


onUpdate ​

virtual Void onUpdate()

Callback when either new data is available or a var has been modified. The current data grid is available via the data method.


sel ​

virtual Dict[] sel()

The selected records or empty list if none selected or not applicable.


session ​

const UiSession session

Session instance.


update ​

Void update(Str:Obj changes := [:], Dict opts := Etc.emptyDict())

Update view with given state.


var ​

Obj? var(Str name)

Return the variable value for the given name, or return null if name not found.


UiViewBar ​

@Js class UiViewBar : Box

UiViewBar provides default support for UiView inputs and actions.

Constructors

makeConstructor.

Methods

layoutWithContentReturn a new DOM node that lays out this viewbar with given content.

Slot Details ​


layoutWithContent ​

Elem layoutWithContent(Elem content)

Return a new DOM node that lays out this viewbar with given content.


make ​

new make(UiView view)

Constructor.