简体   繁体   中英

Insert rounded rectangle into a Prawn table cell ruby

I am trying to recreate this in Prawn but could not get the rounded rectangles inside the table cell.

在此处输入图片说明

I have used Prawn table and here is my code -

tabledata = [["City", "Count" ],
            ["Atlanta", '888'],
            ["New York", '888' ]]


bounding_box([10, cursor], height: 150, width: 300) do
            table(tabledata, :header => true, :column_widths => [250, 50], :cell_style => { :size => 10.5, style: :bold_italic, :height => 24 } ) do
                cells.padding = 6
                row(0).background_color = "edf0f3"
                row(1..3).column(1).background_color = "A61919"
                row(0).text_color = '5D7383'
                row(1..3).column(1).text_color = 'FFFFFF'
                row(1..3).column(0).text_color = '606060'
                row(0..3).borders = [:bottom]
                row(0..3).border_color = 'e0e9eD'
                row(0).border_width = 0.5
                column(1).style(:align => :center)
 end

I am trying to get this bubble inside the table cell. If I replace '888' with 'bubble' it gives me an error - Prawn::Errors::UnrecognizedTableContent (Prawn::Errors::UnrecognizedTableContent)

def bubble
    stroke do
        fill_color "A61919"
        fill_rounded_rectangle [0, cursor + 5], 45, 20, 10
    end
end

Table data is just data and if you replace 888 with bubble , you are executing the method at the moment of definition of tabledata and it inserts the result of the method which, I guess, leads to the error you are getting.

You can try implementing a subclass of Prawn::Table::Cell::Text and override the #draw_background . Then create an instance of this class and put it in tabledata instead of the string 888 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM