---++!! !CommonCtrl.HTMLRenderer %TOC{title="Contents:"}% %STARTINCLUDE% ---++ A simple HTML renderer | *Title* | A simple HTML renderer | | *Author(s)* | LiXizhi | | *Date* | 2007/10/3 | | *File* | script/ide/HTMLRenderer.lua | ---+++ Description It only support formatting to the following tag and their attributes: h1, h2,h3, h4, li, img(attr: src,height, width, title), a(href), anyTag(attr: style="color: #006699; left: -60px; position: relative; top: 30px;width: 100px;height: 100px"),title It also support relative image path as well as HTTP file path. In addition to per tag css, it also support global CSS via a table called css during initialization. All images are displayed on the left block, where all text are displayed in the right block. images is aligned vertically at the its normal text flow position. Note1: the HTML must use ansi encoding. Unicode or UTF8 encoding will render Chinese text unreadable. Note2: all HTML tag and attribute must use lower case. Note3: we can use tag css to position a text or image any where relative to its normal text flow. We can also specify fixed block size. Example file: script/test/testHTMLrenderer.html %T% __Sample Code__ <verbatim> NPL.load("(gl)script/ide/HTMLRenderer.lua"); local ctl = CommonCtrl.GetControl("HTMLRenderer1"); if(not ctl) then ctl = CommonCtrl.HTMLRenderer:new{ name = "HTMLRenderer1", alignment = "_lt", left=0, top=0, width = 512, height = 290, parent = _parent, source = "script/test/TestHTMLRenderer.html" }; end ctl:Show(); -- call to load another source -- ctl:LoadFile("readme.html", true); -- call to unload resources -- ctl:Unload() </verbatim> ---+++ Member Functions ---++++ !HTMLRenderer:new <verbatim> common control library NPL.load("(gl)script/ide/commonlib.lua"); NPL.load("(gl)script/ide/common_control.lua"); define a new control in the common control libary default member attributes local HTMLRenderer = { -- the top level control name name = "HTMLRenderer1", -- normal window size alignment = "_lt", left = 0, top = 0, width = 512, height = 400, -- the fixed text width. the remaining is the image bar width. By default it is 0.6 of the total width TextWidth = nil, parent = nil, -- HTML file path, it also support pure txt file. source = nil, -- HREF link callback, it should be a function of type function(href) end, where href is the string. If this function is not provided, a default function is used. HRefLinkCallback = nil, -- TODO: shall we implement some css in HTML, so that we can set default h1, etc tag style css = { ["title"] = { scaling = 1.2, indent = -20, }, ["h1"] = { scaling = 1.2, indent = -5, headimage = "Texture/unradiobox.png", headimagewidth = 16, }, ["h2"] = { scaling = 1.15, indent = -5, headimage = "Texture/unradiobox.png", headimagewidth = 16, }, ["h3"] = { scaling = 1.1, indent = -5, headimage = "Texture/unradiobox.png", headimagewidth = 16, }, ["h4"] = { scaling = 1.1, indent = 0, headimage = "Texture/unradiobox.png", headimagewidth = 16, }, ["li"] = { scaling = 1, indent = 3, headimage = "Texture/unradiobox.png", headimagewidth = 8, }, ["Text"] = { scaling = 1, indent = -10, }, ["a"] = { scaling = 1, color = "0 0 255", }, }, }</verbatim> CommonCtrl.HTMLRenderer = HTMLRenderer; constructor __syntax__ <verbatim>function HTMLRenderer:new (o)</verbatim> __parameters__ | *o* | | ---++++ !HTMLRenderer:Destroy Destroy the UI control __syntax__ <verbatim>function HTMLRenderer:Destroy ()</verbatim> ---++++ !HTMLRenderer:Show * _param_ __bShow__ : boolean to show or hide. if nil, it will toggle current setting. __syntax__ <verbatim>function HTMLRenderer:Show(bShow)</verbatim> __parameters__ | *bShow* | boolean to show or hide. if nil, it will toggle current setting. | ---++++ !HTMLRenderer:LoadFile load a file to memory and display it. * _param_ __bReload__ : true to reload __syntax__ <verbatim>function HTMLRenderer:LoadFile(source, bReload)</verbatim> __parameters__ | *source* | | | *bReload* | true to reload | ---++++ !HTMLRenderer:Unload unload all resources used by this ctl __syntax__ <verbatim>function HTMLRenderer:Unload()</verbatim> ---++++ !HTMLRenderer.BuildHTML private: build internal treeview node to display a table. * _param_ __o__ : the current xml table * _param_ __treeNode__ : to which treeview node the content is saved to. * _param_ __sizeUI__ : the UI object to calculate size of the UI control * _param_ __style__ : nil or a table containing style{color=string, href=string}. This is a style object to be associated with each node. __syntax__ <verbatim>function HTMLRenderer.BuildHTML(o, node, sizeUI, style)</verbatim> __parameters__ | *o* | the current xml table | | *node* | | | *sizeUI* | the UI object to calculate size of the UI control | | *style* | | ---++++ !HTMLRenderer.HTMLGetAllTextInTable private: retrieve and concartinate all text in the HTML table o, ignoring all tag or hierachies. e,g, "<h1>hello <font> LiXizhi</font> !</h1>" will "return hello LiXizhi !" as a string. __syntax__ <verbatim>function HTMLRenderer.HTMLGetAllTextInTable(o)</verbatim> __parameters__ | *o* | | ---++++ !HTMLRenderer.NewStyle private: create a new copy of style object. * _param_ __baseStyle__ : nil or a table containing styles. * _param_ __cssStyle__ : nil or a string of css style, such as "color = #006699;" * _return_ ____ : The new style returned will copy all attribute of baseStyle and overriding it by cssStyle __syntax__ <verbatim>function HTMLRenderer.NewStyle(baseStyle, cssStyle)</verbatim> __parameters__ | *baseStyle* | nil or a table containing styles. | | *cssStyle* | | | *return* | The new style returned will copy all attribute of baseStyle and overriding it by cssStyle | ---++++ !HTMLRenderer.OnClose close the given control __syntax__ <verbatim>function HTMLRenderer.OnClose(sCtrlName)</verbatim> __parameters__ | *sCtrlName* | | ---++++ !HTMLRenderer.OnClickHRefNode when user clicked an href node. possibly open with an external browser. __syntax__ <verbatim>function HTMLRenderer.OnClickHRefNode(sCtrlName, href)</verbatim> __parameters__ | *sCtrlName* | | | *href* | | ---++++ !HTMLRenderer.DrawHTMLNodeHandler default node renderer: it display a clickable check box for expandable node, followed by node text __syntax__ <verbatim>function HTMLRenderer.DrawHTMLNodeHandler(_parent,treeNode)</verbatim> __parameters__ | *parent* | | | *treeNode* | | %STOPINCLUDE%
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2008-02-29
-
LiXizhi
Home
Site map
CCWeb web
HaqiTeen web
Main web
ParaEngine web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
导航页WebTopMenu
Preferences
开发指南
Getting Started
ParacraftSDK
NPL
MCML
NPL Reference Manual
美术Mod
Account
Log In
English
简体中文
簡體中文
E
dit
A
ttach
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback