Class: MittensUi::Notify
Overview
A dismissible notification widget that displays styled messages with optional auto-hide timer. Supports multiple notification types (error, info, question, default) with distinct styling.
Constant Summary collapse
- NOTIFICATION_CSS =
Embedded CSS styles for all notification types
<<~CSS /* Base notification styles */ .notify-container { padding: 12px; margin: 6px 10px; border-radius: 6px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); transition: all 0.3s ease; } /* Default notification */ .notify-default { background-color: #f0f0f0; color: #333333; border-left: 4px solid #cccccc; } /* Error notification */ .notify-error { background-color: #ffebee; color: #c62828; border-left: 4px solid #ef5350; } /* Info notification */ .notify-info { background-color: #e3f2fd; color: #1565c0; border-left: 4px solid #42a5f5; } /* Question notification */ .notify-question { background-color: #f3e5f5; color: #6a1b9a; border-left: 4px solid #ab47bc; } /* Close button styles */ .notify-close-button { min-width: 24px; min-height: 24px; padding: 0; margin: 0 0 0 12px; border: none; background: none; color: inherit; font-weight: bold; //cursor: pointer; } .notify-close-button:hover { background-color: rgba(0,0,0,0.1); border-radius: 12px; } CSS
Instance Attribute Summary
Attributes inherited from Core
Instance Method Summary collapse
-
#initialize(msg, options = {}) ⇒ Notify
constructor
Creates a new Notify widget with styled notification.
-
#render ⇒ Notify
Displays the notification in the application layout.
Methods inherited from Core
#hidden?, #hide, #keyboard_shortcut, #remove, #remove_keyboard_shortcut, #shortcuts, #show
Methods included from Helpers
#icon_map, #list_system_icons, #set_margin_from_opts_for
Constructor Details
#initialize(msg, options = {}) ⇒ Notify
Creates a new Notify widget with styled notification
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mittens_ui/notify.rb', line 90 def initialize(msg, = {}) @activate_timer = .fetch(:timer, true) @custom_duration = .fetch(:duration, 8000) # Setup CSS provider setup_css_provider # Root container @notify_bar = Gtk::Box.new(:horizontal, 10) @notify_bar.add_css_class('notify-container') @notify_bar.add_css_class(css_class_for()) # Message label msg_label = Gtk::Label.new(msg) msg_label. = true msg_label.xalign = 0 # Close button = Gtk::Button.new(label: '✕') .add_css_class('notify-close-button') .signal_connect('clicked') do @notify_bar.visible = false end @notify_bar.append(msg_label) @notify_bar.append() super(@notify_bar, ) end |
Instance Method Details
#render ⇒ Notify
Displays the notification in the application layout
123 124 125 126 127 128 129 |
# File 'lib/mittens_ui/notify.rb', line 123 def render layout = MittensUi::Application.layout layout.add_at_top(@notify_bar) @notify_bar.visible = true trigger_notify_timer if @activate_timer self end |