From 73188765f5eaa79e20ae34affef8e335322f6af0 Mon Sep 17 00:00:00 2001 From: oc Date: Tue, 20 Feb 2018 23:51:17 +0800 Subject: [PATCH] Bold in SetText --- docs/event.md | 6 ++++-- libs/core.js | 1 + libs/events.js | 3 +++ libs/ui.js | 6 ++++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/event.md b/docs/event.md index a821cebc..b2482c59 100644 --- a/docs/event.md +++ b/docs/event.md @@ -267,8 +267,8 @@ ``` js "x,y": [ // 实际执行的事件列表 - {"type": "setText", "position": "up", "title": [255,0,0], "text": [255,255,0], "background": [0,0,255,0.3]}, - "这段话将显示在上方,标题为红色,正文为黄色,背景为透明度0.3的蓝色" + {"type": "setText", "position": "up", "title": [255,0,0], "text": [255,255,0], "background": [0,0,255,0.3], "bold": true}, + "这段话将显示在上方,标题为红色,正文为黄色粗体,背景为透明度0.3的蓝色" ] ``` @@ -280,6 +280,8 @@ text为可选项,如果设置则为一个RGB三元组或RGBA四元组,表示 background为可选项,如果设置则为一个RGB三元组或RGBA四元组,表示背景色。 +bold为可选项,如果设置则为true或false,表示正文是否使用粗体。 + ### tip:显示一段提示文字 `{"type": "tip"}`可以在左上角显示一段提示文字。 diff --git a/libs/core.js b/libs/core.js index 0569d823..1e3d6457 100644 --- a/libs/core.js +++ b/libs/core.js @@ -130,6 +130,7 @@ function core() { "title": [255,215,0,1], "background": [0,0,0,0.85], "text": [255,255,255,1], + "bold": false, }, 'curtainColor': null, 'usingCenterFly':false, diff --git a/libs/events.js b/libs/events.js index fdb43ac8..e0ed7b83 100644 --- a/libs/events.js +++ b/libs/events.js @@ -313,6 +313,9 @@ events.prototype.doAction = function() { core.status.textAttribute[t]=data[t]; } }) + if (core.isset(data.bold)) { + core.status.textAttribute.bold=data.bold; + } core.events.doAction(); break; case "tip": diff --git a/libs/ui.js b/libs/ui.js index 5ac798bc..34aafaf4 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -120,7 +120,9 @@ ui.prototype.drawTextBox = function(content) { if (id=='hero' || core.isset(icon)) content_left=left+63; var validWidth = right-(content_left-left)-13; - var contents = core.splitLines("ui", content, validWidth, '16px Verdana'); + var font = '16px Verdana'; + if (textAttribute.bold) font = "bold "+font; + var contents = core.splitLines("ui", content, validWidth, font); var height = 20 + 21*(contents.length+1) + (id=='hero'?core.material.icons.hero.height-10:core.isset(name)?32-10:0); @@ -229,7 +231,7 @@ ui.prototype.drawTextBox = function(content) { core.setFillStyle('ui', core.arrayToRGB(textAttribute.text)); for (var i=0;i