Sample Code 117: How to have a Screen Ruler for measuring number of pixels on screen - Part 1? |
|
Written by kksou
|
|
Wednesday, 13 December 2006 |
|
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
Sample Code 1 2 3 4 5 6 7 8 9
| <?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
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
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!
Related Links
User reviews There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |