検索
ホームページウェブフロントエンドhtmlチュートリアル[Hanjiang Guye の Cocos2d-x Journey_33]RichTextEx は、HTML タグを通じてテキスト スタイルを制御するリッチ テキスト コントロールです_html/css_WEB-ITnose

RichTextEx は、HTML タグを通じてテキスト スタイルを制御するリッチ テキスト コントロールです

ブログ アドレス:

ダウンロード アドレス

Github リンク

これは何をしますか

次のテキスト コンテンツを変更します
"【世】Hanjiang Guye:HelloWorld"
画像に示されているスタイルでリッチテキストを生成します ( 画像とフラッシュをサポート、回転やその他のカスタマイズされたエフェクトとコントロール)

それについて

これは LUA バージョンです。CPP バージョンはまだ書かれていません。CPP バージョンと JS バージョンの移植を歓迎します
LUA ファイルは、によって書かれたファイルで変更されています。他の誰か (いくつかの機能を追加し、いくつかのバグを修正してください...前に実行できません、親愛なる...一体どういうことですか)
また、申し訳ありませんが、彼の Github リンクが見つかりません...
· TTF フォントストロークをサポートするシステムです フォントはサポートされていません

手順

RichTextEx の使い方は非常に簡単です。RichTextEx.lua をプロジェクト ディレクトリにコピーして必要とするだけです
例:

APUtils = APUtils or {}  APUtils.RichTextEx = APUtils.RichTextEx or require("APUtils/gui/RichTextEx.lua")

RichText を使用してリッチ テキストを作成します非常に単純です:

local txt = RichTextEx:create() -- 或 RichTextEx:create(26, cc.c3b(10, 10, 10))txt:setText("<outline><underline true><font res>您的元宝和银券不足请充值,或领取抽取元宝奖励!")-- 多行模式要同时设置 ignoreContentAdaptWithSize(false) 和 contentSizetxt:setMultiLineMode(true)  -- 这行其实就是 ignoreContentAdaptWithSize(false)txt:setContentSize(200, 400)someNode:addChild(txt)</font></underline></outline>

文字列がユーザーによって入力された場合は、RichTextEx.htmlEncode("") を呼び出してユーザー入力コンテンツをエンコードし、ユーザーによるキー文字の入力によって引き起こされる予期せぬエラーを回避することをお勧めします
RichTextEx.htmlDecode は、文字列を生成する前に自動的に呼び出されます。テキスト コンテンツを表示するためにコントロールをカスタマイズした場合は、必ずそれを呼び出して文字列をデコードしてください

RichTextEx の基本オプション

 =   = 文字颜色                = 字体大小<font arial>        = 文字字体 支持TTF<img  filename alt="[Hanjiang Guye の Cocos2d-x Journey_33]RichTextEx は、HTML タグを通じてテキスト スタイルを制御するリッチ テキスト コントロールです_html/css_WEB-ITnose" >      = 图片(filename 可以是已经在 SpriteFrameCache 里的 key,或磁盘文件)<img _32 fname alt="[Hanjiang Guye の Cocos2d-x Journey_33]RichTextEx は、HTML タグを通じてテキスト スタイルを制御するリッチ テキスト コントロールです_html/css_WEB-ITnose" >   = 指定大小的图片   2> = 当前字体大小 +-*/                 = 颜色、字体和字体大小恢复默认\n \t               = 换行 和 tab,可能暂时实现得不是很好 最好不要用 如果需要换行你可以创建多个RichText然后依次放好<outline>         = 设置1像素描边,只支持TTF字体<underline true>    = 是否开启下划线</underline></outline></img_32></font>

RichTextEx の例のオプション (で提供されています)。 RichTextEx.defaultCb)

<blink>      = (动画)闪烁那些文字<rotate>     = (动画)旋转那些文字<scale>      = (动画)缩放那些文字(但如果你做了 setText(t, callback) 除非你在 callback 主动调用 defaultCb,否则以上选项会被忽略)   </scale></rotate></blink>

関数を拡張できます

`<img _w http: alt="[Hanjiang Guye の Cocos2d-x Journey_33]RichTextEx は、HTML タグを通じてテキスト スタイルを制御するリッチ テキスト コントロールです_html/css_WEB-ITnose" > 例如从网络下载图片`</img_w>

カスタムの特別な構文もサポートしています。

