You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
自定义组件的思路:
根据MiniGUI绘制图片/文字/矩形的方法,可以将图片,文字以及透明框的矩形放到一个panelPiece中。通过调整不同piece的相对位置可以组合为类似安卓toast的组件效果。
但是需要注意的是,toast的出现与消失是异步的(用户或场景决定什么时机出现)。那么如何在基于MiniGUI的cell-ux-demo中实现呢?我的思路就是利用了MiniGUI中的PostMessage方法,即当触发绘制组件时延时一段时间再删除对应组件。具体代码为:
`#define MSG_REFRESH_UI 100054
#define FONT_SIZE 50
#define TOAST_LENGTH_LONG 5
#define TOAST_LENGTH_SHORT 3
#define TOAST_BORDER_RADIUS 20
#define TOAST_RECT_BORDERSIZE 6
#define TOAST_RECT_BORDER_COLOR_R 0xff
#define TOAST_RECT_BORDER_COLOR_G 0x00
#define TOAST_RECT_BORDER_COLOR_B 0x00
#define TOAST_RECT_BORDER_COLOR_A 0x65
#define TOAST_RECT_COLOR_R 0xff
#define TOAST_RECT_COLOR_G 0x00
#define TOAST_RECT_COLOR_B 0x00
#define TOAST_RECT_COLOR_A 0x02
typedef struct _GradientData {
float pos;
ARGB color;
} GradientData;
static const GradientData infobox1_gradient[] = {
{0.00f, 0xff000000,},
{1.00f, 0xff000000,},
};
void MakeToast::postRefreshUIMessage(mWidget *self) {
sleep(TOAST_LENGTH_SHORT);
if (ToastManager::getInstance()->threadStatus == ToastManager::getInstance()->THREAD_STOP) {
LOGD(LOG_AR_MEDIA, "stop postMessage thread success!");
return;
}
PostMessage(self->hwnd, MSG_REFRESH_UI, (WPARAM) self, 0);
}
void MakeToast::onRefreshUI(mWidget *self, int message, WPARAM wparam, LPARAM lparam) {
ToastManager::getInstance()->deletePieceCache(self);
}
MakeToast *MakeToast::MakeToast = NULL;
MakeToast *MakeToast::getInstance() {
if (MakeToast == NULL) {
MakeToast = new MakeToast();
}
return MakeToast;
}
void MakeToast::destroyInstance() {
if (MakeToast) {
delete MakeToast;
MakeToast = nullptr;
}
}`
`void MakeToast::showToast(int width, int height, char *imgPath, DWORD str, DWORD color, mWidget *actWidget) {
}
`
其中消失的逻辑为:
void MakeToast::onRefreshUI(mWidget *self, int message, WPARAM wparam, LPARAM lparam) { ToastManager::getInstance()->deletePieceCache(self); }
void ToastManager::deletePieceCache(mWidget *self) { _c(panelPiece)->delContent(panelPiece, imagePiece); _c(panelPiece)->delContent(panelPiece, textPiece); _c(panelPiece)->delContent(panelPiece, rectPiece); PanelPiece_invalidatePiece((mHotPiece *) panelPiece, nullptr); InvalidateRect(self->hwnd, NULL, TRUE); DestroyLogFont(mTextFont); }
当然我们需要事先把绘制的panelpiece在activity中注册到数据类:ToastManager中。
经过测试以上逻辑在容器背景不透明时是没问题的。但是如果将activity中的container的背景设置为WS_EX_TRANSPARENT则组件消失失败,经排查日志发现所有流程均和非透明时一致,尝试刷新window或者其他方法都不能解决问题,想请问广大的开发者们对这一问题有什么看法与解决办法吗?该场景比较好复现。
static NCS_WND_TEMPLATE _ctrl_tmpl[] = { {NCSCTRL_CONTAINERCTRL, IDC_CONTAINER, ACTIVITY_X, ACTIVITY_Y, ACTIVITY_W, ACTIVITY_H, WS_VISIBLE, WS_EX_TRANSPARENT, "Container", NULL, NULL, NULL, NULL, 0, 0}, };
值得注意的是:
如果按照上述代码添加一个完全不透明的背景(mShapeTransRoundPiece),那么自定义组件会消失,但是组件消失后会留下背景色,并且这时立即删除背景,界面上还会存在背景颜色。我怀疑是背景再刷新时遮盖了toast组件。
Beta Was this translation helpful? Give feedback.
All reactions