rsheldiii / KeyV2

KeyV2: A Parametric Mechanical Keycap Library
GNU General Public License v3.0
1.48k stars 188 forks source link

Rotate legends on keycaps #80

Closed ThajASara closed 2 years ago

ThajASara commented 3 years ago

I could not find a way to rotate the direction of legends on a keycap. For example: to model a vertical keycap for an ErgoDox style keyboard

Screen Shot 2021-01-07 at 10 36 52 AM

Is this possible? Did I miss something simple (highly likely)?

AaronVerDow commented 3 years ago

I don't know a simple solution but here is one way you could do it:

legend("E",[0,-1])
legend("V",[0,-1/3])
legend("A",[0,1/3])
legend("L",[0,1])
2uh()
key();
limitium commented 3 years ago

You can modify key.scad file like that

module keytext(text, position, font_size, depth) {
  woffset = (top_total_key_width()/3.5) * position[0];
  hoffset = (top_total_key_height()/3.5) * -position[1];
  translate([woffset, hoffset, -depth]){
    color($tertiary_color) linear_extrude(height=$dish_depth){
      rotate([0,0,-90]) text(text=text, font=$font, size=font_size, halign="left", valign="center", direction="ttb");
    }
  }
}

And then you can use rotated keys with a vertical label

translate_u(0,0) sa_row(3) {
   union(){
    2u() rotate([0,0,90]) legend("EVAL",[0,0],4) key();
  }
}

Result example:

image

rsheldiii commented 2 years ago

@limitium 's answer is good, though it's worth mentioning the default keystem in this library is directional; it can only fit on a keyswitch right side up or upside down, not rotated 90 or 270 degrees. if your keyswitch is rotated underneath the 2u use limitium's code, if it is the same orientation as everything else, use this code:

text(text=text, font=$font, size=font_size, halign="center", valign="center", direction="ttb");

then make a keycap like so:

sa_row(5) 2uh() legend("eval", size=5) key();

It would be good to expose the text direction in the library somehow. closing in favor of https://github.com/rsheldiii/KeyV2/issues/139