bool InitUILabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize)
{
// 检查标签指针是否为空
- label = new UILabel();
if (label == nullptr)
{
+ label = new UILabel();
+ if (label == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitUILabel is error");
+ return false; // 内存分配失败,返回false
+ }
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitUILabel is not nullptr");
return false; // 内存分配失败,返回false
}
// 设置标签的位置和大小
bool InitLabel(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize)
{
// 检查标签指针是否为空
-
- label = new UILabelExt();
if (label == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabel is error");
+ label = new UILabelExt();
+ if (label == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabel is error");
+ return false; // 内存分配失败,返回false
+ }
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabel is not nullptr");
return false; // 内存分配失败,返回false
}
// 设置标签的位置和大小
bool InitLabelAdapt(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize)
{
// 检查标签指针是否为空
- label = new UILabelExt();
if (label == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelAdapt is error");
+ label = new UILabelExt();
+ if (label == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelAdapt is error");
+ return false; // 内存分配失败,返回false
+ }
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelAdapt is not nullptr");
return false; // 内存分配失败,返回false
}
// 设置标签的位置和大小
bool InitLabelExt(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, UIResourceTextId id, const char *fontName, int fontSize)
{
// 检查标签指针是否为空
- label = new UILabelExt();
if (label == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelExt is error");
+ label = new UILabelExt();
+ if (label == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelExt is error");
+ return false; // 内存分配失败,返回false
+ }
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelExt is not nullptr");
return false; // 内存分配失败,返回false
}
// 设置标签的位置和大小
return false; // 内存分配失败,返回false
}
}
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UILabelButtonExt UILabelButtonExt is not nullptr");
+ return false; // 内存分配失败,返回false
+ }
button->SetPosition(left, top);
button->Resize(width, height);
button->SetViewId(viewId);
{
if (label == nullptr)
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateLabelText label is nullptr");
return nullptr;
}
/*取Id对应的字符串*/
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label is error");
return nullptr;
}
-
std::string str = UpdateLabelText(label, std::to_string(num), id);
return str;
}
{
if (label == nullptr)
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label is error");
return;
}
bool InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId)
{
// 创建新按钮(如果当前按钮为空)
- button = new UIButton();
if (button == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new UIButton fail");
+ button = new UIButton();
+ if (button == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new UIButton fail");
+ return false; // 内存分配失败,返回false
+ }
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButton is not nullptr");
return false; // 内存分配失败,返回false
}
button->SetPosition(left, top);
*/
bool InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath)
{
- imageView = new UIImageView();
+ // 创建新图片(如果当前图片为空)
if (imageView == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "imagePath %s fail", imagePath);
- return false;
+ imageView = new UIImageView();
+ if (imageView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "imagePath %s fail", imagePath);
+ return false;
+ }
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitImageView is not nullptr");
+ return false; // 内存分配失败,返回false
}
if (imagePath == nullptr)
{