Table header/Table column background color

147 views
Skip to first unread message

AuraWind

unread,
Sep 8, 2008, 3:41:46 PM9/8/08
to Prawn
Hello,

I'm currently using the Prawn library (and loving it) and found absent
functionality I think may be beneficial to users.

I think it would be great to be able to specify a table header
background color (in the same spirit as row_colors).

Many of the mockups I receive from my designers like to make the
header more distinguishable from the data and using a background color
is a common solution.

Also, there are times where I'll have a 2 column table with the
"headers" on the left side and the data on the right.

e.g.

Name | John Doe
Company | Some Company
Date | 01/01/2008

"column_colors" would be useful in cases where I want to have all the
left columns share the same background color.

Thanks and keep up the great work!

Gregory Brown

unread,
Sep 8, 2008, 10:54:14 PM9/8/08
to prawn...@googlegroups.com
On Mon, Sep 8, 2008 at 3:41 PM, AuraWind <aura...@gmail.com> wrote:
>
> Hello,
>
> I'm currently using the Prawn library (and loving it) and found absent
> functionality I think may be beneficial to users.

I'm not moving ahead on feature enhancements until I do some major
core stabilization, but I imagine I'll be able to get back to this
stuff reasonably soon...
I'm happy to look over requests, though:

> I think it would be great to be able to specify a table header
> background color (in the same spirit as row_colors).
>
> Many of the mockups I receive from my designers like to make the
> header more distinguishable from the data and using a background color
> is a common solution.

I will probably allow full control of styling of header cells
eventually, but this one is easy. Please file a ticket in lighthouse.
I'll put it on hold but it should be a simple feature to implement
once I get around to it. (And patches are welcome)

> Also, there are times where I'll have a 2 column table with the
> "headers" on the left side and the data on the right.
>
> e.g.
>
> Name | John Doe
> Company | Some Company
> Date | 01/01/2008
>
> "column_colors" would be useful in cases where I want to have all the
> left columns share the same background color.

I'll also probably eventually support full column style tweaking.
However, I'm not sure the best way to support something like 'column 0
gray, column 1..n white'

What did you have in mind, interface wise?

> Thanks and keep up the great work!

Thanks for sharing your suggestions.

-greg

--
Technical Blaag at: http://blog.majesticseacreature.com | Non-tech
stuff at: http://metametta.blogspot.com

AuraWind

unread,
Sep 9, 2008, 10:06:19 AM9/9/08
to Prawn
On Sep 8, 8:54 pm, "Gregory Brown" <gregory.t.br...@gmail.com> wrote:
>
> I'll also probably eventually support full column style tweaking.
> However, I'm not sure the best way to support something like 'column 0
> gray, column 1..n white'
>
> What did you have in mind, interface wise?

I'm a pretty big fan of the way you set up row_colors however I can
see issues when you throw column_colors in the mix. If you decided on
one taking precedence over the other, I think it'll be equally easy to
use as row_colors and stay consistent in how someone expects to do
this kind of formatting.

I'm sure it's easier said than done.

hans-christian

unread,
Sep 10, 2008, 2:01:48 AM9/10/08
to Prawn
> I think it would be great to be able to specify a table header
> background color (in the same spirit as row_colors).
>
> Many of the mockups I receive from my designers like to make the
> header more distinguishable from the data and using a background color
> is a common solution.

In the meantime, you could solve this problem the same way we do it.

header do
fill_color = BACKGROUND_COLOR
fill_rectangle(TOP_LEFT, RIGHT, HEIGHT)
fill_color = TEXT_COLOR

text "TEXT"
end

AuraWind

unread,
Sep 11, 2008, 11:25:00 AM9/11/08
to Prawn
> header do
>   fill_color = BACKGROUND_COLOR
>   fill_rectangle(TOP_LEFT, RIGHT, HEIGHT)
>   fill_color = TEXT_COLOR
>
>   text "TEXT"
> end

Thanks for the suggestion but unfortunately it won't work in my
situation. The header seems to be drawn last so it will completely
overlay my content's table header. Maybe layer support like iText
would be a good feature for Prawn? Not particularly to solve my
problem but for other instances.

I was able to do achieve the correct effect by rendering the rectangle
prior to the table but it won't work on a table that flows over
multiple pages.

I went ahead and modified the library to support a :header_color
option for tables.

Gregory Brown

unread,
Sep 11, 2008, 11:30:24 AM9/11/08
to prawn...@googlegroups.com
On Thu, Sep 11, 2008 at 11:25 AM, AuraWind <aura...@gmail.com> wrote:
>
>> header do
>> fill_color = BACKGROUND_COLOR
>> fill_rectangle(TOP_LEFT, RIGHT, HEIGHT)
>> fill_color = TEXT_COLOR
>>
>> text "TEXT"
>> end
>
> Thanks for the suggestion but unfortunately it won't work in my
> situation. The header seems to be drawn last so it will completely
> overlay my content's table header. Maybe layer support like iText
> would be a good feature for Prawn? Not particularly to solve my
> problem but for other instances.

I need to take a deeper look into whether z-ordering is complicated.
It's a feature than many wanted in PDF::Writer but was never
implemented. I'll read up on the spec once I've cleaned up the core,
and see what the details are. If anyone wants to get a head start and
read up on this and then share notes with me, that'd be great.

> I was able to do achieve the correct effect by rendering the rectangle
> prior to the table but it won't work on a table that flows over
> multiple pages.
>
> I went ahead and modified the library to support a :header_color
> option for tables.

Can you bring up a fork on github and share this code? If it's fairly
straightforward, I'll merge it.

AuraWind

unread,
Sep 11, 2008, 12:59:19 PM9/11/08
to Prawn
> Can you bring up a fork on github and share this code?  If it's fairly
> straightforward, I'll merge it.

Sure, I really have no idea what I'm doing when it comes to git.
Hopefully this is what you wanted.

http://github.com/AuraWind/prawn/commit/37ede353421ecfa07ef07f087905b95eb7012189

Gregory Brown

unread,
Sep 11, 2008, 1:02:05 PM9/11/08
to prawn...@googlegroups.com

yep, that looks pretty simple, too.

Can you add an example that shows how it works under examples/ ?

I'll pull this in, probably not for 0.2 because I'm about to make that
snapshot, but immediately after that, and it will be in 0.3 if I don't
implement full header tweaking functionality by then.

AuraWind

unread,
Sep 11, 2008, 1:16:39 PM9/11/08
to Prawn
> Can you add an example that shows how it works under examples/ ?

Sure thing, I've added one under my fork.

Gregory Brown

unread,
Sep 11, 2008, 1:18:20 PM9/11/08
to prawn...@googlegroups.com
On Thu, Sep 11, 2008 at 1:16 PM, AuraWind <aura...@gmail.com> wrote:
>
>> Can you add an example that shows how it works under examples/ ?
>
> Sure thing, I've added one under my fork.

Great, I'm going to try to get that 0.2 snapshot out today, I'll pull
this into master just after that.

Thanks!

Reply all
Reply to author
Forward
0 new messages