Ecere SDK/eC Forums • View topic - Q1 - Tooltips




Ecere SDK/eC Forums

Ecere Developers Community

Q1 - Tooltips

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.

Q1 - Tooltips

Postby D.Bane » Mon Jan 16, 2012 1:16 pm

Hi to all.

I wanted to add the Tooltip control/class to the Window class and had no success as there were few other things that I did not understand as well, which I want to include in the Tooltip class.

The reason I was thinking about the tooltips is that I believe that they are very important in any application as sometimes there is a need to explain a bit more then the name of the button truly explains the action to the end user.

I thought of making it do a for loop and check if the mouse is over any control and if that control has useTooltip=true then show it, but I believe that it would be better to have a Tooltip class inside Window class and that every control checks it out for itself instead.

I did take a look at the ecere.dll (source) and was thinking about adding it directly to the "class Window{" by making something as:

Code: Select all
class Tooltip : Window
{
...
}
 
class Window{
..
Tooltip tooltip{};
..
}


or if someone has another idea how to address this?

Thank you upfront,
D.Bane.
No army is to big, if the heart is beating strong.
There's no bad luck, it's just easier to blame someone else.
D.Bane
 
Posts: 78
Joined: Thu Jul 29, 2010 2:51 pm

Re: Q1 - Tooltips

Postby jerome » Sat Feb 04, 2012 12:51 pm

Hi again D.Bane!

Ecere now has tooltips :D ! I've decided to add a String property called toolTip to the CommonControl class.

You can also instantiate the ToolTip class itself, giving you the opportunity to change the looks.

Please pull the latest code from github.

The following sample code demonstrates both options. I've also attached it to this post.
Code: Select all
import "ecere"
 
class ToolTipsDemo : Window
{
   text = "Tool Tips Demo";
   background = activeBorder;
   borderStyle = sizable;
   nativeDecorations = true;
   tabCycle = true;
   hasClose = true;
   font = { "Arial", 14 };
   size = { 400, 300 };
 
   Button button1
   {
      this, text = "Simple Tooltip", position = { 88, 104 };
      toolTip = "This button does this.\nPlease click it!";
   };
   Button button2
   {
      this, text = "Custom Tooltip", position = { 192, 168 }
   };
   ToolTip tt
   {
      button2, tip = "You can change fonts and colors!";
      alphaBlend = true, opacity = 0.75;
      font = { "Comic Sans MS", 12 };
      background = lightSkyBlue, foreground = darkSlateBlue;     
   };
}
 
ToolTipsDemo demo {};


Because tooltips are a toolbar's best friends, I've attached a ToolBar demo using the new tooltips as well. To build the toolbar demo, you will need to add ToolBar.ec and IconBag.ec to your project, which can be found under the sdk/extras/gui and sdk/extras/gui/controls directories. Please keep in mind that like anything in the extras directory, the ToolBar classes are subject to change to improve simplicity and ease of use before making its way within the main Ecere GUI library.

From now on both of these samples, along with the earlier TextScroller, will be found in the samples directory under sdk/samples/guiAndGfx directory as well.

All the best!

Jerome
Attachments
toolBarDemo.ec
ToolBar & ToolTips demo
(1.95 KiB) Downloaded 740 times
toolTips.ec
ToolTips demo
(744 Bytes) Downloaded 722 times
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm

Re: Q1 - Tooltips

Postby D.Bane » Wed Feb 08, 2012 8:36 am

:D Nice

You did this really fast :) Oh, also, I forgot to write this in the first post, I hope that you had great time for the New Years.

I really like that you added the option to modify it as needed.

But, I will need to pick your brain a bit :) Sorry, like to know things, especially if they are cool 8-)

I immediately opened the Ecere.dll (source) and found Tooltip, but I was wondering about few things like
Code: Select all
Window::OnMouseOverHandler
Window::OnMouseLeaveHandler
Window::OnLeftButtonDownHandler
Window::OnMouseMoveHandler


especially when you already have:
Code: Select all
OnMouseOver
OnMouseLeave
OnLeftButtonDown


