Method: Prawn::Document#checkbox
- Defined in:
- lib/barkest_core/extensions/prawn_document_extensions.rb
#checkbox(x, y, options = { }) ⇒ Object
Creates a small box that can be used as a checkbox.
The x and y parameters are absolute positions for the checkbox.
Valid options:
- checked
-
If set, the box will be marked with an X.
- stroke_width
-
The line width to draw the checkbox with. Defaults to 0.5.
- size
-
The size of the checkbox. Defaults to 8.0.
- rounded
-
Set to true to have rounded corners. Defaults to false.
- color
-
The color to draw the checkbox in. Defaults to ‘000000’ (black).
- label
-
An optional label to follow the checkbox.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/barkest_core/extensions/prawn_document_extensions.rb', line 217 def checkbox(x, y, = { }) = { stroke_width: 0.5, size: 8, rounded: false, color: '000000' }.merge( || {}) stored_line_width = line_width stored_color = stroke_color self.line_width = [:stroke_width] self.stroke_color = [:color] if [:rounded] stroke_rounded_rectangle [x, y], [:size], [:size], [:size] * 0.2 else stroke_rectangle [x, y], [:size], [:size] end if [:checked] self.stroke_color = '000000' self.line_width = [:size] * 0.125 offset = [:size] * 0.1 stroke_line [x + offset, y - offset], [x + [:size] - offset, y - [:size] + offset] stroke_line [x + offset, y - [:size] + offset], [x + [:size] - offset, y - offset] end self.line_width = stored_line_width self.stroke_color = stored_color unless [:label].blank? text_box [:label], at: [x + [:size] + 2.pt, y] end end |