12. 编辑器界面定制
编辑器UI界面¶
VRP编辑器UI界面中可进行对字体、背景、Logo与各个组件的颜色、大小、透明度及渐变等样式进行修改。
一、整体JS代码框架¶
程序界面整体采用MVC架构:
-
程序界面入口:/GUI/index.html文件
-
视图层文件:/GUI/editor/window/*.js
-
控制器文件:/GUI/controller/*.js
具体呈像如下图:
二、UI组件库¶
程序的UI组件库采用zebkit.js库,源码放置在/GUI/thirdparty/zebkit/中。同时,程序也对zebkit组件库进行了封装,为/GUI/common/VrpUIComponent.js文件,此文件中包括对基础的UI组件(按钮、输入框、图片容器、文本、折叠栏、多选框、列表等UI组件)的参数及函数进行了初始化定义。
如下按钮组件代码参数及函数说明:
- 原生按钮
/** * @event fired * @param {zebkit.ui.Button} src a button that has been pressed * */ pkg.Button = Class(pkg.EvStatePan, pkg.DrawFocusMarker, pkg.FireEventRepeatedly, [ function(t) { this.$super(); if (arguments.length > 0 && t !== null) { t = pkg.$component(t, this); this.add(t); this.setFocusAnchorComponent(t); } }, function $clazz() { this.Label = Class(pkg.Label, []); this.ViewPan = Class(pkg.ViewPan, [ function(v) { this.$super(); this.setView(v); }, function $prototype() { this.setState = function(id) { if (this.view !== null && this.view.activate !== undefined) { this.activate(id); } }; } ]); this.ImageLabel = Class(pkg.ImageLabel, []); }, function $prototype() { /** * Indicates the component can have focus * @attribute canHaveFocus * @type {Boolean} * @default true */ this.canHaveFocus = true; this.catchInput = true; } ]).events("fired");
- 封装按钮:
//Button //text参数设置按钮的初始文本|bd设置按钮边框是否为0,默认值为fasle|border参数设置边框的颜色|background设置按钮的背景颜色 createButton(text, bd = false, border = Theme.EditorUIStyle.borderColor, background = Theme.EditorUIStyle.btnBackground) { //zebkit.ui.Button语句调用zebkit.js的按钮组件 const button = new zebkit.ui.Button(text).setBackground("rgba(0,0,0,0.0)"); if(bd){ button.setBackground(background).setBorder(new zebkit.draw.Border(border, 1, 0)); button.pointerEntered = function () { this.setBackground(Theme.EditorUIStyle.backgroundThree).setBorder(new zebkit.draw.Border(Theme.EditorUIStyle.SelectWireFrame, 1, 0));} button.pointerExited = function () { this.setBackground(background).setBorder(new zebkit.draw.Border(border, 1, 0));} }else{ if(border != Theme.EditorUIStyle.borderColor){ button.setBorder(new zebkit.draw.Border(border, 1, 0)); } if(background != Theme.EditorUIStyle.btnBackground){ button.setBackground(background); } } return button; }
三、字体、背景、Logo与各个组件对应解决方案¶
Theme.js(位置为/data/GUI/Theme.js)文件通过读取各个主题的Json文件为程序配置主体风格。各个主题的Json文件包括字体变量配置文件、UI组件配置文件,位置分别位于/data/GUI/thirdparty/json/..、/data/GUI/thirdparty/zebkit/rs/themes/..中。
1.字体|背景 Theme.js文件中读取字体颜色和大小数据到Theme.EditorUIStyle对象中,通过该对象读取数据下各个颜色控制变量来实现对界面字体的大小及颜色进行配置。如图所示:
2.Logo 关于界面中的图片来源,图片存储在/data/GUI/eidtor/images/..中,如需修改文件,可通过界面悬浮提示找到相对应名字的图片源,然后对其进行替换。如图所示:
3.组件 界面包含图片按钮、多选框、复选框、选项卡、搜索框、折叠栏、列表、树等UI结构。如需对其样式进行配置,可通过/data/GUI/thirdparty/zebkit/rs/themes/..下的json配置文件进行修改或者对组件库进行配置。如图所示:
四、示例案例¶
以白色主题为背景:
1.对界面主题字体颜色进行配置 目前为颜色值为“#111111”,目标将颜色配置为粉色(颜色值可为当前的三种格式),则步骤如下:
1)打开/data/GUI/thirdparty/json/JSONVRPWhite/config.json文件,找到fontColorMain变量;
2)修改fontColorMain变量值为“pink”;
3)步骤示意与效果如下图:
2.对界面主背景进行配置
目前背景颜色值为“#FEFEFE”,目标将背景颜色配置为黄蓝色,则步骤如下:
1)打开/data/GUI/thirdparty/json/JSONVRPWhite/config.json文件,找到backgroundMain变量;
2)修改backgroundMain变量值为“yellow”;
3)步骤示意与效果如下图:
3.对用户头像进行配置
步骤如下:
1)打开/data/GUI/editor/images/window/EditorWindow.js文件,找到avatarImage变量,目前图片源路径为“eidtor/images/material/avatar-light.svg”;
2)根据路径找到相对应的图片进行更替(文件名要为avatar-light,格式为.svg格式,其他名字和格式均可但需跟变量值相对应);
3)步骤示意与效果如下图:
4.对菜单栏子列表组件字体颜色进行配置
步骤如下:
1)打开/data/GUI/thirdparty/zebkit/rs/themes/VRPWhite/ui.json与ui.custom.config.json文件,找到MenuItem对象与MenuItem_Config对象;
2)修改MenuItem_Config下各个样式的值;
3)步骤示意与效果如下图: