Module: Shoes::DSL::Element

Included in:
Shoes::DSL
Defined in:
shoes-core/lib/shoes/dsl/element.rb

Overview

DSL methods for adding UI elements in Shoes applications.

See Also:

Instance Method Summary collapse

Instance Method Details

#background(color, styles = {}) ⇒ Shoes::Background

Creates a background for the current slot.

Parameters:

Returns:



23
24
25
# File 'shoes-core/lib/shoes/dsl/element.rb', line 23

def background(color, styles = {})
  create Shoes::Background, pattern(color), style_normalizer.normalize(styles)
end

#border(color, styles = {}) ⇒ Shoes::Border

Creates a border for the current slot.

Parameters:

Returns:



14
15
16
# File 'shoes-core/lib/shoes/dsl/element.rb', line 14

def border(color, styles = {})
  create Shoes::Border, pattern(color), styles
end

#button(text = nil, opts = {}, &blk) ⇒ Shoes::Button

Creates a clickable button.

Parameters:

  • text (String) (defaults to: nil)

    text to display on the button

  • blk (Proc)

    code to run when the button is clicked

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

Options Hash (opts):

  • text (String)

    text to display on the button

  • click (Proc)

    code to run when the button is clicked

Returns:



125
126
127
# File 'shoes-core/lib/shoes/dsl/element.rb', line 125

def button(text = nil, opts = {}, &blk)
  create Shoes::Button, text, opts, blk
end

#check(opts = {}, &blk) ⇒ Shoes::Check

Creates a checkbox UI element.

Parameters:

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

Options Hash (opts):

  • checked (Boolean) — default: false

    is the box checked?

Returns:



66
67
68
# File 'shoes-core/lib/shoes/dsl/element.rb', line 66

def check(opts = {}, &blk)
  create Shoes::Check, opts, blk
end

#edit_box(text = "", styles = {}) ⇒ Shoes::EditBox

Creates a multi-line UI element for entering text.

Parameters:

  • text (String) (defaults to: "")

    initial text for the edit line

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

Returns:



46
47
48
49
50
# File 'shoes-core/lib/shoes/dsl/element.rb', line 46

def edit_box(*args, &blk)
  style = pop_style(args)
  text  = args.first || ''
  create Shoes::EditBox, text, style, blk
end

#edit_line(text = "", styles = {}) ⇒ Shoes::EditLine

Creates a single line UI element for entering text.

Parameters:

  • text (String) (defaults to: "")

    initial text for the edit line

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

Options Hash (styles):

  • secret (Boolean) — default: false

    hides typed characters

Returns:



34
35
36
37
38
# File 'shoes-core/lib/shoes/dsl/element.rb', line 34

def edit_line(*args, &blk)
  style = pop_style(args)
  text  = args.first || ''
  create Shoes::EditLine, text, style, blk
end

#flow(opts = {}, &blk) ⇒ Shoes::Flow

Creates a flow container. Flows contain other UI elements, and will line them up until all available width is consumed before wrapping to another line for additional elements.

Parameters:

  • blk (Proc)

    code to place elements inside the flow

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

Options Hash (opts):

  • scroll (Boolean)

    whether the flow supports scrolling

Returns:



102
103
104
# File 'shoes-core/lib/shoes/dsl/element.rb', line 102

def flow(opts = {}, &blk)
  create Shoes::Flow, opts, blk
end

#list_box(opts = {}, &blk) ⇒ Shoes::ListBox

Creates a list box UI element.

Parameters:

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

Options Hash (opts):

  • items (Array)

    list of items to show in the list

  • choose (String)

    item to select in list

Returns:



90
91
92
# File 'shoes-core/lib/shoes/dsl/element.rb', line 90

def list_box(opts = {}, &blk)
  create Shoes::ListBox, opts, blk
end

#progress(opts = {}, &blk) ⇒ Shoes::Progress

Creates a progress bar UI element.

Parameters:

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

Options Hash (opts):

  • fraction (Float) — default: 0.0

    progress complete, from 0.0 to 1.0

Returns:



57
58
59
# File 'shoes-core/lib/shoes/dsl/element.rb', line 57

def progress(opts = {}, &blk)
  create Shoes::Progress, opts, blk
end

#radio(group = "", opts = {}) ⇒ Shoes::Radio

Creates a radio button UI element.

Parameters:

  • group (String) (defaults to: "")

    radio group associated with this element

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

Options Hash (opts):

  • checked (Boolean) — default: false

    is the radio selected?

  • group (String) — default: ""

    associated radio group

Returns:



78
79
80
81
82
# File 'shoes-core/lib/shoes/dsl/element.rb', line 78

def radio(*args, &blk)
  style = pop_style(args)
  group = args.first
  create Shoes::Radio, group, style, blk
end

#stack(opts = {}, &blk) ⇒ Shoes::Flow

Creates a stacked container. Stacks contain other UI elements and after each item wraps to a new line.

Parameters:

  • blk (Proc)

    code to place elements inside the stack

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

Options Hash (opts):

  • scroll (Boolean)

    whether the stack supports scrolling

Returns:



113
114
115
# File 'shoes-core/lib/shoes/dsl/element.rb', line 113

def stack(opts = {}, &blk)
  create Shoes::Stack, opts, blk
end