Is there anything special about the *Handler functions, meaning if it is better to call them for some things and 'regular' functions for another?

Thank you,
D.Bane.
No army is to big, if the heart is beating strong.
There's no bad luck, it's just easier to blame someone else.
D.Bane
 
Posts: 78
Joined: Thu Jul 29, 2010 2:51 pm

Re: Q1 - Tooltips

Postby jerome » Sat Feb 11, 2012 3:10 am

Hi D.Bane,

I'm glad you enjoy the new ToolTips! 8-)

I encourage your curiosity in the inner workings of Ecere, so I will satisfy it about those *Handler functions!

I hope one day this same curiosity will bring you to help us resolve the many pending issues on our Mantis Bugtracker, to make Ecere as good as it ought to be! :D

So those *Handler methods, they are actually defined and declared in the ToolTip class themselves.
i.e. they are not something defined by the base GUI toolkit, e.g. the Window class.

Their purpose is to override the respective OnMouseMove/OnMouseOver/OnMouseLeave/OnLeftButtonDown events of the window to which the tooltip is assigned (the window it describes, gives tips on, tippedWindow in the code).
They are not called simply e.g. OnMouseOver, because this would override the ToolTip window's own event, rather than the 'tippedWindow''s. If you look at the code, you will see there is actually a OnMouseOver that handles the OnMouseOver event of the ToolTip itself (when your mouse moves over the actual tooltip).

The mere definitions of those methods do nothing by themselves, but they take effect when the tooltip is assigned to a window, and the code does:
Code: Select all
         tippedWindow.OnMouseOver = OnMouseOverHandler;
         tippedWindow.OnMouseLeave = OnMouseLeaveHandler;
         tippedWindow.OnMouseMove = OnMouseMoveHandler;
         tippedWindow.OnLeftButtonDown = OnLeftButtonDownHandler;


You will also notice some code that preserves the original mouse handles of the tippedWindow, saving it in e.g. OrigOnMouseOver. You will also notice the original mouse handler is also chained at the end of the *Handler methods, and it is restored if the tooltip is 'detached' form the 'tippedWindow'.

All this code dynamics is rather complex, but it shows some of the flexibility of eC and the Ecere GUI toolkit :)

I will admit a lot of the trickiness of the code is due to the fact that I insisted on using the 'parent' property for the tippedWindow of the ToolTip class, so we could do (because 'parent' is the first property of any Window class):

ToolTip tt { button }; instead of ToolTip tt { tippedWindow = button };

even though button is never actually the parent ( The parent of a window, in the Ecere GUI toolkit, is the window within which the window is confined, obviously not the case for the tooltips ).

We should probably think of some eC feature to change this 'default' first property so we do not have to resort to such hacks... You will notice in the code for example the watch(parent) which is invoked whenever the parent property is modified, which assigns tippedWindow to that value, and then goes and change the parent back to null (the desktop).

Just a fun thing to point out, the code you put in your first post would have endlessly created ToolTip classes, since the ToolTip derived from Window and Window contained a ToolTip instance! :lol:
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm

Re: Q1 - Tooltips

Postby D.Bane » Sun Feb 12, 2012 4:22 pm

Hi Jerome.

jerome wrote:Just a fun thing to point out, the code you put in your first post would have endlessly created ToolTip classes, since the ToolTip derived from Window and Window contained a ToolTip instance! :lol:


Yes, I thought that it should be done in a different way, but in the same time I did not know exactly how to approach it, but you made it great. I especially like the ability to change the style of it, as well as to have it transparent.

Oh, sorry, I passed trough the code and got distracted by the *Handler functions and had missed the part where they are assigned to regular events. :oops: I really thought that they were in Ecere Window class where I went immediately but had not found them :( .. now I know why :)

Thank you Jerome, all the best.
D.Bane.
No army is to big, if the heart is beating strong.
There's no bad luck, it's just easier to blame someone else.
D.Bane
 
Posts: 78
Joined: Thu Jul 29, 2010 2:51 pm


Return to GUI Toolkit & 2D Graphics

Who is online

Users browsing this forum: No registered users and 5 guests

cron