More customization

This commit is contained in:
Alexander Gehrke 2025-04-14 22:19:42 +02:00
parent 60444e3584
commit 0761bacc12
2 changed files with 97 additions and 63 deletions

View file

@ -1,11 +1,42 @@
/* [Main settings] */
// path to the tab icon
icon = "icons/classes/Guardian.svg";
// number of tabs
tabs = 4;
// index of the tab, 0 for first tab. must be smaller than number of tabs
index = 0;
// generate a card for each tab index for testing overlap
test_tabs = false;
/* [Dimensions] */
// horizontal size of the card
horizontal = 87.0;
// vertical size of the card (not including the tab)
vertical = 61.0;
// width of the tab's top (excluding the slope)
tab_width = 16.0;
// height of the tab
tab_height = 10.0;
// angle of the slope. lower angle means steeper slope, i.e. 0 makes square tabs
tab_angle = 45; // [0:89]
// height of the icon (will be resized). Must be smaller than tab_height
target_icon_height = 9.0;
// width of the icon. If set to zero, will keep aspect, but may cause it to be off center if it isn't square
target_icon_width = 0.0;
base_color = "black";
icon_color = "lime";
/* [Hidden] */
$fa = 1;
$fs = 0.4;
index = 0;
icon = "icons/classes/Mystic.svg";
tab_offset = 14;
target_icon_height = 9;
target_icon_width = 9;
module outer_tab(tab_height = 10, tab_width = 16, tab_angle = 45, flip = false)
{
@ -39,46 +70,11 @@ module inner_tab(tab_height = 10, tab_width = 16, tab_angle = 45)
polygon(tab);
}
module card(index = 0, thickness = 0.6, icon = "", icon_thickness = 0.4, horizontal = 87, vertical = 61,
tab_height = 10, tab_width = 16, tab_angle = 45)
{
slope_width = tab_height * tan(tab_angle);
is_inner = index > 0 && index < 3;
inner_tab_width = tab_width + 2 * slope_width;
outer_tab_width = tab_width + slope_width;
positions = [
0,
tab_offset,
horizontal - tab_offset - inner_tab_width,
horizontal - outer_tab_width,
];
linear_extrude(thickness)
{
square([ horizontal, vertical ]);
translate([ positions[index], vertical, 0 ])
{
if (is_inner)
inner_tab(tab_height, tab_width, tab_angle);
else
outer_tab(tab_height, tab_width, tab_angle, index == 3);
}
}
if (icon != "")
{
// If no icon width is given, we assume the icon is square.
icon_width = (target_icon_width == 0 ? target_icon_height : target_icon_width);
icon_offset = (index > 0 ? slope_width : 0) + tab_width / 2 - icon_width / 2;
translate([ positions[index] + icon_offset, vertical + 0.5, thickness - 0.001 ]) color("blue")
linear_extrude(icon_thickness + 0.001) resize([ target_icon_width, target_icon_height, 0 ], auto = true)
offset(delta = 0.001) import(icon);
}
}
module card2(index = 0, thickness = 0.6, icon = "", icon_thickness = 0.4, horizontal = 87, vertical = 61, tabs = 4,
tab_height = 10, tab_width = 16, tab_angle = 45)
module card(index = 0, thickness = 0.6, icon = "", icon_thickness = 0.4, horizontal = 87, vertical = 61, tabs = 4,
tab_height = 10, tab_width = 16, tab_angle = 45, target_icon_height = 9, target_icon_width = 9)
{
assert(0 <= index && index < tabs, str("Tab index out of range. Index: ", index, " Tabs: ", tabs));
assert(target_icon_height <= tab_height, str("Icon larger than tab!"));
is_inner = index > 0 && index < tabs - 1;
@ -89,7 +85,7 @@ module card2(index = 0, thickness = 0.6, icon = "", icon_thickness = 0.4, horizo
slope_width = tab_height * tan(tab_angle);
indent = index == 0 ? 0 : (tab_width + tab_spacing) * index - slope_width;
color("black") linear_extrude(thickness)
color(base_color) linear_extrude(thickness)
{
square([ horizontal, vertical ]);
translate([ indent, vertical, 0 ])
@ -106,16 +102,26 @@ module card2(index = 0, thickness = 0.6, icon = "", icon_thickness = 0.4, horizo
icon_width = (target_icon_width == 0 ? target_icon_height : target_icon_width);
icon_x_offset = (index > 0 ? slope_width : 0) + tab_width / 2 - icon_width / 2;
icon_y_offset = tab_height / 2 - target_icon_height / 2;
translate([ indent + icon_x_offset, vertical + icon_y_offset, thickness - 0.001 ]) color("lime")
linear_extrude(icon_thickness + 0.001) resize([ target_icon_width, target_icon_height, 0 ], auto = true)
translate([ indent + icon_x_offset, vertical + icon_y_offset, thickness ]) color(icon_color)
linear_extrude(icon_thickness) resize([ target_icon_width, target_icon_height, 0 ], auto = true)
offset(delta = 0.001) import(icon);
}
}
card(index, icon = icon, horizontal = 61, vertical = 87);
translate([ 100, 0, 0 ])
if (test_tabs)
{
card2(index + 0, icon = icon, horizontal = 61, vertical = 87, tab_width = 16, tabs = 3, tab_angle = 30);
card2(index + 1, icon = icon, horizontal = 61, vertical = 87, tab_width = 16, tabs = 3, tab_angle = 30);
card2(index + 2, icon = icon, horizontal = 61, vertical = 87, tab_width = 16, tabs = 3, tab_angle = 30);
for (idx = [0:tabs - 1])
{
translate([ 0, 0, idx ])
card(index = idx, icon = icon, horizontal = horizontal, vertical = vertical, tab_width = tab_width,
tabs = tabs, tab_height = tab_height, tab_angle = tab_angle, target_icon_height = target_icon_height,
target_icon_width = target_icon_width);
}
}
else
{
card(index, icon = icon, horizontal = horizontal, vertical = vertical, tab_width = tab_width, tabs = tabs,
tab_height = tab_height, tab_angle = tab_angle, target_icon_height = target_icon_height,
target_icon_width = target_icon_width);
}