Class: MittensUi::Image
Overview
An image widget that displays a static image or animated GIF. Wraps Gtk::Image. Click events are handled via Gtk::GestureClick.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from Core
Instance Method Summary collapse
-
#click { ... } ⇒ void
Connects a block to the click event.
-
#initialize(path, options = {}) ⇒ Image
constructor
Creates a new Image widget.
Methods inherited from Core
#hidden?, #hide, #keyboard_shortcut, #remove, #remove_keyboard_shortcut, #render, #shortcuts, #show
Methods included from Helpers
#icon_map, #list_system_icons, #set_margin_from_opts_for
Constructor Details
#initialize(path, options = {}) ⇒ Image
Creates a new Image widget.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mittens_ui/image.rb', line 30 def initialize(path, = {}) @path = path.strip tooltip_text = [:tooltip_text] || '' @img_width = [:width] || 80 @img_height = [:height] || 80 if @path.include?('.gif') init_gif else init_static_image end @image.tooltip_text = tooltip_text # GTK4: use a Picture widget for better size control if available, # otherwise wrap in a fixed-size container @container = Gtk::Box.new(:vertical, 0) @container.set_size_request(@img_width, @img_height) @container.halign = :start @container.valign = :start @container.append(@image) super(@container, ) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
19 20 21 |
# File 'lib/mittens_ui/image.rb', line 19 def path @path end |
Instance Method Details
#click { ... } ⇒ void
This method returns an undefined value.
Connects a block to the click event.
61 62 63 64 65 |
# File 'lib/mittens_ui/image.rb', line 61 def click gesture = Gtk::GestureClick.new gesture.signal_connect('pressed') { yield } @container.add_controller(gesture) end |