Horizontal Slider thumb and Tooltip

Forum for general chit-chat or off-topic discussion.

Moderators: CEGUI MVP, CEGUI Team

Armitage1982
Not too shy to talk
Not too shy to talk
Posts: 43
Joined: Wed Dec 10, 2008 14:15
Location: Belgium

Horizontal Slider thumb and Tooltip

Postby Armitage1982 » Tue Feb 10, 2009 13:33

Hi

Considering I'm using the TaharezLook and that I have no room left for another widget in order to show the current slider value.

Is there a way to always show the thumb tooltip of Horizontal Slider ? (Except maybe in normal situation, a bit like some sliders value in microsoft tool).

I already change the Tooltip options (like HoverTime, FadeTime and DisplayTime to 0) but unfortunately when I click down the mouse over my thumb or simply move it the tooltip logically disappear.

I'm not very comfortable with Falagard so I doubt I will be able to put some kind of static text next to the SliderHorizThumb.

Have you an idea ?
Thanks

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Tue Feb 10, 2009 19:50

Hi,

I don't think there is a really simple way to get what you're after (meaning you'd have to DIY somehow - a real PITA, or write a custom tool-tip tailor made for what you need - not simple, but a nice solution).

Having said this, I'll have a play around with a couple of ideas and the existing tooltip, and perhaps reply again in a little while ;) Also, if you're using 0.6.2 there is a known issue (stack overflow) if the tooltip happens to pop-up right under the mouse cursor, so you'll want to be avoiding that!

CE.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Tue Feb 10, 2009 21:08

Ok, I have a solution that may work for you; it's a total hack, of course, because the tooltip was not made to work like this.

Anyway, basically what you do is subscribe a listener to EventHidden on the Tooltip, and in the handler for that you basically reset the target window to the slider thumb. The code below is using the system default tooltip, though I think it might be better if the slider and it's thumb were using their own private tooltip.

Also if note is that the handler is checking specifically for a single 'thumb' to reassign the tooltip to, if you have multiple sliders you need this to work on, you'll need to get a little creative.

So, you set up the tooltip like this (or similar)

Code: Select all

    Tooltip* tooltip = System::getSingleton().getDefaultTooltip();
    tooltip->subscribeEvent(Tooltip::EventHidden, tooltipKeeper);
    tooltip->setHoverTime(0);

    winMgr.getWindow("MySlider")->setTooltipText("1.0");
    winMgr.getWindow("MySlider__auto_thumb__")->setInheritsTooltipText(true);

I set the initial value as the tooltip text, and also make sure that the thumb is set to inherit this value from the main slider - though this can be done in the LookNFeel to save doing it manually.

The handler, 'tooltipKeeper' looks like this:

Code: Select all

bool tooltipKeeper(const CEGUI::EventArgs& args)
{
    using namespace CEGUI;

    Window* thumb =
        WindowManager::getSingleton().getWindow("MySlider__auto_thumb__");

    System& sys = System::getSingleton();
    if (sys.getWindowContainingMouse() == thumb)
        sys.getDefaultTooltip()->setTargetWindow(thumb);

    return true;
}


In the handler that responds to slider changes, you need to set not only the slider tooltip text, but also the text on the tooltip itself, for example:

Code: Select all

    Window* slider = WindowManager::getSingleton().getWindow("MySlider");
    slider->setTooltipText(slider->getProperty("CurrentValue"));
    System::getSingleton().getDefaultTooltip()->setText(slider->getProperty("CurrentValue"));


I notice you mention a "horizontal" slider and TaharezLook, since there is no such thing, I presume you must mean a scrollbar? This example uses a 'real' slider, so you may have to make a couple of adjustments accordingly.

HTH

CE.

Armitage1982
Not too shy to talk
Not too shy to talk
Posts: 43
Joined: Wed Dec 10, 2008 14:15
Location: Belgium

Postby Armitage1982 » Wed Feb 11, 2009 19:24

Thanks CrazyEddie.
I will try this asap.
To be honest i'm using the Aqualook Skin which is based on the TaharezLook so probably the Horizontal slider is specific to this one.

For the moment I reshape my panel and add a little bit more space so I can add the value at the end of the description label next to my slider.
But good to know there is hack for this :)

Thank you very much.


Return to “Offtopic Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests