User-specific colour

I was showing a prospective client some samples of my work a couple days ago. She liked what she was seeing except for one thing. “Can you get rid of all that white background; I can’t see a thing!”

First of all, I gave an inner wince, because I like my white backgrounds (assuming I have put a small bit of colour elsewhere). I’ve found that once clients ask for things like this, the database is well on the way to looking like Clown Puke, as described in my post on May 26, 2010.

… and that’s a slippery slope, friend.

However, I just had new business cards printed that list my title as “FileMaker Database Superhero” (seriously!), so I don’t like to leave a citizen in distress.

I asked my client-to-be, “How about if I give you the option of picking your background colour?” That sounded great to her. Now … how to make that happen?

I’ve created a quick layout with a plain white background. I can see how it may not seem attractive in this form.

I have also created a Prefs table, with the following layout (which the client will never see):

You’ll see that it has a repeating field to hold the five colours that the user can select, and a global container field to hold the selected colour.

Now let’s draw a square under each of the repetitions. These will be the five colours that you can select as backgrounds. White should be the first one. I’ve drawn them on a black background so that you can see them easier.

I made each of those squares 19×19 pixels, for no particular reason. They could have been 1×1 pixel squares, and still served our purpose.

Now you need to go select each of those squares (one at a time), copy them, and paste them into each repetition of the colours field. It will end up looking like this in Browse Mode.

Now let’s set up a relationship between these two tables:

Notice the X in the box between them. This is a Cartesian join. Which means that all records in Client match all records in Prefs. So it doesn’t really matter what fields I use for the match. I used the primary keys — just because.

The next thing we’re going to do is write a very short script that looks like this:

If this script looks a little cryptic at this point, well don’t think twice, it’s all right, Bob! We’ll get you there.

Now let’s return to our original Client layout. Back to Layout Mode, campers.

The first thing we’re going to do is put the zdg_selectedColour field on this layout. There are a few things you have to do to it:

  1. Don’t give it a field label.
  2. Make it cover the entire layout.
  3. Make sure it has no field borders (in the Object area of the Appearance tab on the Inspector).
  4. Move it to the back of the layout so it isn’t covering everything, by clicking the Send to Back button on the Arrange & Align area of the Inspector’s Position tab.
  5. Make the field un-enterable, by deselecting the Browse Mode and Find Mode boxes in the Behavior area of the Inspector’s Data tab.
  6. In the Data Formatting area of the Inspector’s Data tab,  for Format, select “Reduce or Enlarge Image to Fit”, and uncheck “Maintain original proportions”.

We need to put a few more fields on the layout. Up in the top right corner of the layout, put a field there. Select the Prefs::colours field, and perform the following steps on it that we just did on the background field: 1, 3, 5, 6.

This is the first repetition of the colour field. Duplicate that field, but go to the Inspector > Data > Field > Show repetitions area. Tell it that you want to show “2 to: 2″. Then you want duplicates that show the third, fourth, fifth repetitions.

We’ll put them all on top of a grey rectangle, so that the result looks like this in Browse Mode:

We just need to do one more thing. As John Lee Hooker used to say, “Boogie to Layout Mode, chillun” (an approximate quote).

Each of those five colour fields needs to be made into a button. Select the first one, and then select Button Setup from the Format menu. It needs to Perform Script, using the following options:

We selected our new script, and specified a script parameter of “1″.

On the next colour field, do the exact same thing, but specify a script parameter of “2″, and so on until you’ve made all five of the fields into buttons.

So getting back to that script we created, we are using it to say the following: “Please take the number I send you as a script parameter, and grab that repetition of the colour field. Set it into the background colour field.”

Go back into Browse Mode and start clicking on those colours. You should see your background colour change. Click a few more, and be amazed by what you have created. Now ask your spouse to watch as you click a few more times. This may be the time to grumble that your spouse doesn’t understand you, because he/she was nowhere near as excited about this as you.

That’s okay. I understand you.

Notes:

  1. That’s not to say that the addition of background colour automatically makes a layout look like Clown Puke. I’ve seen some amazing layouts that have the perfect blend of colours to look really classy — while remaining easy to read. That’s just a difficult thing to do for those of us who are mere mortals without graphic design training. I suspect it could also take a little longer than a lot of clients are willing to pay.
  2. Why did I do it this way, instead of just colouring the background. There are other people who will be using this database. They may want a different colour — or no colour at all.
  3. One other thing you should probably do is set up auto-resizing to make sure your background field always covers the entire background, no matter what a user may resize your window to. Check out my post from July 10, 2010 to see how to do that.
  4. By the way, I remember learning in a high school marketing class, that the most visible combination is black text on a yellow background. I went through a phase of trying to make that work, but it often looked like someone had peed on my layout. I try to make sure that my databases don’t make people think about urine.
  5. In a multi-user situation, I would probably set this preference up in a user table, so that users don’t have to reselect their favourite background colour every time they log in.
  6. Repeating fields are often a bad thing to use in FileMaker Pro. They are a really bad idea for holding any real data. However, for settings like this, they can be handy.

Paul Spafford
FMLayoutMode.com
Spafford Data Solutions

Leave a comment

5 Comments.

  1. I’ve had a problem with a 1 pixel white border whenever I’ve used a container field as the background, no matter what parameters I’ve tried to adjust. I’ve not developed in 11 yet, though; has 11 solved this problem?

  2. Anthony,
    Container fields with 1px images as backgrounds do not work on Windows platforms when using standard image formats. For what its worth .pict images work ok, but according to documentation, this format may not be supported in future version.

    All,
    A better way to do this for cross platform compatibility would be store colours as integer values and a text field containing char(9600) set at some ridiculous size.
    You can then change the colour with the TextColor() function.

    I have implemented this throughout my solution and its working well cross platform, including FM Go.

    If you interested, here is a small video of it in action, ignoring the labels I have given each selection :-P
    http://bit.ly/cqXv00

    I use a free plugin to provide a colour picker, thus giving my clients the ability to set a colour scheme which suits them best, although this is not required

    I also use a custom function, which determines the brightness of the chosen colour and allows me to change the text to either white or black using conditional formatting to keep it visible.

    As for the rounded borders, I ended up using conditional formatting and pre-setting a number of colours for this.

    For what its worth, it may seem like over-kill.. but with the release of our solutions latest version we had a number of clients who where not happy with our default colours, this addition has kept all of our clients happy.

    Steve.

  3. Thanks Steve. What I meant was that whenever I’ve used a container field as the background to a layout, set to cover the whole width and height (anchored on all edges), and with an image (not 1 pixel) inside it, a 1 pixel white border is visible around every edge. I have tried various adjustments to border pixel size, colour, etc to get this 1 pixel border to disappear but to no avail. I remember this being a known issue for a recent version of FileMaker – FileMaker 9? – and I am currently developing in 10 (because of plug-in compatibility issues) and the problem is still there. Hence my original question, has the problem been solved in 11? Or have I missed something?

    That aside, your suggested approach looks interesting. (I watched the video.) Are you using ScriptMaster to generate the colour picker?

    Finally, Paul, this blog entry states that there are three comments but I can only see two.

    Anthony.

  4. Very cool technique, Steve. I love seeing creative uses for Conditional Formatting!

    Anthony: I have the same issue with the white border. I’ve tried everything I can think of to get rid of it, but no joy (and I’m using FileMaker 11). Please report this to FileMaker as a bug, and I will do the same (the more reports the better). When we specify a border line of “None” that’s what we should be able to expect.

    Re the comment count. I’m subscribed to a service that lists tweets that mention each article — you’ll see it down at the bottom of the page, under the “Leave a Reply” box. WordPress counts that as one comment.

    Thanks!

Leave a Reply


[ Ctrl + Enter ]

Trackbacks and Pingbacks: