--[[ desc: STRING, a lib that encapsulate string function. author: Musoucrow since: 2018-8-13 alter: 2018-12-31 ]]-- local _UTF8 = require("utf8") local _CONFIG = require("config") ---@class Lib.STRING local _STRING = { colorMap = { w = {255, 255, 255, 255}, --white W = {255, 255, 230, 255}, B = {0, 0, 0, 0}, --black r = {255, 100, 100, 255}, --red R = {255, 0, 0, 255}, g = {180, 255, 180, 255}, --green b = {200, 255, 255, 255}, --blue y = {255, 255, 180, 255}, --yellow o = {255, 200, 55, 255}, --orange p = {255, 150, 255, 255}, --pink P = {255, 50, 255, 255}, --purple G = {192, 192, 192, 255}, --grey D = {233, 218, 195, 255} --dialog } } ---@param map table ---@return string function _STRING.GetVersion(map) if (map == nil) then return "" elseif (type(map) == "string") then return map end return map[_CONFIG.setting.language] end ---@param content string ---@return table | string function _STRING.Colorize(content) if (type(content) == "table" or not string.find(content, "|")) then return content end local list = _STRING.Split(content, "|") local ret = {} for n=1, #list do if (#list[n] > 1) then local color = n == 1 and _STRING.colorMap.w or _STRING.colorMap[string.sub(list[n], 1, 1)] local text = n == 1 and list[n] or string.sub(list[n], 2) table.insert(ret, color) table.insert(ret, text) end end return ret end
时间: 2024-04-22 14:26:35 浏览: 14
这段代码定义了一个名为 `_STRING` 的字符串库,用于封装字符串相关的函数。
该库包含以下属性:
- `colorMap`:颜色映射表,用于将字符映射到对应的颜色值。
该库包含以下方法:
- `GetVersion(map)`:根据传入的语言映射表 `map`,返回对应语言的版本字符串。如果 `map` 为 `nil`,则返回空字符串;如果 `map` 是字符串类型,直接返回该字符串;否则,根据当前设置的语言返回对应的版本字符串。
- `Colorize(content)`:将文本内容 `content` 进行颜色标记。如果 `content` 是一个表格或不包含 `|` 字符,则直接返回 `content`;否则,将文本按 `|` 字符进行切割,并根据切割后的片段设置对应的颜色,并以表格形式返回。
通过这些方法,可以实现对字符串的一些操作,例如获取指定语言的版本字符串和对文本进行颜色标记。该库还可能依赖了其他模块(例如 `utf8` 和 `config`)来完成一些功能。
相关问题
bounds.Encapsulate
`bounds.Encapsulate` 是一个 Unity 引擎中的方法,用于将包围盒(Bounds)扩展以包含指定点。具体来说,它会将传入的点考虑进去,更新包围盒的最小和最大点,以确保该点也在包围盒内。
例如,如果我们有一个包围盒 `bounds`,并且想要将点 `point` 考虑进去,可以这样写:
```
bounds.Encapsulate(point);
```
这将更新 `bounds` 的最小和最大点,使其包含 `point`。这个方法通常用于计算一组点的包围盒,例如在进行物体的碰撞检测时,我们可以将所有顶点的位置考虑进去,得到该物体的包围盒,以便进行更高效的碰撞检测。
import QtQuick import QtQuick.Layouts import QtQuick.Controls ApplicationWindow{ id:appWindow visible: true width: 600 height: 400 menuBar: MenuBar{ id:appMenuBar Menu{ title: qsTr("&File") //RECOMMENDED Way: to encapsulate actions using MenuItem MenuItem{action: actions.openAction} MenuItem{action: actions.folderAction} MenuItem{action: actions.exitAction} } Menu{ title: qsTr("&View") //using Action object as menu item directly Action{ text:qsTr("&Full Screen") icon.name:"view-fullscreen" onTriggered: { content.fullScreen(); } } //sub menu Menu{ title: qsTr("ViewMode") MenuItem{action: actions.imageModePreserveAspectCropAction} MenuItem{action: actions.imageModePreserveAspectFitAction} MenuItem{action: actions.imageModeStretchAction} } } Menu { title: qsTr("&Help") //using Action object id as menu item contentData:[ actions.contentsAction, actions.aboutAction ] } } header: ToolBar { id:appToolBar RowLayout{ ToolButton{ action: actions.openAction } ToolButton{ action: actions.folderAction } } } //setting the logic of all actions Actions{ id:actions openAction.onTriggered: content.dialogs.openFileDialog() folderAction.onTriggered: content.dialogs.openFolderDialog() imageModePreserveAspectCropAction.onTriggered: content.setImageFillMode(Image.PreserveAspectCrop) imageModePreserveAspectFitAction.onTriggered: content.setImageFillMode(Image.PreserveAspectFit) imageModeStretchAction.onTriggered: content.setImageFillMode(Image.Stretch) aboutAction.onTriggered: content.dialogs.openAboutDialog() } //setting the logic of content Content{ id:content anchors.fill: parent onFullScreen: { menuBar.visible = false; header.visible = false; appWindow.showFullScreen(); isFullScreen = true; singleView(); } onWindow: { menuBar.visible = true header.visible = true appWindow.showNormal() isFullScreen=false; } } }
这段代码是一个QML文件,创建了一个应用程序窗口(ApplicationWindow),其中包含菜单栏(MenuBar)、工具栏(ToolBar)和内容(Content)。通过定义Actions元素,对菜单栏中的操作进行了逻辑设置。
其中,菜单栏中包含了文件、视图和帮助三个菜单,每个菜单中包含了多个操作(MenuItem或Action)。工具栏中包含了两个工具按钮(ToolButton),分别对应了文件操作和文件夹操作。
Content元素中通过定义onFullScreen和onWindow属性,实现了全屏和窗口模式下的界面切换,并在其中调用了Content元素中的方法singleView()。
需要注意的是,在使用这段代码时,需要将其放在合适的QML文件中,并将相关的依赖项进行导入。