Skip to content

Commit fab66e1

Browse files
authored
feat: apply active border radius to stack tab buttons
1 parent dcf17f3 commit fab66e1

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/stack.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class Stack {
169169
const entity = window.entity;
170170
const active = Ecs.entity_eq(entity, this.active);
171171

172-
const button = new TabButton(window)
172+
const button = new TabButton(window);
173173
const id = this.buttons.insert(button);
174174

175175
let tab: Tab = { active, entity, signals: [], button: id, button_signal: null };
@@ -220,7 +220,7 @@ export class Stack {
220220

221221
let id = 0;
222222

223-
for (const component of this.tabs) {
223+
for (const [idx, component] of this.tabs.entries()) {
224224
let name;
225225

226226
this.window_exec(id, component.entity, (window) => {
@@ -244,12 +244,13 @@ export class Stack {
244244
if (component.active) {
245245
let settings = this.ext.settings;
246246
let color_value = settings.hint_color_rgba();
247-
tab_color = `background: ${color_value}; color: ${utils.is_dark(color_value) ? 'white' : 'black'}`;
248-
247+
tab_color = `${color_value}; color: ${utils.is_dark(color_value) ? 'white' : 'black'}`;
249248
} else {
250-
tab_color = `background: ${INACTIVE_TAB_STYLE}`;
249+
tab_color = `${INACTIVE_TAB_STYLE}`;
251250
}
252-
button.set_style(tab_color);
251+
252+
const tab_border_radius = this.get_tab_border_radius(idx);
253+
button.set_style(`background: ${tab_color}; border-radius: ${tab_border_radius};`);
253254
}
254255
})
255256

@@ -259,6 +260,23 @@ export class Stack {
259260
this.reset_visibility(permitted)
260261
}
261262

263+
// returns the tab button border radius based on it's order.
264+
// Only curving the corners on the edges.
265+
private get_tab_border_radius(idx: Number): string {
266+
let result = `0px 0px 0px 0px`;
267+
268+
// the minus 4px is to accomodate the inner radius being tighter
269+
let radius = Math.max(0, this.ext.settings.active_hint_border_radius() - 4);
270+
// only allow a radius up to half the tab_height
271+
radius = Math.min(radius, Math.trunc(this.tabs_height / 2));
272+
// set each corner's radius based on it's order
273+
if (this.tabs.length === 1) result = `${radius}px`;
274+
else if (idx === 0) result = `${radius}px 0px 0px ${radius}px`;
275+
else if (idx === this.tabs.length - 1) result = `0px ${radius}px ${radius}px 0px`;
276+
277+
return result;
278+
}
279+
262280
/** Connects `on_window_changed` callbacks to the newly-active window */
263281
private active_connect(window: Meta.Window, active: Entity) {
264282
// Disconnect before attaching new window as active window

0 commit comments

Comments
 (0)