Toast Popup

In javascript I use a thing called “Toast” which briefly displays an unclickable balloon popup that fades away after a moment.

It’s very useful for getting the user’s attention or providing feedback. I want to use it to indicate that text actually was copied when the user pressed a Copy button, or to indicate that an account was created successfully.

Is there something like this in Xojo, or maybe MBS? I’m having trouble searching because I don’t know if there’s an official name for it. Or perhaps there’s a better way of doing it? I want to avoid msgbox and statusbar text for certain things.

-Mike

Set the “help Tag” property in the right hand inspector of the control in question at design time. See if that does what you are looking for.

Check out http://www.monkeybreadsoftware.net/class-maattachedwindowmbs.shtml . I have a wrapper calculating size and position if you want.

Thanks!

The help tag property isn’t really what I’m looking for, I want it to pop up with no user action required, like after a thread finishes logging the user into a remote server.

MAAttachedWindow looks close but it’s Mac only. I’m hoping to find a cross platform solution.

You can kind of see what I mean here, when it pops up “At last, you selected something!”

http://www.youtube.com/watch?v=gnakLKnS_5g

I don’t need any of that sliding nonsense, just a good way to notify the user of events completing without being intrusive with a MSGBOX.

This could be done with window.show and window.close and if needed some timer in between…

I think you’re right, if I could find a way to make it fade in and out I could probably make it work.

I would also need to make sure it didn’t get focus and interrupt whatever the user was doing.

There was discussion not long ago about popover boxes, and I remember a nice demo. Popover do not receive focus, if I understand right. Search for ‘popover’. You could use some of the code.

Another approach, which gets pretty close to the example you cited, is to use a rectangle or rounded rectangle with a label on top, and render it visible and invisible. The limitation is that you got to remain within the current window, but you can move it within, and from what I experimented quickly, sure it does not fade in and out, but appearance and disappearance remain fine to me.

Maybe instead of a fade out you can modify the background color, or have the box move out of the window.

The rectangle carries the label together, and you only need to set the rectangle visibility to set both. It is convenient because you can reuse it at will and change the text as you need. And the rectangle will not steal the focus. I triggered it by characters within the keydown event of a TextField, and it does not slow it a bit.

And this is cross platform as well :slight_smile:

Good idea, I’m going to give it a try right now.

Thanks Michel, worked perfectly, here is my not so elegant but working solution. I’m using an MBS plugin to size the rectangle. I would improve it by changing the position of the popup if the user’s mouse is near the bottom or right of the screen.

-RoundRectangle, rectPop, invisible and colored yellow
-Label within, lblRectPop
-Timer timRectPop mode 0
-iTimRectPop, integer 0

Sub showRectPopup(s as string) dim t as NSTextFieldMBS = lblRectPopup.NSTextFieldMBS lblRectPopup.Text = s 'lblRectPopup.NSTextFieldMBS.sizeToFit t.sizeToFit lblRectPopup.Width = t.bounds.Width rectPopup.Width = lblRectPopup.Width + 40 rectPopup.top = MouseY + 30 rectPopup.Left = MouseX + 10 rectPopup.Visible = true iTimRectPopup = 0 timRectPopup.mode = 2 End Sub

Timer:

iTimRectPopup = iTimRectPopup + 1 if iTimRectPopup >= 4 then rectPopup.Visible = false timRectPopup.Mode = 0 end if

Doh! The NSTextField is not cross platform. I will have to remove that and resize the text another way for windows.

Glad it works fine.

You are going to have to use #If TargetWin32 Then and slightly modify to accomodate Windows, but the important thing is, you got it working and know what you want to obtain :slight_smile:

This approach will work on Macs without MBS and on Windows. You might have to tweak the numbers a bit.

lblRectPopup.Text = s lblRectPopup.Width = len(s) * 10 rectPopup.Width = lblRectPopup.Width + 40 rectPopup.top = MouseY + 30 rectPopup.Left = MouseX + 10 rectPopup.Visible = true iTimRectPopup = 0 timRectPopup.mode = 2