balloon: fix leave tracking + multi-line height in wl_balloon_draw
This commit is contained in:
parent
adf79141b2
commit
784b4c89ce
|
|
@ -204,9 +204,15 @@ void W_BalloonHandleEnterView(WMView * view)
|
|||
if (!bPtr->flags.enabled)
|
||||
return;
|
||||
|
||||
/* Clear any previous balloon before showing a new one */
|
||||
if (bPtr->view->flags.mapped && bPtr->forWindow != view->window) {
|
||||
W_UnmapView(bPtr->view);
|
||||
bPtr->forWindow = WM_NATIVE_NONE;
|
||||
}
|
||||
|
||||
text = WMHashGet(bPtr->table, view);
|
||||
if (!text) {
|
||||
if (bPtr->view->flags.realized)
|
||||
if (bPtr->view->flags.realized && bPtr->forWindow == WM_NATIVE_NONE)
|
||||
W_UnmapView(bPtr->view);
|
||||
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -642,9 +642,22 @@ static void wl_balloon_draw(void *vctx, W_View *view, int x, int y,
|
|||
|
||||
W_Screen *scr = view->screen;
|
||||
WMFont *font = scr->normalFont;
|
||||
int textWidth = WMWidthOfString(font, text, strlen(text));
|
||||
int bw = textWidth + 16;
|
||||
int bh = WMFontHeight(font) + 8;
|
||||
int fh = WMFontHeight(font);
|
||||
|
||||
/* Count lines and find widest line for multi-line text */
|
||||
int maxWidth = 0, numLines = 1;
|
||||
const char *p = text;
|
||||
while (*p) {
|
||||
const char *nl = strchr(p, '\n');
|
||||
int lineLen = nl ? (int)(nl - p) : (int)strlen(p);
|
||||
int lw = WMWidthOfString(font, p, lineLen);
|
||||
if (lw > maxWidth) maxWidth = lw;
|
||||
p = nl ? nl + 1 : p + lineLen;
|
||||
if (nl) numLines++;
|
||||
}
|
||||
|
||||
int bw = maxWidth + 16;
|
||||
int bh = numLines * fh + 8;
|
||||
if (bw < bh) bw = bh;
|
||||
|
||||
int bx = x + w / 2 - bw / 2;
|
||||
|
|
@ -674,8 +687,18 @@ static void wl_balloon_draw(void *vctx, W_View *view, int x, int y,
|
|||
{bw - 1, 0, 1, bh}
|
||||
});
|
||||
|
||||
WMDrawString(scr, (WMDrawable)view->window, scr->black, font,
|
||||
8, (bh - WMFontHeight(font)) / 2, text, strlen(text));
|
||||
/* Draw each line */
|
||||
p = text;
|
||||
int line = 0;
|
||||
while (*p) {
|
||||
const char *nl = strchr(p, '\n');
|
||||
int lineLen = nl ? (int)(nl - p) : (int)strlen(p);
|
||||
int ty = 4 + line * fh;
|
||||
WMDrawString(scr, (WMDrawable)view->window, scr->black, font,
|
||||
8, ty, p, lineLen);
|
||||
p = nl ? nl + 1 : p + lineLen;
|
||||
line++;
|
||||
}
|
||||
}
|
||||
|
||||
static void wl_drag_begin(void *vctx, W_View *view, WMEvent *event)
|
||||
|
|
|
|||
Loading…
Reference in New Issue