Module: Lich::Common::GUI::Components
- Defined in:
- documented/common/gui/components.rb
Class Method Summary collapse
-
.create_button(label: nil, css_provider: nil) ⇒ Gtk::Button
Creates a new button with an optional label and CSS provider.
-
.create_button_box(buttons, expand: false, fill: false, padding: 5) ⇒ Gtk::Box
Creates a horizontal button box containing the specified buttons.
-
.create_labeled_entry(label_text, entry_width: 15, password: false) ⇒ Hash
Creates a labeled entry field with an optional password visibility.
-
.create_notebook(pages, tab_position: :top, show_border: true, css_provider: nil) ⇒ Gtk::Notebook
Creates a notebook widget with the specified pages and settings.
Class Method Details
.create_button(label: nil, css_provider: nil) ⇒ Gtk::Button
Creates a new button with an optional label and CSS provider.
12 13 14 15 16 |
# File 'documented/common/gui/components.rb', line 12 def self.(label: nil, css_provider: nil) = label ? Gtk::Button.new(label: label) : Gtk::Button.new .style_context.add_provider(css_provider, Gtk::StyleProvider::PRIORITY_USER) if css_provider end |
.create_button_box(buttons, expand: false, fill: false, padding: 5) ⇒ Gtk::Box
Creates a horizontal button box containing the specified buttons.
26 27 28 29 30 31 32 33 34 |
# File 'documented/common/gui/components.rb', line 26 def self.(, expand: false, fill: false, padding: 5) box = Gtk::Box.new(:horizontal) .each do || box.pack_end(, expand: , fill: fill, padding: padding) end box end |
.create_labeled_entry(label_text, entry_width: 15, password: false) ⇒ Hash
Creates a labeled entry field with an optional password visibility.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'documented/common/gui/components.rb', line 43 def self.create_labeled_entry(label_text, entry_width: 15, password: false) label = Gtk::Label.new(label_text) label.set_width_chars(entry_width) entry = Gtk::Entry.new entry.visibility = !password if password pane = Gtk::Paned.new(:horizontal) pane.add1(label) pane.add2(entry) { label: label, entry: entry, box: pane } end |
.create_notebook(pages, tab_position: :top, show_border: true, css_provider: nil) ⇒ Gtk::Notebook
Creates a notebook widget with the specified pages and settings.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'documented/common/gui/components.rb', line 65 def self.create_notebook(pages, tab_position: :top, show_border: true, css_provider: nil) notebook = Gtk::Notebook.new notebook.set_tab_pos(tab_position) notebook.show_border = show_border if css_provider notebook.style_context.add_provider(css_provider, Gtk::StyleProvider::PRIORITY_USER) end # Track tab indices to avoid hardcoding page numbers notebook.define_singleton_method(:tab_indices) do @tab_indices ||= {} end pages.each do |page| label = page[:label] index = notebook.append_page(page[:widget], Gtk::Label.new(label)) notebook.tab_indices[label] = index end notebook end |