MCPcopy Create free account
hub / github.com/defold/defold / LuaNewTextNode

Function LuaNewTextNode

engine/gui/src/gui_script.cpp:1720–1736  ·  view source on GitHub ↗

creates a new text node * Dynamically create a new text node. * * @name gui.new_text_node * @param pos [type:vector3|vector4] node position * @param text [type:string] node text * @return node [type:node] new text node */

Source from the content-addressed store, hash-verified

1718 * @return node [type:node] new text node
1719 */
1720 static int LuaNewTextNode(lua_State* L)
1721 {
1722 Point3 pos = GetPositionFromArgumentIndex(L, 1);
1723 const char* text = luaL_checkstring(L, 2);
1724 Scene* scene = GuiScriptInstance_Check(L);
1725 void* font = scene->m_DefaultFont;
1726 Vector3 size = Vector3(1,1,1);
1727 if (font != 0x0)
1728 {
1729 dmGui::TextMetrics metrics;
1730 scene->m_Context->m_GetTextMetricsCallback(font, text, 0.0f, false, 1, 0, &metrics);
1731 size.setX(metrics.m_Width);
1732 size.setY(metrics.m_MaxAscent + metrics.m_MaxDescent);
1733 }
1734
1735 return LuaDoNewNode(L, scene, pos, size, NODE_TYPE_TEXT, 0, text, font);
1736 }
1737
1738 /*# creates a new pie node
1739 * Dynamically create a new pie node.

Callers

nothing calls this directly

Calls 6

GuiScriptInstance_CheckFunction · 0.85
LuaDoNewNodeFunction · 0.85
Vector3Class · 0.50
setXMethod · 0.45
setYMethod · 0.45

Tested by

no test coverage detected