txt:setText("XXXXX <aaaa haha> <bbbb> <cccc> xxx", function(text, sender) -- 第二个参数 sender 可选    -- 对每一个自定义的  都会调用此 callback    -- text 就等于 *** (不含)    -- 简单的返回一个 Node 的子实例就可,如    -- 如果接收第二个参数 sender,就可获取当前文字大小、颜色: sender._fontSize、sender._textColor    if string.sub(text, 1, 4) == "aaaa" then        return ccui.Text:create("aaa111" .. string.sub(text, 6)), "", 32)        --这里如果为了代码的健壮性最好加入self:htmlDecode        --return ccui.Text:create(self:htmlDecode("aaa111" .. string.sub(text, 6))), "", 32)    elseif text == "bbbb" then        -- 用当前文字大小和颜色        local lbl = ccui.Text:create("bbb111", "", sender._fontSize)        lbl:setTextColor(sender._textColor)        return lbl    elseif string.sub(text, 1, 4) == "CCCC" then        local img = ccui.ImageView:create(....)        img:setScale(...)        img:runAction(...)        return img    endend)</cccc></bbbb></aaaa>
などのコールバックを追加するだけです

他に何をしたいですか

トレースをサポートするには、エッジと下線、Cocos のソース コードも変更する必要があります
UIRichText.h と UIRichText.cpp は、元のものを置き換えるためにプロジェクトのソース コード ディレクトリに配置されます
パス: Frameworks/cocos2d-x/cocos/ui
(メイン変更は 3 つの側面で行われます: アンダースコアの追加設定、ストローク設定の追加、リッチテキストは高さを自動的に変更できます)
さらに、toLua ファイルを変更する必要があります
Frameworks/cocos2d-x/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto .cpp
18878 行目あたりに 2 つの関数があります
int lua_cocos2dx_ui_RichElementText_init(lua_State* tolua_S)

int lua_cocos2dx_ui_RichElementText_create(lua_State* tolua_S)
これら 2 つの関数の実装を次のように置き換えます次の形式:

