Class: MittensUi::Separator

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

Overview

A visual divider used to separate sections of a UI. Wraps Gtk::Separator. Vertical separators are automatically wrapped in a horizontal Gtk::Box with a minimum height so they render correctly in any layout context.

Examples:

Horizontal separator (default)

MittensUi::Separator.new

Vertical separator

MittensUi::Separator.new(:vertical)

With margin

MittensUi::Separator.new(:horizontal, top: 10, bottom: 10)

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(orientation = :horizontal, options = {}) ⇒ Separator

Creates a new Separator widget.

Parameters:

  • orientation (Symbol) (defaults to: :horizontal)

    the orientation of the separator. Accepted values are :horizontal (default) and :vertical

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

    configuration options

Options Hash (options):

  • :height (Integer) — default: 50

    height of the container in pixels. Only applies to :vertical orientation.

  • :width (Symbol) — default: :full

    column width in the layout grid

  • :top (Integer)

    top margin in pixels

  • :bottom (Integer)

    bottom margin in pixels

  • :left (Integer)

    left margin in pixels

  • :right (Integer)

    right margin in pixels

  • :defer_render (Boolean) — default: false

    skip auto-rendering into layout



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mittens_ui/separator.rb', line 34

def initialize(orientation = :horizontal, options = {})
  unless %i[horizontal vertical].include?(orientation)
    raise ArgumentError, 'orientation must be :horizontal or :vertical'
  end

  gtk_orientation =
    orientation == :horizontal ? Gtk::Orientation::HORIZONTAL : Gtk::Orientation::VERTICAL

  @separator = Gtk::Separator.new(gtk_orientation)

  widget = if orientation == :vertical
      height = options[:height] || 100

      container = Gtk::Box.new(Gtk::Orientation::HORIZONTAL, 0)
      container.set_size_request(10, height)

      @separator.set_size_request(2, height)
      @separator.hexpand = false
      @separator.vexpand = true

      container.append(@separator)
      container
    else
      @separator.hexpand = true
      @separator
    end

  super(widget, options)
end