mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-12-02 13:14:11 +01:00
fix(bar): avoid bobbing when switching between populated/empty workspaces
This was debugged by Lando Calrissian on Discord who submitted this text patch. The rest of this commit message is from Lando's investigation summary shared on Discord: The left panel in komorebi-bar uses `Align2::LEFT_CENTER` anchor, which vertically centers the panel content within the bar. When switching between workspaces with windows (icons) and empty workspaces (text labels only), the content height differed by ~1-2px, causing the vertical center point to shift - resulting in visible "bobbing" of the workspace indicators. The height inconsistency occurred because: 1. `show_icons()` wrapped content in a Frame with inner_margin 2. `show_fallback_icon()` had NO Frame wrapper 3. `show_label()` had NO Frame wrapper and used default text height Fix: 1. Wrap `show_fallback_icon()` in the same Frame with inner_margin as show_icons 2. Wrap `show_label()` in the same Frame with inner_margin as show_icons 3. Add `ui.set_min_height(self.icon_size.y)` to show_label to ensure the label has the same minimum height as icons 4. Change show_label from static to instance method (&self) to access icon_size This ensures all three rendering functions produce consistent content height, preventing the LEFT_CENTER anchor from shifting when workspace content changes.
This commit is contained in:
1 parent
1c699ed4c4
commit
5a37f6357d
1 file changed
+41
-29
@@ -407,7 +407,7 @@ impl WorkspacesBar {
|
||||
// 2: Show icons, with no fallback | Label workspace name (no hover)
|
||||
AllIconsAndText | Existing(DisplayFormat::IconAndText) => |bar, ctx, ui, ws| {
|
||||
bar.show_icons(ctx, ui, ws);
|
||||
Self::show_label(ctx, ui, ws);
|
||||
bar.show_label(ctx, ui, ws);
|
||||
},
|
||||
// 3: Show icons, fallback if no icons and not selected | Label workspace name if selected else hover
|
||||
AllIconsAndTextOnSelected | Existing(DisplayFormat::IconAndTextOnSelected) => {
|
||||
@@ -416,7 +416,7 @@ impl WorkspacesBar {
|
||||
bar.show_fallback_icon(ctx, ui, ws);
|
||||
}
|
||||
if ws.is_selected {
|
||||
Self::show_label(ctx, ui, ws);
|
||||
bar.show_label(ctx, ui, ws);
|
||||
} else {
|
||||
ui.response().on_hover_text(&ws.name);
|
||||
}
|
||||
@@ -427,11 +427,11 @@ impl WorkspacesBar {
|
||||
if ws.is_selected {
|
||||
bar.show_icons(ctx, ui, ws);
|
||||
}
|
||||
Self::show_label(ctx, ui, ws);
|
||||
bar.show_label(ctx, ui, ws);
|
||||
},
|
||||
// 5: Never show icon (no icons at all) | Label workspace name always
|
||||
Existing(DisplayFormat::Text) => |_, ctx, ui, ws| {
|
||||
Self::show_label(ctx, ui, ws);
|
||||
Existing(DisplayFormat::Text) => |bar, ctx, ui, ws| {
|
||||
bar.show_label(ctx, ui, ws);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -469,33 +469,45 @@ impl WorkspacesBar {
|
||||
|
||||
/// Draws a fallback icon (a rectangle with a diagonal) for the workspace.
|
||||
fn show_fallback_icon(&self, ctx: &Context, ui: &mut Ui, ws: &WorkspaceInfo) -> Response {
|
||||
let (response, painter) = ui.allocate_painter(self.icon_size, Sense::hover());
|
||||
let stroke: Stroke = Stroke::new(
|
||||
1.0,
|
||||
if ws.is_selected {
|
||||
ctx.style().visuals.selection.stroke.color
|
||||
} else {
|
||||
ui.style().visuals.text_color()
|
||||
},
|
||||
);
|
||||
let mut rect = response.rect;
|
||||
let rounding = CornerRadius::same((rect.width() * 0.1) as u8);
|
||||
rect = rect.shrink(stroke.width);
|
||||
let c = rect.center();
|
||||
let r = rect.width() / 2.0;
|
||||
painter.rect_stroke(rect, rounding, stroke, StrokeKind::Outside);
|
||||
painter.line_segment([c - vec2(r, r), c + vec2(r, r)], stroke);
|
||||
response
|
||||
Frame::NONE
|
||||
.inner_margin(Margin::same(ui.style().spacing.button_padding.y as i8))
|
||||
.show(ui, |ui| {
|
||||
let (response, painter) = ui.allocate_painter(self.icon_size, Sense::hover());
|
||||
let stroke: Stroke = Stroke::new(
|
||||
1.0,
|
||||
if ws.is_selected {
|
||||
ctx.style().visuals.selection.stroke.color
|
||||
} else {
|
||||
ui.style().visuals.text_color()
|
||||
},
|
||||
);
|
||||
let mut rect = response.rect;
|
||||
let rounding = CornerRadius::same((rect.width() * 0.1) as u8);
|
||||
rect = rect.shrink(stroke.width);
|
||||
let c = rect.center();
|
||||
let r = rect.width() / 2.0;
|
||||
painter.rect_stroke(rect, rounding, stroke, StrokeKind::Outside);
|
||||
painter.line_segment([c - vec2(r, r), c + vec2(r, r)], stroke);
|
||||
response
|
||||
})
|
||||
.inner
|
||||
}
|
||||
|
||||
/// Shows the workspace label (colored if selected).
|
||||
fn show_label(ctx: &Context, ui: &mut Ui, ws: &WorkspaceInfo) -> Response {
|
||||
if ws.is_selected {
|
||||
let text = RichText::new(&ws.name).color(ctx.style().visuals.selection.stroke.color);
|
||||
ui.add(Label::new(text).selectable(false))
|
||||
} else {
|
||||
ui.add(Label::new(&ws.name).selectable(false))
|
||||
}
|
||||
fn show_label(&self, ctx: &Context, ui: &mut Ui, ws: &WorkspaceInfo) -> Response {
|
||||
Frame::NONE
|
||||
.inner_margin(Margin::same(ui.style().spacing.button_padding.y as i8))
|
||||
.show(ui, |ui| {
|
||||
ui.set_min_height(self.icon_size.y);
|
||||
if ws.is_selected {
|
||||
let text =
|
||||
RichText::new(&ws.name).color(ctx.style().visuals.selection.stroke.color);
|
||||
ui.add(Label::new(text).selectable(false))
|
||||
} else {
|
||||
ui.add(Label::new(&ws.name).selectable(false))
|
||||
}
|
||||
})
|
||||
.inner
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user