int lua_cocos2dx_ui_RichElementText_init(lua_State* tolua_S){    int argc = 0;    cocos2d::ui::RichElementText* cobj = nullptr;    bool ok  = true;#if COCOS2D_DEBUG >= 1    tolua_Error tolua_err;#endif#if COCOS2D_DEBUG >= 1    if (!tolua_isusertype(tolua_S,1,"ccui.RichElementText",0,&tolua_err)) goto tolua_lerror;#endif    cobj = (cocos2d::ui::RichElementText*)tolua_tousertype(tolua_S,1,0);#if COCOS2D_DEBUG >= 1    if (!cobj)     {        tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_RichElementText_init'", nullptr);        return 0;    }#endif    argc = lua_gettop(tolua_S)-1;    if (argc == 8)    {        int arg0;        cocos2d::Color3B arg1;        uint16_t arg2;        std::string arg3;        std::string arg4;        double arg5;        int arg6;        bool arg7;        ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ccui.RichElementText:init");        ok &= luaval_to_color3b(tolua_S, 3, &arg1, "ccui.RichElementText:init");        ok &= luaval_to_uint16(tolua_S, 4,&arg2, "ccui.RichElementText:init");        ok &= luaval_to_std_string(tolua_S, 5,&arg3, "ccui.RichElementText:init");        ok &= luaval_to_std_string(tolua_S, 6,&arg4, "ccui.RichElementText:init");        ok &= luaval_to_number(tolua_S, 7,&arg5, "ccui.RichElementText:init");        ok &= luaval_to_int32(tolua_S, 8,&arg6, "ccui.RichElementText:init");        ok &= luaval_to_boolean(tolua_S, 9,&arg7, "ccui.RichElementText:init");        if(!ok)        {            tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_RichElementText_init'", nullptr);            return 0;        }        bool ret = cobj->init(arg0, arg1, arg2, arg3, arg4, arg5,arg6,arg7);        tolua_pushboolean(tolua_S,(bool)ret);        return 1;    }    luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.RichElementText:init",argc, 6);    return 0;#if COCOS2D_DEBUG >= 1    tolua_lerror:    tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_RichElementText_init'.",&tolua_err);#endif    return 0;}int lua_cocos2dx_ui_RichElementText_create(lua_State* tolua_S){    int argc = 0;    bool ok  = true;#if COCOS2D_DEBUG >= 1    tolua_Error tolua_err;#endif#if COCOS2D_DEBUG >= 1    if (!tolua_isusertable(tolua_S,1,"ccui.RichElementText",0,&tolua_err)) goto tolua_lerror;#endif    argc = lua_gettop(tolua_S) - 1;    if (argc == 6)    {        int arg0;        cocos2d::Color3B arg1;        uint16_t arg2;        std::string arg3;        std::string arg4;        double arg5;        ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ccui.RichElementText:create");        ok &= luaval_to_color3b(tolua_S, 3, &arg1, "ccui.RichElementText:create");        ok &= luaval_to_uint16(tolua_S, 4,&arg2, "ccui.RichElementText:create");        ok &= luaval_to_std_string(tolua_S, 5,&arg3, "ccui.RichElementText:create");        ok &= luaval_to_std_string(tolua_S, 6,&arg4, "ccui.RichElementText:create");        ok &= luaval_to_number(tolua_S, 7,&arg5, "ccui.RichElementText:create");        if(!ok)        {            tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_RichElementText_create'", nullptr);            return 0;        }        cocos2d::ui::RichElementText* ret = cocos2d::ui::RichElementText::create(arg0, arg1, arg2, arg3, arg4, arg5);        object_to_luaval<:ui::richelementtext>(tolua_S, "ccui.RichElementText",(cocos2d::ui::RichElementText*)ret);        return 1;    }    if (argc == 7)    {        int arg0;        cocos2d::Color3B arg1;        uint16_t arg2;        std::string arg3;        std::string arg4;        double arg5;        int arg6;        ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ccui.RichElementText:create");        ok &= luaval_to_color3b(tolua_S, 3, &arg1, "ccui.RichElementText:create");        ok &= luaval_to_uint16(tolua_S, 4,&arg2, "ccui.RichElementText:create");        ok &= luaval_to_std_string(tolua_S, 5,&arg3, "ccui.RichElementText:create");        ok &= luaval_to_std_string(tolua_S, 6,&arg4, "ccui.RichElementText:create");        ok &= luaval_to_number(tolua_S, 7,&arg5, "ccui.RichElementText:create");        ok &= luaval_to_int32(tolua_S, 8,&arg6, "ccui.RichElementText:create");        if(!ok)        {            tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_RichElementText_create'", nullptr);            return 0;        }        cocos2d::ui::RichElementText* ret = cocos2d::ui::RichElementText::create(arg0, arg1, arg2, arg3, arg4, arg5, arg6);        object_to_luaval<:ui::richelementtext>(tolua_S, "ccui.RichElementText",(cocos2d::ui::RichElementText*)ret);        return 1;    }    if (argc == 8)    {        int arg0;        cocos2d::Color3B arg1;        uint16_t arg2;        std::string arg3;        std::string arg4;        double arg5;        int arg6;        bool arg7;        ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ccui.RichElementText:create");        ok &= luaval_to_color3b(tolua_S, 3, &arg1, "ccui.RichElementText:create");        ok &= luaval_to_uint16(tolua_S, 4,&arg2, "ccui.RichElementText:create");        ok &= luaval_to_std_string(tolua_S, 5,&arg3, "ccui.RichElementText:create");        ok &= luaval_to_std_string(tolua_S, 6,&arg4, "ccui.RichElementText:create");        ok &= luaval_to_number(tolua_S, 7,&arg5, "ccui.RichElementText:create");        ok &= luaval_to_int32(tolua_S, 8,&arg6, "ccui.RichElementText:create");        ok &= luaval_to_boolean(tolua_S, 9,&arg7, "ccui.RichElementText:create");        if(!ok)        {            tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_RichElementText_create'", nullptr);            return 0;        }        cocos2d::ui::RichElementText* ret = cocos2d::ui::RichElementText::create(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);        object_to_luaval<:ui::richelementtext>(tolua_S, "ccui.RichElementText",(cocos2d::ui::RichElementText*)ret);        return 1;    }    luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccui.RichElementText:create",argc, 6);    return 0;#if COCOS2D_DEBUG >= 1    tolua_lerror:    tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_RichElementText_create'.",&tolua_err);#endif    return 0;}  </:ui::richelementtext></:ui::richelementtext></:ui::richelementtext>

プロジェクトを再コンパイルし、次にプロジェクトで使用できます

次のバージョンで更新される内容

1. タブと改行のサポートを改善するために、引き続き Cocos2d-x の RichText のソース コードを変更します
2. クリック可能なテキストを追加し、クリック後の色を変更します
3. システムフォントのストロークを追加する(システムフォントと判定された場合、ストロークを影に置き換えます)

その他

下線の実装が非常に不器用なので、もっと良い方法があれば教えて下さい。
Cocos2d-x ソース コードの変更を必要としないバージョンが必要かもしれません (このバージョン はストロークと下線をサポートしていません)
QQ: 446569365

への連絡を歓迎します。

著作権声明: この記事はブロガーによるオリジナル記事、ブロガーの許可なく転載を禁じます。 🎜
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
Lang属性をタグにどのように設定しますか?なぜこれが重要なのですか?Lang属性をタグにどのように設定しますか?なぜこれが重要なのですか?May 08, 2025 am 12:03 AM

タグのLang属性を設定することは、WebアクセシビリティとSEOを最適化する重要なステップです。 1)ラング属性をタグに設定します。 2)多言語コンテンツでは、ようなさまざまな言語パーツのLang属性を設定します。 3)「EN」、「FR」、「ZH」などのISO639-1標準に準拠する言語コードを使用します。Lang属性を正しく設定すると、Webページと検索エンジンランキングのアクセシビリティが向上します。

HTML属性の目的は何ですか?HTML属性の目的は何ですか?May 07, 2025 am 12:01 AM

htmlattributeSareSientionalentionalentionalentionalentiallyance'functionalityandappearance.theyaddinformationtodefinebehavior、light、and interaction、makewebsitesteractive、responsive、andviseallyappaleal.attributeslikesrc、href、class、型、およびdoadabledransform

HTMLでリストを作成するにはどうすればよいですか?HTMLでリストを作成するにはどうすればよいですか?May 06, 2025 am 12:01 AM

toreatealistinhtml、useforunorderedlistsandfororderedlists:1)forunorderedlists、wrapitemsinanduseforeachitem、renderingasabulletedlist.2)

HTMLアクション:Webサイト構造の例HTMLアクション:Webサイト構造の例May 05, 2025 am 12:03 AM

HTMLは、明確な構造のWebサイトを構築するために使用されます。 1)Webサイト構造などのタグを使用し、定義します。 2)例は、ブログとeコマースのウェブサイトの構造を示しています。 3)誤ったラベルネスティングなどの一般的な間違いを避けてください。 4)HTTP要求を削減し、セマンティックタグを使用してパフォーマンスを最適化します。

HTMLページに画像を挿入するにはどうすればよいですか?HTMLページに画像を挿入するにはどうすればよいですか?May 04, 2025 am 12:02 AM

to inertanimageintoanhtmlpage、usethetagwithsrcandaltattributes.1)usealttextforaccessibilityandseo.2)emplencesrcsetForresponsiveimages.3)applylazyloadingwithloading = "lazy" tooptimizeperformance.4)

HTMLの目的:Webブラウザがコンテンツを表示できるようにするHTMLの目的:Webブラウザがコンテンツを表示できるようにするMay 03, 2025 am 12:03 AM

HTMLの中心的な目的は、ブラウザがWebコンテンツを理解して表示できるようにすることです。 1。HTMLは、タグなどのタグを介してWebページの構造とコンテンツを定義します。 3.HTMLは、ユーザーの相互作用をサポートするフォーム要素を提供します。 4. HTMLコードの最適化は、HTTP要求の削減やHTMLの圧縮など、Webページのパフォーマンスを改善できます。

Web開発にとってHTMLタグが重要なのはなぜですか?Web開発にとってHTMLタグが重要なのはなぜですか?May 02, 2025 am 12:03 AM

htmltagsareSterenceforwebdevelovementasyStheStructureanhandhancewebpages.1)theydefineLayout、semantics、and-interactivity.2)semanticagsimprovecessibility.3)opeusofusofagscanoptimizeperformanceandensurecross-brows-compativeation。

HTMLタグと属性に一貫したコーディングスタイルを使用することの重要性を説明します。HTMLタグと属性に一貫したコーディングスタイルを使用することの重要性を説明します。May 01, 2025 am 12:01 AM

コードの読みやすさ、保守性、効率を向上させるため、一貫したHTMLエンコーディングスタイルは重要です。 1)低ケースタグと属性を使用します。2)一貫したインデントを保持し、3)シングルまたはダブルの引用符を選択して固執する、4)プロジェクトのさまざまなスタイルの混合を避け、5)きれいなスタイルやEslintなどの自動化ツールを使用して、スタイルの一貫性を確保します。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

SublimeText3 Linux 新バージョン

SublimeText3 Linux 新バージョン

SublimeText3 Linux 最新バージョン

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。