MessageCtrl package for U++ ----------------------------- This class implements a messages manager. Messages are simple message boxes similar to prompts in that they can allow the same basic user actions. However, message boxes are not meant as a replacement for the traditional U++ dialogs. The main difference between the messages and the prompts is that the message boxes are implemented as frames instead of dialogs, and are meant to be less intrusive, and non-blocking. There are several types of messages: - Information: Should be used to display common information. - Warning: Should be used to report non-critical issue, to inform that everything is all right. - Success: Should be used to display successful operations. Essentially this is an information notification. - Question: Should be used to ask for some interaction. - Error: Should be used to display critical application errors - Custom: If the predefined notification types don't suit your needs, you can create one. Message boxes use QTF texts. This allows for embedding hyperlinks in messages. It also means that in some cases the text messages should be escaped, using DeQtf() function. History: -------------------- 2018-04-07: UseCross() method added. It is now possible to use a small image button with cross instead of OK button. Informative message boxes use crosses by default. 2018-03-03: Name clash on Windows fixed. MessageBox::Type::ERROR -> MessageBox::Type::FAILURE Message display order changed. New messages will be inserted as the the topmost/bottom-most frame (depending on orientation) Selective clearing added. 2018-03-01: Information and custom message boxes can now have timeouts. 2018-02-21: Widget renames as MessageCtrl. (Final) 2018-02-20: It is now possible to add mesasges as both top and bottom frames. It is now possible to add single message box without using the manager. Message framework further refactored. 2018-02-19: Name change: Notification -> Message. Code refactored. (Thanks Klugier!) 2018-02-18: Initial public release
include <CtrlLib/CtrlLib.h> using namespace Upp; class RichTextTest : public TopWindow { FrameTop<RichTextCtrl> qtf; Button bt; public: RichTextTest() { SetRect(0, 0, 640, 480); Sizeable().Zoomable().CenterScreen(); Add(bt.RightPos(4).BottomPos(4)); bt << [=] { String z = "Hello World!"; qtf.VCenter(); // Comment out this line, and highlighting works. qtf.SetQTF("[G1 " << z); qtf.Height(40); // As the height increases, highlighting becomes impossible. // This problem doesn't arise with wrapped (Line > 1) text qtf.SetFrame(FieldFrame()); AddFrame(qtf); }; } }; GUI_APP_MAIN { RichTextTest().Run(); }
2918-02-20: It is now possible to add messages as both top and bottom frames. It is now possible to add single message box without using the manager. Message framework further refactored.
Hello,
I was thinking about your code and I think it's final name should be MessageCtrl. Ctrl prefix in upp world means any graphical control, that you can use in your own code. In the Message class we are solving such problem. Please, let me know what do you think?
Message is too general. It could also represent chat message or IPC message etc.
____________
Some time ago, I also created "Associated projects" website to collect interesting projects related to the Upp. If you have any comments related to that page, please let me know.
See first message of this topic for GIT address and/or zipped package.
Oblivion
Could you please check it?
Oblivion.
now it works. I just needed a similar widget, thanks!
I have few questions:
1) I saw that the new message, even if Top() is set are appended to the existing ones.
Is it possible that the most recent message enter from top and appear on first row? In this way the user can observe only the first row.
2) Moreover, is it possible to add a message without any button?
3) It would be nice to set a maximum number of messages, the most recent, and delete automatically the others that become obsolete.
Hello Luigi,
1) Done (see package) It is the default behaviour now.
I may also add Append() if requested.
2) Yes this is possible too. But I have some reservations about this.
It might make sense to add this option to MessageBox, but IMO this should be restricted to Information type message box. (as with the timeout).
Others (Error, Success, Warning, Question) need to stay, and wait for confirmation, since they are although informational, yet important messages.
So here's what I propose: I'll add it as an option to both Custom message boxes, and Information boxes (with a default timeout)
3) I don't quite understand this one. You ask me to add a message limit, time limit, or something else? Could you elaborate a little more?
Best regards,
Oblivion
MessageCtrl: Append() method added. MessageCtrl: Selective clearing added. (You can target a specific ctrl for clearing).
Regarding the buttonless informative message boxes: I will add them as an option.
How to proceed?
Should I add an overlay icon that only appears when the mouse pointer is near, or should I just let them have a timeout?
class MyWindow : public TopWindow { MessageCtrl messages; DocEdit editor; RichEdit richeditor; void DisplayEditorErrorMessage() { messages.Error(editor, "This is an error message."); } void DisplayRichEditorSuccessMessage() { messages.Success(richeditor, "This is a success message."); } // Other members, constructors, etc... };
I've written a new example to clarify the behaviour. Please find the attached example.
I've written a new example to clarify the behaviour. Please find the attached example.
with no success. Perhaps I must use several MessageCtrl and bind each of them to a different ctrl.
messages.Clear(&editor)
#include <CtrlLib/CtrlLib.h> #include <MessageCtrl/MessageCtrl.h> using namespace Upp; class Messages : public TopWindow { MessageCtrl msg; DocEdit editor; Button button1, button2; public: Messages() { Title("U++ Message Boxes (Passive Notifications)"); SetRect(0,0, 640, 480); Sizeable().Zoomable().CenterScreen(); SetMinSize({100, 100}); auto action = [=](int id) { switch(id) { case IDYES: PromptOK("You've chosen 'yes'"); break; case IDNO: PromptOK("You've chosen 'no'"); break; } }; Add(editor.HSizePosZ().VSizePos(0, 24)); Add(button1.SetLabel("Test").RightPos(4).BottomPos(4)); Add(button2.SetLabel("Clear").LeftPos(4).BottomPos(4)); button2 << [=] { msg.Clear(this); }; // Selective clearing. button1 << [=] { msg.Animation() .Top() .Information(*this, "This is a time-constrained information message. It will disappear in 5 seconds.", Null, 5) .Success(*this, "This is a success message.") .Warning(*this, "This is a warning message.") .Error(*this, "This is an error message.") .Information(*this, "[C [4 This information message is using 16 pt courier font...]") // <-- Different font face and font size... .Bottom() .AskYesNo(editor, "This is a question box 'in' the text editor with " "[^https:www`.ultimatepp`.org^ l`i`n`k]" " support. Would you like to continue?", action, callback(LaunchWebBrowser) ); }; } }; GUI_APP_MAIN { Messages().Run(); }
Hello Luigi,
And unfortunately the method has to be renamed to something else. (undefining and redefining the "Success" constant won't work in this case). Therefore, I renamed it to OK.
- Standard message boxesnow adjust to light/dark theme.