In our last article on smart frames, we built a SmartShape that maintained a constant border-thickness, no matter the size of the shape.
It was a fairly simple frame, it got the job done, but it had a uniform frame-thickness all the way around, and offered no way for an end-user to change that thickness.
In this article, we’ll add some flexibility to the shape by making separate margin parameters for each side. We’ll also expose the margin settings to the user via Shape Data fields.
Freedom for All Sides!
The best part about a smart frame is that the border stays the same when we resize the shape. But that doesn’t mean we want the border to be the same thickness all the way ‘round!
Monitors and displays are often thicker on the bottom. Racks have thin rails for sides, and thicker bits on top and at the bottom. One might start to think of drawing frames for title blocks and zones that allow more space on one side for hole-punches and binding. The list of examples is endless.
So lets free up our sides! The first step is to add three more User-defined Cells section, so that we can control the thickness of each side of the frame.
So whip out a copy of your shape from the first article, and open up the ShapeSheet. You can add user cells by:
- Placing your cursor in an existing User-defined cell
- Choosing Insert Row from the menu
Do this three times. Then rename the original cell, and give the new ones names. You should see something like this when you’re done:
You can set the values to whatever you feel like. But only User.marginLeft will have any sway, because we haven’t linked the geometry to the new cells.
Re-smarten the Geometry
Geometry 2 represents our inner-frame, and it needs to be modified to take advantage of our new parameters. I could go on about the theory, but it’s probably easiest to just copy the new formulas shown in the ShapeSheet below.
Remember, if you get lost in the vertex-soup, you can always look for that black dot in the drawing window. It visually shows you which vertex is represented by the geometry cell in which your cursor is currently sitting!
Now you can individually specify a value for each margin! Go ahead, enter some wacky values and take your new shape for a spin!
Above, you can see four different margin thicknesses. But the margins still maintain their sizes, no matter how we stretch the shape!
Link to Shape Data Fields
Now, let’s give our end-users access to the frame’s settings. And no, you Visio die-hards, Window > Show ShapeSheet is not an end-user feature!
We’re going to expose the user-cells to the world by linking them to Shape Data fields (Custom Properties for Visio-2003-and-earlier users)
Now, Visio has a nice user-interface for adding Shape Data fields, but since we’re already in the ShapeSheet, we’ll do it the programmer way:
- Right-click somewhere in your ShapeSheet Window
- Choose: Insert Section…
- Check Shape Data
You’re done! You should have a shiny new Shape Data section, with one row in it:
Not extremely useful or interesting, except that if you go back to the drawing window and select your shape, you’ll notice that the Shape Data window displays your brand-new field! (Note: you might have to turn the window on via: View > Shape Data Window)
Now the obvious thing to do would be to add three more rows of Shape Data and link each one of them to the corresponding User-cell. But let’s not be so obvious!
You see, the neat thing about having both the User-defined cells and the Shape Data fields is that we can choose what to expose to the user.
I mentioned earlier the case of monitors and displays. They usually have equal thicknesses for the left, top, and right sides, but the bottom is thicker—it adds a stabilizing visual weight to the aesthetic.
So lets just add two Shape Data fields. One for the margins on the left, top and right, and another for the bottom. I’ll let you figure out how to get your Shape Data section to look like this:
|Prop.MarginLTR||Left, top, right margin||2||5 in|
|Prop.MarginBottom||Bottom margin||2||5 in|
The Label cell is what the user sees in the Shape Data window. You can add some pretty text so that the user doesn’t have to read MarginLTR and get scared.
Type = 2 tells Visio that this field should hold a number (or a value-unit pair.) If the user enters “Bob” in the Shape Data window, Visio will complain that Bob is not a number. But 2in, 3mm, 4miles, etc. will be perfectly fine.
Re-smarten the User-cells
Now your geometry cells are just as smart as they were before we added the Shape Data. But the User-cells are now the weak-link. They still don’t know diddly about the user-interface, and the new parameters we just added.
Soooooo hook ‘em up, cowboy!
By the way, you create cell-reference formulas just like you do in Excel:
- Put your cursor in User.marginLeft
- Type “=” (cell waits for more info)
- Click on the Value cell in Prop.MarginLTR
- Hit Enter
Sounds familiar, eh?
You can download a Visio drawing containing this version of the smart frame and and check your own version against it:
Download “How to Make Smart Frames and Bezels #2”s!Aj0wJuswNyXlhVXo4gF0rQ7tQqeG – Downloaded 988 times – 103 B
In the next article on Smart Frames and Bezels, we’ll add a way for users to directly manipulate the frame borders using control handles, so stay tuned!
Be sure and read our previous articles on How to Build Smart Frames and Bezels: