1
0
Fork 0
forked from wry/wry

fix split bug on single windows and elide titles

This commit is contained in:
kossLAN 2026-05-03 15:35:34 -04:00
parent 7f71a6556b
commit c555593ae2
No known key found for this signature in database
8 changed files with 207 additions and 145 deletions

View file

@ -92,6 +92,23 @@ impl<'a> Config<'a> {
markup,
scale,
},
Config::RenderFittingOrEllipsized {
height,
max_width,
font,
text,
color,
markup,
scale,
} => Config::RenderFittingOrEllipsized {
height,
max_width,
font,
text: text.into_owned().into(),
color,
markup,
scale,
},
Config::Render {
x,
y,
@ -262,6 +279,26 @@ fn render_fitting(
)
}
fn render_fitting_or_ellipsized(
memfd: &Memfd,
height: Option<i32>,
max_width: i32,
font: &str,
text: &str,
color: Color,
markup: bool,
scale: Option<f64>,
) -> Result<RenderedText, TextError> {
let measurement = measure(memfd, font, text, markup, scale)?;
if measurement.ink_rect.width() <= max_width {
return render_fitting(memfd, height, font, text, color, markup, scale);
}
let height = height.unwrap_or(measurement.ink_rect.height());
render(
memfd, 0, None, max_width, height, 0, font, text, color, true, markup, scale,
)
}
#[derive(Debug, Copy, Clone, Default)]
pub struct TextMeasurement {
pub ink_rect: Rect,
@ -303,6 +340,24 @@ impl RenderWork {
markup,
scale,
} => render_fitting(&self.memfd, height, font, text, color, markup, scale),
Config::RenderFittingOrEllipsized {
height,
max_width,
ref font,
ref text,
color,
markup,
scale,
} => render_fitting_or_ellipsized(
&self.memfd,
height,
max_width,
font,
text,
color,
markup,
scale,
),
Config::Render {
x,
y,
@ -428,6 +483,15 @@ enum Config<'a> {
markup: bool,
scale: Option<f64>,
},
RenderFittingOrEllipsized {
height: Option<i32>,
max_width: i32,
font: Arc<String>,
text: Cow<'a, str>,
color: Color,
markup: bool,
scale: Option<f64>,
},
Render {
x: i32,
y: Option<i32>,
@ -573,6 +637,29 @@ impl TextTexture {
self.apply_config(on_completed, config)
}
pub fn schedule_render_fitting_or_ellipsized(
&self,
on_completed: Rc<dyn OnCompleted>,
height: Option<i32>,
max_width: i32,
font: &Arc<String>,
text: &str,
color: Color,
markup: bool,
scale: Option<f64>,
) {
let config = Config::RenderFittingOrEllipsized {
height,
max_width,
font: font.clone(),
text: text.into(),
color,
markup,
scale,
};
self.apply_config(on_completed, config)
}
pub fn flip(&self) -> Result<(), TextError> {
let res = self
.data

View file

@ -937,14 +937,29 @@ impl ContainerNode {
.persistent
.scale
.get();
let old_textures: AHashMap<_, _> = self
.tab_bar
.borrow()
.as_ref()
.map(|bar| {
bar.entries
.iter()
.map(|entry| (entry.child_id, entry.title_texture.clone()))
.collect()
})
.unwrap_or_default();
let mut bar = TabBar::new(height, render_scale);
for child in self.children.iter() {
let child_id = child.node.node_id();
let title = self.get_child_tab_title(&child, override_id, override_title);
let title_texture = old_textures
.get(&child_id)
.cloned()
.unwrap_or_else(|| Rc::new(RefCell::new(None)));
bar.entries.push(TabBarEntry {
child_id,
title,
title_texture: Rc::new(RefCell::new(None)),
title_texture,
active: child_id == active_id,
attention_requested: child.attention_requested.get(),
x: Cell::new(0),
@ -964,10 +979,27 @@ impl ContainerNode {
let Some(focused) = self.focus_history.last() else {
return;
};
if self.num_children.get() <= 1 {
let focused_node = focused.node.clone();
let focused_active = focused_node.tl_data().active();
if self.num_children.get() == 1 {
let sub = ContainerNode::new(
&self.state,
&self.workspace.get(),
focused_node.clone(),
split,
);
let sub_id = sub.node_id();
if ephemeral {
sub.ephemeral.set(Ephemeral::On);
}
self.clone().cnode_replace_child(&*focused_node, sub);
if focused_active
&& let Some(group) = self.child_nodes.borrow().get(&sub_id).map(|n| n.to_ref())
{
self.update_child_active(&group, true, 1);
}
return;
}
let focused_node = focused.node.clone();
// Record the sibling that comes AFTER the focused child so we can
// insert the new group at the same position.
let next_sibling: Option<Rc<dyn ToplevelNode>> = {
@ -1774,6 +1806,7 @@ impl ContainerNode {
e.title.clone(),
TabBar::entry_colors(&self.state, e),
e.title_texture.clone(),
e.width.get(),
)
})
.collect();
@ -1794,12 +1827,24 @@ impl ContainerNode {
texture_height = (bar_height as f64 * s).round() as _;
}
let mut texture_refs = Vec::new();
for (title, (_, _, text_color), title_texture) in &entries {
let text_padding = self.state.theme.sizes.tab_bar_text_padding.get();
let border_width = self.state.theme.sizes.tab_bar_border_width.get();
for (title, (_, _, text_color), title_texture, tab_width) in &entries {
let max_width = (*tab_width - 2 * (text_padding + border_width)).max(0);
let max_width = if let Some(s) = scale {
(max_width as f64 * s).round() as i32
} else {
max_width
};
if max_width <= 0 {
continue;
}
let mut tex_ref = title_texture.borrow_mut();
let tex = tex_ref.get_or_insert_with(|| TextTexture::new(&self.state, &ctx));
tex.schedule_render_fitting(
tex.schedule_render_fitting_or_ellipsized(
on_completed.clone(),
Some(texture_height),
max_width,
&font,
title,
*text_color,
@ -2465,6 +2510,7 @@ impl ToplevelNodeBase for ContainerNode {
let padding = self.state.theme.sizes.tab_bar_padding.get();
bar.layout_entries(rect.width(), padding);
}
self.schedule_update_tab_textures();
}
// log::info!("tl_change_extents");
self.perform_layout();