1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#!/usr/bin/env ruby
#
# This sample code is a port of gtk3/demos/gtk-demo/css_accordion.c. The
# CSS files used in this sample code are copied from gtk3/demos/gtk-demo.
# They are licensed under the terms of the GNU Lesser General Public
# License, version 2.1 or (at your option) later.
#
# Copyright (C) 2013 Ruby-GNOME2 Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
=begin
= CSS Theming/CSS Accordion
A simple accordion demo written using CSS transitions and multiple backgrounds
=end
require "common"
module Demo
class CssAccordion < BasicWindow
def initialize
super("CSS Accordion")
set_default_size(600, 300)
container = Gtk::Box.new(:horizontal, 0)
container.set_halign(:center)
container.set_valign(:center)
add(container)
child = Gtk::Button.new(:label => "This")
container.add(child)
child = Gtk::Button.new(:label => "Is")
container.add(child)
child = Gtk::Button.new(:label => "A")
container.add(child)
child = Gtk::Button.new(:label => "CSS")
container.add(child)
child = Gtk::Button.new(:label => "Accordion")
container.add(child)
child = Gtk::Button.new(:label => ":-)")
container.add(child)
provider = Gtk::CssProvider.new
provider.load(:data => File.read("css_accordion.css"))
apply_css(self, provider)
end
def apply_css(widget, provider)
widget.style_context.add_provider(provider, GLib::MAXUINT)
if widget.is_a?(Gtk::Container)
widget.each_forall do |child|
apply_css(child, provider)
end
end
end
end
end
|