Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Recently I've seen this widget in Gedit:

enter image description here

It appears when you press Ctrl + F. What I am interested is in how to get the sliding effect. Any suggestion will be appreciated.

share|improve this question
    
Not Understand Sliding effect clarify what "sliding effect means " –  Gaurav_Java Sep 7 '12 at 15:49
    
@Gaurav_Java it appears sliding from below the top panel. If you see it in Gedit you'll see it pressing 'Ctrl + F' –  Ángel Araya Sep 7 '12 at 19:19
    
The effect is often called "drop-down", I believe - sometimes menus are animated in the same way. –  Steve Kroon Sep 9 '12 at 10:11
1  
I thought maybe you could use a css transition property, but I don't see how to change positioning in css. Looking through the gedit code, they seem to use a custom viewframe to for the search box bazaar.launchpad.net/~vcs-imports/gedit/master-git/view/head:/… which they animate through some theatrics module (look at the bzr). I'm not very good at parsing C code though. –  Ian B. Sep 10 '12 at 0:27
1  
BTW, this widget is also in Google Chrome (and Chromium presumably) –  Ian B. Sep 10 '12 at 0:28

2 Answers 2

I have achieved a fade-out effect using pure GTK and CSS.

It is only working in GTK 3.6 and I am not sure if a slide in / out effect would be possible, however, if you want, you can look at the source at launchpad.net/uberwriter

It works through a state-change and then GTK Transitions... Maybe with height // width that would be possible, too.

EDIT

Because people obviously downvote me, here is another, more detailed explanation:

This is the CSS I have used:

GtkLabel:insensitive {
    color: rgba(255,255,255,0);
    transition: 500ms ease-in-out;
}

If you use this as CSS (I hope I am allowed to reference an explanation from myself, how to that: http://wolfvollprecht.de/blog/gtk-python-and-css-are-an-awesome-combo/) then you can use Gtk.StateFlags to fade out the Label.

e.g.:

label.set_state_flags(Gtk.StateFlags.INSENSITIVE, True)

Then you get a transition to zero opacity.

However, as I have noticed, there are not many options to influence placement / width with CSS, so I guess it's limited to colors / opacity etc.

Enjoy.

PS: Note that this only works in Gtk 3.6, since Ubuntu 12.10

share|improve this answer

Such animation is not achievable in pure GTK+. There are no mechanisms that would process it.

I have given a quick look on gedit's source code, it's clear that they process this animation on their own. I have not looked into details, for the code related to animations is quite expanded, but I have noted that they incorporate Cairo drawing features for the animated search widget. Most likely the widget is animated by moving its position frame by frame and redrawing it on a different place in the overlay that is used on a single text display area.

That seems to be the simplest solution. (gedit's code seems to be prepared for many animations sharing the same code base, thus it may be an overkill to use it's exact approach in a simple application.)

To reproduce this effect, you will need to:

  • Use a custom widget for the UI piece that you want to slide in/out.
  • Make it react on draw event and periodical timeouts (to redraw each frame of animation)
  • Create a transparent overlay over the rest of your widgets (or any area that has to appear as if it was below the sliding widget)
  • Draw the animated widget manually on such overlay.

I can't come up with any easier solution. However, considering the fact that gedit developers do know GTK+ as probably very little do, there may be no simpler trick to achieve such effect.

share|improve this answer
    
It seems your idea it's the "simplest". I thought it could be done with some CSS hacking, but reading Gedit's code seems to be more like hardcoded and prepared for more than a simple search box entry, as you say. So, I'll try making a custom widget and, first, move it around on certain events (at least if it is possible). Thanks for your suggestions. –  Ángel Araya Sep 12 '12 at 18:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.