# Designing gtk+ applications

**URL:** <https://www.ruby-forum.com/t/designing-gtk-applications/190952>\
**Category:** Ruby-Gnome 2\
**Created:** [July 1, 2010, 2:30pm UTC](https://www.ruby-forum.com/t/designing-gtk-applications/190952 "2010-07-01T14:30:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmn228](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@rmn228](https://www.ruby-forum.com/u/rmn228)\
**Post date:** [July 1, 2010, 2:30pm UTC](https://www.ruby-forum.com/t/designing-gtk-applications/190952/1 "2010-07-01T14:30:04Z")

</div>

Hi guys, I’d like to consult with you about the following:  
is it possible to customize design of GTK+ apps? I mean they use system  
theme’s settings by default(the same width, color, transparency etc.),  
but I’d like my application to look as I want. I’ve almost created my  
mp3 player, but it’s look kills me. What should I do to use my own  
design features?

Best,  
Roman.

---

<div class="post-metadata">

**Author:** ![rmn228](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@rmn228](https://www.ruby-forum.com/u/rmn228)\
**Post date:** [July 1, 2010, 2:50pm UTC](https://www.ruby-forum.com/t/designing-gtk-applications/190952/2 "2010-07-01T14:50:24Z")

</div>

write web apps.

---

<div class="post-metadata">

**Author:** ![rmn228](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@rmn228](https://www.ruby-forum.com/u/rmn228)\
**Post date:** [July 1, 2010, 6:42pm UTC](https://www.ruby-forum.com/t/designing-gtk-applications/190952/3 "2010-07-01T18:42:52Z")

</div>

yeah, you can’t change the theme of a gtk app without changing the whole  
system theme.

On Thu, Jul 1, 2010 at 1:49 PM, niklas | brueckenschlaeger \<

---

<div class="post-metadata">

**Author:** ![rmn228](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@rmn228](https://www.ruby-forum.com/u/rmn228)\
**Post date:** [July 1, 2010, 8:03pm UTC](https://www.ruby-forum.com/t/designing-gtk-applications/190952/4 "2010-07-01T20:03:04Z")

</div>

It’s possible, but not encouraged.

Take the following, for example - it demonstrates the parsing of an  
additional theme file, local modification of settings that are otherwise  
shared and overriding the drawing of a particular widget.

–8\<—  
#!/usr/bin/ruby  
vanilla = fork()

require ‘gtk2’

window = Gtk::Window.new

window.set\_border\_width(16)  
window.add(button = Gtk::Button.new(“Text”))  
button.children[0].set\_padding(16,16)

unless vanilla

# Parse custom gtkrc

Gtk::RC.parse\_string \<\<-RC  
style “displace”  
{  
GtkButton::child\_displacement\_y = 8  
GtkButton::child\_displacement\_x = 8  
}  
class “GtkButton” style “displace”  
RC

# Modify local gtk settings, ie. theme

Gtk::Settings.default.gtk\_theme\_name = “HighContrastInverse”

# Paint the button using cairo instead of theme

button.set\_app\_paintable(true)  
button.signal\_connect(‘expose-event’) do |widget,e|  
cr = widget.window.create\_cairo\_context

xmod, ymod = widget.style\_get\_property(‘child-displacement-x’),  
widget.style\_get\_property(‘child-displacement-y’)  
allocation = widget.allocation

if widget.state == Gtk::STATE\_ACTIVE  
x, y, w, h = allocation.x + 2_xmod, allocation.y + 2_ymod,  
allocation.width - 2_xmod, allocation.height - 2_ymod  
else  
x, y, w, h = allocation.x + xmod, allocation.y + xmod,  
allocation.width - 2_xmod, allocation.height - 2_xmod  
cr.save do  
cr.translate(xmod, ymod)  
cr.rounded\_rectangle(x, y, w, h, 16)  
cr.set\_source\_rgba(0.6,0.2,0.2,0.8)  
cr.fill  
end  
end  
cr.rounded\_rectangle(x, y, w, h, 16)  
cr.set\_source\_rgba(0.5,0.5,0.5,0.8)  
cr.fill

# Propagate expose event to child widgets

widget.children.each { |child| widget.propagate\_expose(child, e) }

# Block default expose-event handler

true  
end

end

window.show\_all

Gtk.main  
–8\<–

---

<div class="post-metadata">

**Author:** ![rmn228](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@rmn228](https://www.ruby-forum.com/u/rmn228)\
**Post date:** [July 1, 2010, 11:08pm UTC](https://www.ruby-forum.com/t/designing-gtk-applications/190952/5 "2010-07-01T23:08:41Z")

</div>

It is not that wery hard to write your own widgets.

If you want VERY fancy widgets you can also use Cairo.  
Take a look at

[http://www.raditex.nu//websvn/listing.php?repname=kurssrc.Exempel&path=%2FCairoCandy%2F#\_CairoCandy\_](http://www.raditex.nu//websvn/listing.php?repname=kurssrc.Exempel&path=%2FCairoCandy%2F#_CairoCandy_)

Gorhas

2010/7/1 Grant McLean [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![rmn228](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@rmn228](https://www.ruby-forum.com/u/rmn228)\
**Post date:** [July 1, 2010, 11:03pm UTC](https://www.ruby-forum.com/t/designing-gtk-applications/190952/6 "2010-07-01T23:03:24Z")

</div>

On Thu, 2010-07-01 at 14:30 +0200, Roman Tolmachev wrote:

> Hi guys, I’d like to consult with you about the following:  
> is it possible to customize design of GTK+ apps? I mean they use system  
> theme’s settings by default(the same width, color, transparency etc.),  
> but I’d like my application to look as I want. I’ve almost created my  
> mp3 player, but it’s look kills me. What should I do to use my own  
> design features?

When you need to step outside the standard set of GTK user interface  
elements, one approach is to use a canvas widget. The GNOME canvas is  
certainly one option and I think the Ruby bindings should work. Be  
warned that the GNOME canvas has been deprecated upstream but as yet no  
clear replacement has emerged.

Recently I’ve been doing some work with the Clutter canvas which is very  
good. I have no idea about the availability of Ruby bindings for  
Clutter though as I’ve mostly been working with Perl.

Cheers  
Grant
