Module: Fourmi::Prawn::Utils::Extensions::VisualForm

Defined in:
lib/fourmi/prawn/utils/extensions/visual_form.rb

Instance Method Summary collapse

Instance Method Details

#visual_checkbox(name, checked = false, size: 8, white: false, form: false, at: [0, cursor]) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fourmi/prawn/utils/extensions/visual_form.rb', line 7

def visual_checkbox(name, checked = false, size: 8, white: false, form: false, at: [0, cursor])
  bounding_box(at, width: bounds.width) do
    float do
      bounding_box([0, cursor], width: size, height: size) do
        if form
          checkbox name: name, at: [0, bounds.top], checked: checked, width: bounds.width, height: bounds.height
        else
          with_fill_color 'FFFFFF' do
            fill_rectangle [0, bounds.top], bounds.width, bounds.height if white
          end
          fill_rectangle [2, bounds.height - 2], bounds.width - 4, bounds.height - 4 if checked
        end
        stroke_bounds
      end
    end
    indent(size + 7) do
      yield
    end if block_given?
  end
end

#visual_radio(parent, value:, checked: false, size: 8, white: false, form: false, at: [0, cursor]) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fourmi/prawn/utils/extensions/visual_form.rb', line 28

def visual_radio(parent, value:, checked: false, size: 8, white: false, form: false, at: [0, cursor])
  bounding_box(at, width: bounds.width) do
    float do
      bounding_box([0, cursor], width: size, height: size) do
        center_coordinates = [bounds.right / 2.0, bounds.top / 2.0]
        radius = size / 2.0

        if form
          radio parent: parent, at: [0, bounds.top], value: value, width: bounds.width, height: bounds.height
        else
          with_fill_color 'FFFFFF' do
            fill_circle center_coordinates, radius if white
          end
          fill_circle center_coordinates, radius - 2 if checked
        end
        stroke_circle center_coordinates, bounds.width / 2
      end
    end
    indent(size + 7) do
      yield
    end if block_given?
  end
end