Class: RubyJard::Layouts

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruby_jard/layouts.rb,
lib/ruby_jard/layouts/tiny_layout.rb,
lib/ruby_jard/layouts/wide_layout.rb,
lib/ruby_jard/layouts/narrow_vertical_layout.rb,
lib/ruby_jard/layouts/narrow_horizontal_layout.rb

Overview

Layouts registry.

Constant Summary collapse

TinyLayout =
RubyJard::Templates::LayoutTemplate.new(
  min_height: 10,
  fill_height: false,
  children: [
    RubyJard::Templates::LayoutTemplate.new(
      height_ratio: 80,
      width_ratio: 100,
      min_height: 7,
      fill_height: true,
      children: [
        RubyJard::Templates::ScreenTemplate.new(
          screen: :source,
          height_ratio: 100
        )
      ]
    ),
    RubyJard::Templates::ScreenTemplate.new(
      height: 2,
      screen: :menu
    )
  ]
)
WideLayout =
RubyJard::Templates::LayoutTemplate.new(
  min_width: 120,
  min_height: 24,
  fill_height: false,
  children: [
    RubyJard::Templates::LayoutTemplate.new(
      height_ratio: 80,
      width_ratio: 50,
      children: [
        RubyJard::Templates::ScreenTemplate.new(
          screen: :source,
          height_ratio: 70,
          adjust_mode: :expand
        ),
        RubyJard::Templates::ScreenTemplate.new(
          screen: :backtrace,
          height_ratio: 30,
          min_height: 3
        )
      ]
    ),
    RubyJard::Templates::LayoutTemplate.new(
      height_ratio: 80,
      width_ratio: 50,
      children: [
        RubyJard::Templates::ScreenTemplate.new(
          screen: :variables,
          height_ratio: 80,
          adjust_mode: :expand
        ),
        RubyJard::Templates::ScreenTemplate.new(
          screen: :threads,
          height_ratio: 20,
          min_height: 3
        )
      ]
    ),
    RubyJard::Templates::ScreenTemplate.new(
      height: 2,
      screen: :menu
    )
  ]
)
NarrowVerticalLayout =
RubyJard::Templates::LayoutTemplate.new(
  min_width: 40,
  min_height: 24,
  fill_height: false,
  children: [
    RubyJard::Templates::LayoutTemplate.new(
      height_ratio: 80,
      width_ratio: 100,
      children: [
        RubyJard::Templates::ScreenTemplate.new(
          screen: :source,
          height_ratio: 60
        ),
        RubyJard::Templates::ScreenTemplate.new(
          screen: :variables,
          height_ratio: 40
        )
      ]
    ),
    RubyJard::Templates::ScreenTemplate.new(
      height: 2,
      screen: :menu
    )
  ]
)
NarrowHorizontalLayout =
RubyJard::Templates::LayoutTemplate.new(
  min_width: 80,
  min_height: 10,
  fill_height: false,
  children: [
    RubyJard::Templates::LayoutTemplate.new(
      height_ratio: 80,
      width_ratio: 100,
      children: [
        RubyJard::Templates::ScreenTemplate.new(
          screen: :source,
          width_ratio: 60
        ),
        RubyJard::Templates::ScreenTemplate.new(
          screen: :variables,
          width_ratio: 40
        )
      ]
    ),
    RubyJard::Templates::ScreenTemplate.new(
      height: 2,
      screen: :menu
    )
  ]
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fallback_layout = RubyJard::Layouts::WideLayout) ⇒ Layouts

Returns a new instance of Layouts.



24
25
26
27
# File 'lib/ruby_jard/layouts.rb', line 24

def initialize(fallback_layout = RubyJard::Layouts::WideLayout)
  @layout_registry = {}
  @fallback_layout = fallback_layout
end

Instance Attribute Details

#fallback_layoutObject (readonly)

Returns the value of attribute fallback_layout.



22
23
24
# File 'lib/ruby_jard/layouts.rb', line 22

def fallback_layout
  @fallback_layout
end

Class Method Details

.instanceObject



17
18
19
# File 'lib/ruby_jard/layouts.rb', line 17

def instance
  @instance ||= new
end

Instance Method Details

#[](name) ⇒ Object Also known as: get



37
38
39
# File 'lib/ruby_jard/layouts.rb', line 37

def [](name)
  @layout_registry[name.to_s.strip]
end

#add_layout(name, layout_class) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/ruby_jard/layouts.rb', line 29

def add_layout(name, layout_class)
  unless layout_class.is_a?(RubyJard::Templates::LayoutTemplate)
    raise RubyJard::Error, "#{layout_class} must be a #{RubyJard::Templates::LayoutTemplate}"
  end

  @layout_registry[name] = layout_class
end

#each(&block) ⇒ Object



42
43
44
# File 'lib/ruby_jard/layouts.rb', line 42

def each(&block)
  @layout_registry.each(&block)
end