Move legend from key function to legend function.

legend function may be called repeatedly, with posititioning and sizing parameters to place multiple legends on a key.
This commit is contained in:
Myles Metzler 2018-02-25 00:21:42 -05:00
parent d7311d2dac
commit ad86c1a7a9
4 changed files with 28 additions and 8 deletions

View File

@ -38,3 +38,6 @@ for (p = [0:len(key_profiles)-1]) {
} }
/* translate_u(0, 0) one_row_profile("oem"); */ /* translate_u(0, 0) one_row_profile("oem"); */
dcs_row(3) cherry() legend("X", "top", "left", 3) legend("X") key(true);
translate_u(1, 0) dcs_row(3) cherry() legend("M", "top", "left", 3) legend("Z") key(true);

View File

@ -161,10 +161,12 @@ module top_of_key(){
} }
} }
module keytext(text, depth = 0) { module keytext(text, halign, valign, font_size, depth) {
translate([0, 0, -depth]){ woffset = (top_total_key_width()/3.5) * (halign == "center" ? 0 : halign == "left" ? -1 : 1);
hoffset = (top_total_key_height()/3.5) * (valign == "center" ? 0 : valign == "bottom" ? -1 : 1);
translate([woffset, hoffset, -depth]){
linear_extrude(height=$dish_depth){ linear_extrude(height=$dish_depth){
text(text=text, font=$font, size=$font_size, halign="center", valign="center"); text(text=text, font=$font, size=font_size, halign="center", valign="center");
} }
} }
} }
@ -217,10 +219,12 @@ module clearance_check() {
} }
// legends / artisan support // legends / artisan support
module artisan(legend, depth) { module artisan(depth) {
top_of_key() { top_of_key() {
// outset legend // outset legend
if (legend != "") keytext(legend, depth); for (i=[0:len($legends)-1]) {
keytext($legends[i][0], $legends[i][1], $legends[i][2], $legends[i][3], depth);
}
// artisan objects / outset shape legends // artisan objects / outset shape legends
children(); children();
} }
@ -244,19 +248,19 @@ module keytop() {
// The final, penultimate key generation function. // The final, penultimate key generation function.
// takes all the bits and glues them together. requires configuration with special variables. // takes all the bits and glues them together. requires configuration with special variables.
module key(legend = "", inset = false) { module key(inset = false) {
difference() { difference() {
union(){ union(){
// the shape of the key, inside and out // the shape of the key, inside and out
keytop(); keytop();
// additive objects at the top of the key // additive objects at the top of the key
if(!inset) artisan(legend) children(); if(!inset) artisan() children();
// render the clearance check if it's enabled, but don't have it intersect with anything // render the clearance check if it's enabled, but don't have it intersect with anything
if ($clearance_check) %clearance_check(); if ($clearance_check) %clearance_check();
} }
// subtractive objects at the top of the key // subtractive objects at the top of the key
if (inset) artisan(legend, 0.3) children(); if (inset) artisan(0.3) children();
// subtract the clearance check if it's enabled, letting the user see the // subtract the clearance check if it's enabled, letting the user see the
// parts of the keycap that will hit the cherry switch // parts of the keycap that will hit the cherry switch
if ($clearance_check) clearance_check(); if ($clearance_check) clearance_check();

View File

@ -100,3 +100,10 @@ module flat_support() {
$support_type = "flat"; $support_type = "flat";
children(); children();
} }
module legend(text, valign="center", halign="center", size=0) {
//valign = "top" or "center" or "bottom"
//halign = "left" or "center" or "right"
$legends = [for(L=[$legends, [[text, halign, valign, size > 0 ? size : $font_size]]], a=L) a];
children();
}

View File

@ -109,3 +109,9 @@ $rounded_cherry_stem_d = 5.5;
// dimensions of alps stem // dimensions of alps stem
$alps_stem = [4.45, 2.25]; $alps_stem = [4.45, 2.25];
//list of legends to place on a key format: [text, halign, valign, size]
//halign = "left" or "center" or "right"
//valign = "top" or "center" or "bottom"
$legends = [];