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
|
# Copyright (c) 2015-2016 Ruby-GNOME2 Project Team
# This program is licenced under the same licence as Ruby-GNOME2.
#
=begin
= Overlay/Interactive Overlay
Shows widgets in static positions over a main widget.
The overlayed widgets can be interactive controls such
as the entry in this example, or just decorative, like
the big blue label.
=end
class OverlayDemo
def initialize(main_window)
@window = Gtk::Window.new(:toplevel)
@window.set_default_size(500, 510)
@window.title = "Interactive Overlay"
@window.screen = main_window.screen
overlay = Gtk::Overlay.new
initialize_grid
overlay.add(@grid)
@entry = Gtk::Entry.new
@entry.placeholder_text = "Your Lucky Number"
vbox = Gtk::Box.new(:vertical, 10)
overlay.add_overlay(vbox)
overlay.set_overlay_pass_through(vbox, true)
vbox.halign = :center
vbox.valign = :center
label = Gtk::Label.new("<span foreground='blue' weight='ultrabold' font='40'>Numbers</span>")
label.use_markup = true
vbox.pack_start(label, :expand => false, :fill => false, :padding => 8)
vbox.pack_start(@entry, :expand => false, :fill => false, :padding => 8)
@window.add(overlay)
overlay.show_all
end
def run
if !@window.visible?
@window.show_all
else
@window.destroy
end
end
private
def initialize_grid
@grid = Gtk::Grid.new
(0..4).each do |i|
(0..4).each do |j|
text = (5 * j + i).to_s
button = Gtk::Button.new(:label => text)
button.hexpand = true
button.vexpand = true
button.signal_connect "clicked" do |widget|
@entry.text = widget.label
end
@grid.attach(button, i, j, 1, 1)
end
end
end
end
|