Skip to content

NPanel

NPanel组件本身没有特定的功能,它作为UI容器的角色非常重要。NPanel可以用于组织和管理其他UI元素,使你能够构建复杂的界面布局。它广泛应用于 菜单、对话框、动态界面 和UI结构的实现中。

接口名称返回值接口含义
SetTexturevoid设置纹理
GetTextureNTexturePtr获取纹理对象
GetImageFileNamestd::string获取图片的文件路径
LoadFromMemoryDatavoid通过内存数据进行纹理加载
SetColorvoid设置颜色
GetColorColor32获取颜色
SetAlphavoid设置透明度
GetAlphafloat获取透明度

设置和获取纹理

接口:
void SetTexture(NTexturePtr texture);
Void SetTexture(const std::string& fileName, bool bAsync = true, std::function<void()> callback = nullptr);
NTexturePtr GetTexture() const;
std::string GetImageFileName() const;
void LoadFromMemoryData(const std::string textureName, ETextureSuffix suffix, NResourceMemoryDataPtr memoryData);

参数:

参数说明
texture纹理共享指针
fileName纹理资源路径
textureName纹理命名
suffix图片类型后缀
memoryData内存数据指针
描述:
以上接口和NImageView功能一致,因为NPanel底层实现就是NImageView。

代码示例: 请查看NImageView接口示例。

设置和获取颜色以及透明度

接口:
void SetColor(Color32 color);
Color32 GetColor() const;
void SetAlpha(float alpha);
float GetAlpha();

参数:

参数说明
color设置的颜色值
alpha设置的透明度值
描述:
通过上面接口可以修改图片混合的颜色,也可以设置图片显示的透明度,来达到一些渲染效果。

代码示例: 请查看NImageView接口示例。