Class: MittensUi::Label

Inherits:
Core
  • Object
show all
Defined in:
lib/mittens_ui/label.rb

Overview

A simple wrapper around a GTK4::Label for use with MittensUi::Core.

This class ensures the provided text is non-empty and initializes a GTK4 label widget, then delegates common setup to MittensUi::Core.

Examples:

label = MittensUi::Label.new("Hello")
label = MittensUi::Label.new(nil) # => uses "Label"

Examples:

Passing options to Core

MittensUi::Label.new("Hi", expand: true, margin: 8)

See Also:

Instance Attribute Summary

Attributes inherited from Core

#core_widget

Instance Method Summary collapse

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(text, options = {}) ⇒ MittensUi::Label

Create a new Label wrapper.

Parameters:

  • text (String, nil)

    The label text. If nil or blank, defaults to “Label”.

  • options (Hash) (defaults to: {})

    Options forwarded to MittensUi::Core (e.g., layout/ styling keys).

Options Hash (options):

  • :margin (Integer)

    Margin around the widget (optional).

  • :expand (Boolean)

    Whether the widget should expand (optional).



29
30
31
32
33
34
# File 'lib/mittens_ui/label.rb', line 29

def initialize(text, options = {})
  text = 'Label' if text.nil? || text.to_s.strip.empty?

  gtk_label = Gtk::Label.new(text)
  super(gtk_label, options)
end

Instance Method Details

#textString

Returns the current label text.

Returns:

  • (String)

    returns the current label text.



37
38
39
# File 'lib/mittens_ui/label.rb', line 37

def text
  @core_widget.label
end

#text=(value) ⇒ Object

Parameters:

  • value (String)

    A String value that the label gets set to



42
43
44
# File 'lib/mittens_ui/label.rb', line 42

def text=(value)
  @core_widget.set_label(value.to_s)
end