Problem
I have been using a screen ruler from tigercolor.com for measuring the width and height of anything on the screen. It costs USD $19.95. I was browsing through the php-gtk manual yesterday when I realized that I can have a similar screen ruler with just a few lines of code in php-gtk2 as shown below:
Solution
- Create a horizontal ruler with GtkHRuler, or a vertical ruler with GtkVRuler
- Set the range with with GtkRuler::set_range().
Sample Code
1 2 5 6 7 8 9 10 11 14 15 16 17 18 | <?php $window = new GtkWindow(); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox()); $ruler = new GtkHRuler(); // note 1 $ruler->set_range(0, 800, 100, 1024); // note 2 $ruler->set_size_request(800, 20); $vbox->pack_start($ruler, 0, 0); // note 3 $window->show_all(); Gtk::main(); ?> |
Output
As shown above.
Explanation
- Create a horizontal ruler. The default unit is pixel.
- Here we set the ruler to be from 0 to 800 (pixels). The third parameter is the position marker (displayed as a triangle). Here we set it to 100 initially, just for you to see where's the marker. You could set it to zero. The last parameter is the maximum size.
- Remember to set expand and fill to false!
Read more...