class PopoverDemo
Popovers¶ ↑
A bubble-like window containing contextual information or options. GtkPopovers can be attached to any widget, and will be displayed within the same window, but on top of all its content.
Public Class Methods
new(main_window)
click to toggle source
# File gtk3/sample/gtk-demo/popover.rb, line 12 def initialize(main_window) @window = Gtk::Window.new(:toplevel) @window.screen = main_window.screen box = Gtk::Box.new(:vertical, 24) box.margin = 24 @window.add(box) widget = add_toggle_button_with_popover box.add(widget) widget = add_custom_entry_with_complex_popover box.add(widget) widget = add_calendar_with_popover box.add(widget) end
Public Instance Methods
add_calendar_with_popover()
click to toggle source
# File gtk3/sample/gtk-demo/popover.rb, line 94 def add_calendar_with_popover widget = Gtk::Calendar.new widget.signal_connect "day-selected" do |calendar| event = Gtk.current_event if event.type == :button_press x, y = event.window.coords_to_parent(event.x, event.y) allocation = calendar.allocation rect = Gdk::Rectangle.new(x - allocation.x, y - allocation.y, 1, 1) cal_popover = create_popover(calendar, CustomEntry.new, :bottom) cal_popover.pointing_to = rect cal_popover.show end end widget end
add_custom_entry_with_complex_popover()
click to toggle source
# File gtk3/sample/gtk-demo/popover.rb, line 72 def add_custom_entry_with_complex_popover widget = CustomEntry.new entry_popover = create_complex_popover(widget, :top) widget.set_icon_from_icon_name(:primary, "edit-find") widget.set_icon_from_icon_name(:secondary, "edit-clear") widget.signal_connect "icon-press" do |entry, icon_pos, _event| rect = entry.get_icon_area(icon_pos) entry_popover.pointing_to = rect entry_popover.show entry.popover_icon_pos = icon_pos end widget.signal_connect "size-allocate" do |entry, _allocation| if entry_popover.visible? popover_pos = entry.popover_icon_pos rect = entry.get_icon_area(popover_pos) entry_popover.pointing_to = rect end end widget end
create_complex_popover(parent, pos)
click to toggle source
# File gtk3/sample/gtk-demo/popover.rb, line 47 def create_complex_popover(parent, pos) if Gtk::Version.or_later?(3, 20) builder = Gtk::Builder.new(:resource => "/popover/popover.ui") else builder = Gtk::Builder.new(:resource => "/popover/popover-3.18.ui") end window = builder["window"] content = window.child content.parent.remove(content) window.destroy popover = create_popover(parent, content, pos) popover end
create_popover(parent, child, pos)
click to toggle source
# File gtk3/sample/gtk-demo/popover.rb, line 38 def create_popover(parent, child, pos) popover = Gtk::Popover.new(parent) popover.position = pos popover.add(child) child.margin = 6 child.show popover end
run()
click to toggle source
# File gtk3/sample/gtk-demo/popover.rb, line 29 def run if !@window.visible? @window.show_all else @window.destroy end @window end