renderer: add support for floating-titlebars (#4)
Reviewed-on: https://git.kosslan.dev/wry/jay/pulls/4
This commit is contained in:
parent
4d803360dd
commit
6dba659978
13 changed files with 316 additions and 158 deletions
|
|
@ -383,16 +383,26 @@ impl ContainerNode {
|
|||
let mb = self.mono_body.get();
|
||||
return (mb.width(), mb.height());
|
||||
}
|
||||
let spacing = self.state.theme.sizes.gap.get().max(
|
||||
self.state.theme.sizes.border_width.get(),
|
||||
);
|
||||
let gap = self.state.theme.sizes.gap.get();
|
||||
let bw = self.state.theme.sizes.border_width.get();
|
||||
let floating = self.state.theme.floating_titles.get() && gap != 0;
|
||||
let nc = self.num_children.get() as i32 + 1;
|
||||
match self.split.get() {
|
||||
ContainerSplit::Horizontal => {
|
||||
let spacing = if floating {
|
||||
self.state.theme.sizes.title_gap.get() + 2 * bw
|
||||
} else {
|
||||
gap.max(bw)
|
||||
};
|
||||
let content_w = self.width.get().sub((nc - 1) * spacing).max(0);
|
||||
(content_w / nc, self.height.get().sub(tpuh).max(0))
|
||||
}
|
||||
ContainerSplit::Vertical => {
|
||||
let spacing = if floating {
|
||||
self.state.theme.sizes.title_gap.get() + bw
|
||||
} else {
|
||||
gap.max(bw)
|
||||
};
|
||||
let content_h = self
|
||||
.height
|
||||
.get()
|
||||
|
|
@ -407,6 +417,7 @@ impl ContainerNode {
|
|||
self.update_content_size();
|
||||
// log::info!("on_spaces_changed");
|
||||
self.schedule_layout();
|
||||
self.schedule_compute_render_positions();
|
||||
}
|
||||
|
||||
pub fn on_colors_changed(self: &Rc<Self>) {
|
||||
|
|
@ -416,7 +427,7 @@ impl ContainerNode {
|
|||
}
|
||||
|
||||
fn damage(&self) {
|
||||
let bw = if self.state.theme.sizes.gap.get() > 0 {
|
||||
let bw = if self.state.theme.sizes.gap.get() != 0 {
|
||||
self.state.theme.sizes.border_width.get()
|
||||
} else {
|
||||
0
|
||||
|
|
@ -485,8 +496,15 @@ impl ContainerNode {
|
|||
|
||||
let th = self.state.theme.title_height();
|
||||
let bw = self.state.theme.sizes.border_width.get();
|
||||
let bw_top = self.state.theme.floating_title_top_margin();
|
||||
let floating = self.state.theme.floating_titles.get();
|
||||
let spacing = if floating {
|
||||
self.state.theme.sizes.title_gap.get() + 2 * bw
|
||||
} else {
|
||||
bw
|
||||
};
|
||||
let num_children = self.num_children.get() as i32;
|
||||
let content_width = self.width.get().sub(bw * (num_children - 1)).max(0);
|
||||
let content_width = self.width.get().sub(spacing * (num_children - 1)).max(0);
|
||||
let width_per_child = content_width / num_children;
|
||||
let mut rem = content_width % num_children;
|
||||
let mut pos = 0;
|
||||
|
|
@ -498,18 +516,28 @@ impl ContainerNode {
|
|||
}
|
||||
child
|
||||
.title_rect
|
||||
.set(Rect::new_sized_saturating(pos, 0, width, th));
|
||||
pos += width + bw;
|
||||
.set(Rect::new_sized_saturating(pos, bw_top, width, th));
|
||||
pos += width + spacing;
|
||||
}
|
||||
}
|
||||
|
||||
fn perform_split_layout(self: &Rc<Self>) {
|
||||
let sum_factors = self.sum_factors.get();
|
||||
let gap = self.state.theme.sizes.gap.get();
|
||||
let border_width = self.state.theme.sizes.border_width.get();
|
||||
let spacing = self.state.theme.sizes.gap.get().max(border_width);
|
||||
let floating = self.state.theme.floating_titles.get() && gap != 0;
|
||||
let title_height_tmp = self.state.theme.title_height();
|
||||
let title_plus_underline_height = self.state.theme.title_plus_underline_height();
|
||||
let tpuh = self.state.theme.title_plus_underline_height();
|
||||
let split = self.split.get();
|
||||
let spacing = if floating {
|
||||
let title_gap = self.state.theme.sizes.title_gap.get();
|
||||
match split {
|
||||
ContainerSplit::Horizontal => title_gap + 2 * border_width,
|
||||
ContainerSplit::Vertical => title_gap + border_width,
|
||||
}
|
||||
} else {
|
||||
gap.max(border_width)
|
||||
};
|
||||
let (content_size, other_content_size) = match split {
|
||||
ContainerSplit::Horizontal => (self.content_width.get(), self.content_height.get()),
|
||||
ContainerSplit::Vertical => (self.content_height.get(), self.content_width.get()),
|
||||
|
|
@ -527,24 +555,14 @@ impl ContainerNode {
|
|||
body_size = body_size.min(remaining_content_size);
|
||||
remaining_content_size -= body_size;
|
||||
let (x1, y1, width, height) = match split {
|
||||
ContainerSplit::Horizontal => (
|
||||
pos,
|
||||
title_plus_underline_height,
|
||||
body_size,
|
||||
other_content_size,
|
||||
),
|
||||
_ => (
|
||||
0,
|
||||
pos + title_plus_underline_height,
|
||||
other_content_size,
|
||||
body_size,
|
||||
),
|
||||
ContainerSplit::Horizontal => (pos, tpuh, body_size, other_content_size),
|
||||
_ => (0, pos + tpuh, other_content_size, body_size),
|
||||
};
|
||||
let body = Rect::new_sized_saturating(x1, y1, width, height);
|
||||
child.body.set(body);
|
||||
pos += body_size + spacing;
|
||||
if split == ContainerSplit::Vertical {
|
||||
pos += title_plus_underline_height;
|
||||
pos += tpuh;
|
||||
}
|
||||
}
|
||||
if remaining_content_size > 0 {
|
||||
|
|
@ -561,39 +579,28 @@ impl ContainerNode {
|
|||
let (x1, y1, width, height, size) = match split {
|
||||
ContainerSplit::Horizontal => {
|
||||
let width = body.width() + add;
|
||||
(
|
||||
pos,
|
||||
title_plus_underline_height,
|
||||
width,
|
||||
other_content_size,
|
||||
width,
|
||||
)
|
||||
(pos, tpuh, width, other_content_size, width)
|
||||
}
|
||||
_ => {
|
||||
let height = body.height() + add;
|
||||
(
|
||||
0,
|
||||
pos + title_plus_underline_height,
|
||||
other_content_size,
|
||||
height,
|
||||
height,
|
||||
)
|
||||
(0, pos + tpuh, other_content_size, height, height)
|
||||
}
|
||||
};
|
||||
body = Rect::new_sized_saturating(x1, y1, width, height);
|
||||
child.body.set(body);
|
||||
pos += size + spacing;
|
||||
if split == ContainerSplit::Vertical {
|
||||
pos += title_plus_underline_height;
|
||||
pos += tpuh;
|
||||
}
|
||||
}
|
||||
}
|
||||
let bw_top = self.state.theme.floating_title_top_margin();
|
||||
self.sum_factors.set(1.0);
|
||||
for child in self.children.iter() {
|
||||
let body = child.body.get();
|
||||
child.title_rect.set(Rect::new_sized_saturating(
|
||||
body.x1(),
|
||||
body.y1() - title_plus_underline_height,
|
||||
body.y1() - tpuh + bw_top,
|
||||
body.width(),
|
||||
title_height_tmp,
|
||||
));
|
||||
|
|
@ -604,25 +611,33 @@ impl ContainerNode {
|
|||
}
|
||||
|
||||
fn update_content_size(&self) {
|
||||
let gap = self.state.theme.sizes.gap.get();
|
||||
let border_width = self.state.theme.sizes.border_width.get();
|
||||
let spacing = self.state.theme.sizes.gap.get().max(border_width);
|
||||
let title_plus_underline_height = self.state.theme.title_plus_underline_height();
|
||||
let floating = self.state.theme.floating_titles.get() && gap != 0;
|
||||
let title_gap = self.state.theme.sizes.title_gap.get();
|
||||
let tpuh = self.state.theme.title_plus_underline_height();
|
||||
let nc = self.num_children.get();
|
||||
match self.split.get() {
|
||||
ContainerSplit::Horizontal => {
|
||||
let spacing = if floating {
|
||||
title_gap + 2 * border_width
|
||||
} else {
|
||||
gap.max(border_width)
|
||||
};
|
||||
let new_content_size = self.width.get().sub((nc - 1) as i32 * spacing).max(0);
|
||||
self.content_width.set(new_content_size);
|
||||
self.content_height
|
||||
.set(self.height.get().sub(title_plus_underline_height).max(0));
|
||||
self.content_height.set(self.height.get().sub(tpuh).max(0));
|
||||
}
|
||||
ContainerSplit::Vertical => {
|
||||
let spacing = if floating {
|
||||
title_gap + border_width
|
||||
} else {
|
||||
gap.max(border_width)
|
||||
};
|
||||
let new_content_size = self
|
||||
.height
|
||||
.get()
|
||||
.sub(
|
||||
title_plus_underline_height
|
||||
+ (nc - 1) as i32 * (spacing + title_plus_underline_height),
|
||||
)
|
||||
.sub(tpuh + (nc - 1) as i32 * (spacing + tpuh))
|
||||
.max(0);
|
||||
self.content_height.set(new_content_size);
|
||||
self.content_width.set(self.width.get());
|
||||
|
|
@ -630,9 +645,9 @@ impl ContainerNode {
|
|||
}
|
||||
self.mono_body.set(Rect::new_sized_saturating(
|
||||
0,
|
||||
title_plus_underline_height,
|
||||
tpuh,
|
||||
self.width.get(),
|
||||
self.height.get() - title_plus_underline_height,
|
||||
self.height.get() - tpuh,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -904,9 +919,9 @@ impl ContainerNode {
|
|||
rect.height() + tuh,
|
||||
));
|
||||
}
|
||||
if gap > 0 && !mono && !child.node.node_is_container() {
|
||||
if gap != 0 && !mono && !child.node.node_is_container() {
|
||||
child.border_color_is_focused.set(child.active.get());
|
||||
} else if gap == 0 && i > 0 {
|
||||
} else if i > 0 {
|
||||
let sep = if mono {
|
||||
Rect::new_sized_saturating(rect.x1() - bw, 0, bw, th)
|
||||
} else if split == ContainerSplit::Horizontal {
|
||||
|
|
@ -914,7 +929,10 @@ impl ContainerNode {
|
|||
} else {
|
||||
Rect::new_sized_saturating(0, rect.y1() - bw, cwidth, bw)
|
||||
};
|
||||
rd.border_rects.push(sep);
|
||||
let floating = self.state.theme.floating_titles.get();
|
||||
if gap == 0 || (mono && !floating) {
|
||||
rd.border_rects.push(sep);
|
||||
}
|
||||
}
|
||||
if child.active.get() {
|
||||
rd.active_title_rects.push(rect);
|
||||
|
|
@ -925,7 +943,7 @@ impl ContainerNode {
|
|||
} else {
|
||||
rd.title_rects.push(rect);
|
||||
}
|
||||
if !mono {
|
||||
if !mono && (!self.state.theme.floating_titles.get() || gap == 0) {
|
||||
let rect = Rect::new_sized_saturating(rect.x1(), rect.y2(), rect.width(), 1);
|
||||
rd.underline_rects.push(rect);
|
||||
}
|
||||
|
|
@ -937,10 +955,14 @@ impl ContainerNode {
|
|||
}
|
||||
}
|
||||
}
|
||||
if mono {
|
||||
if mono && (!self.state.theme.floating_titles.get() || gap == 0) {
|
||||
rd.underline_rects
|
||||
.push(Rect::new_sized_saturating(0, th, cwidth, tuh));
|
||||
}
|
||||
if gap == 0 && th > 0 {
|
||||
rd.underline_rects
|
||||
.push(Rect::new_sized_saturating(0, 0, cwidth, tuh));
|
||||
}
|
||||
if self.toplevel_data.visible.get() && (mono || split == ContainerSplit::Horizontal) {
|
||||
self.state
|
||||
.damage(Rect::new_sized_saturating(abs_x, abs_y, cwidth, tpuh));
|
||||
|
|
@ -1248,7 +1270,7 @@ impl ContainerNode {
|
|||
// log::info!("node_child_active_changed");
|
||||
self.schedule_render_titles();
|
||||
self.schedule_compute_render_positions();
|
||||
if self.state.theme.sizes.gap.get() > 0 && self.toplevel_data.visible.get() {
|
||||
if self.state.theme.sizes.gap.get() != 0 && self.toplevel_data.visible.get() {
|
||||
self.damage();
|
||||
}
|
||||
if let Some(parent) = self.toplevel_data.parent.get() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue