I'm trying to design a fold-down table that is going to be attached to a wall with its legs folded under it when in down position. The problem is -- there is less space under the table top than is necessary for a leg that would reach all the way to the floor. Think top reaching floor when folded, so when unfolded it needs support that is as long as the top is deep. But wall mount (a horizontal bar with piano hinge) takes up space needed by the folded leg.
So to solve that I'm planning to fold part of the leg itself by connecting L-shaped assembly of 3 cubes all rotating against each other. Pretty much exactly like is done in this wooden cube puzzle.
When extended and unfolded leg would stand on the last cube, when folded cubes would fold flat under the top.
Question is, how to join the parts? Joint won't be load bearing, but should be fairly tight without wearing down wood after repeated rotating.
UPDATE: Below is a rough illustration of folded leg on the left and unfolded on the right. Difference between pictures is cubes are rotated 180 degrees around red axes.
UPDATE2: Here is how wall/top/leg(s) are related. Red arcs are folding points (piano hinges). Blue lines are of equal size. So first leg folds up to the top, then top folds down to the wall. Idea is that folded top lays flat against the wall and looks pretty, hiding leg assembly under some trim (thus I'm going for fold down instead of fold up). There will be a second leg on the other side as well (with a bar between them if needed).
I want the table to be fairly stable and support a decent load, thus top resting on the wall mount when unfolded and not just hanging from the hinge.