1
0
Fork 0
forked from wry/wry

config: clean up and document theming

This commit is contained in:
Julian Orth 2022-05-15 20:10:04 +02:00
parent 4780315f50
commit 6916f03e94
17 changed files with 745 additions and 285 deletions

View file

@ -11,7 +11,6 @@ use {
render::{Renderer, Texture},
state::State,
text,
theme::Color,
tree::{
walker::NodeVisitor, ContainingNode, FindTreeResult, FoundNode, Node, NodeId,
ToplevelData, ToplevelNode, WorkspaceNode,
@ -26,7 +25,6 @@ use {
},
},
ahash::AHashMap,
isnt::std_1::vec::IsntVecExt,
jay_config::{Axis, Direction},
smallvec::SmallVec,
std::{
@ -368,8 +366,8 @@ impl ContainerNode {
self.mono_content
.set(child.content.get().at_point(mb.x1(), mb.y1()));
let th = self.state.theme.title_height.get();
let bw = self.state.theme.border_width.get();
let th = self.state.theme.sizes.title_height.get();
let bw = self.state.theme.sizes.border_width.get();
let num_children = self.num_children.get() as i32;
let content_width = self.width.get().sub(bw * (num_children - 1)).max(0);
let width_per_child = content_width / num_children;
@ -390,8 +388,8 @@ impl ContainerNode {
fn perform_split_layout(self: &Rc<Self>) {
let sum_factors = self.sum_factors.get();
let border_width = self.state.theme.border_width.get();
let title_height = self.state.theme.title_height.get();
let border_width = self.state.theme.sizes.border_width.get();
let title_height = self.state.theme.sizes.title_height.get();
let split = self.split.get();
let (content_size, other_content_size) = match split {
ContainerSplit::Horizontal => (self.content_width.get(), self.content_height.get()),
@ -476,8 +474,8 @@ impl ContainerNode {
}
fn update_content_size(&self) {
let border_width = self.state.theme.border_width.get();
let title_height = self.state.theme.title_height.get();
let border_width = self.state.theme.sizes.border_width.get();
let title_height = self.state.theme.sizes.title_height.get();
let nc = self.num_children.get();
match self.split.get() {
ContainerSplit::Horizontal => {
@ -508,7 +506,7 @@ impl ContainerNode {
}
fn pointer_move(self: &Rc<Self>, seat: &Rc<WlSeatGlobal>, mut x: i32, mut y: i32) {
let title_height = self.state.theme.title_height.get();
let title_height = self.state.theme.sizes.title_height.get();
let mut seats = self.seats.borrow_mut();
let seat_state = seats.entry(seat.id()).or_insert_with(|| SeatState {
cursor: KnownCursor::Default,
@ -630,8 +628,8 @@ impl ContainerNode {
let mut rd = self.render_data.borrow_mut();
let rd = rd.deref_mut();
let theme = &self.state.theme;
let th = theme.title_height.get();
let bw = theme.border_width.get();
let th = theme.sizes.title_height.get();
let bw = theme.sizes.border_width.get();
let font = theme.font.borrow_mut();
let cwidth = self.width.get();
let cheight = self.height.get();
@ -641,9 +639,11 @@ impl ContainerNode {
rd.active_title_rects.clear();
rd.border_rects.clear();
rd.underline_rects.clear();
rd.last_active_rect.take();
let last_active = self.focus_history.last().map(|v| v.node.node_id());
let mono = self.mono_child.get().is_some();
let split = self.split.get();
let have_active = self.children.iter().any(|c| c.active.get());
for (i, child) in self.children.iter().enumerate() {
let rect = child.title_rect.get();
if i > 0 {
@ -656,14 +656,16 @@ impl ContainerNode {
};
rd.border_rects.push(rect.unwrap());
}
if child.active.get() {
let color = if child.active.get() {
rd.active_title_rects.push(rect);
theme.colors.focused_title_text.get()
} else if !have_active && last_active == Some(child.node.node_id()) {
rd.last_active_rect = Some(rect);
theme.colors.focused_inactive_title_text.get()
} else {
rd.title_rects.push(rect);
}
if last_active == Some(child.node.node_id()) {
rd.last_active_rect = Some(rect);
}
theme.colors.unfocused_title_text.get()
};
if !mono {
let rect = Rect::new_sized(rect.x1(), rect.y2(), rect.width(), 1).unwrap();
rd.underline_rects.push(rect);
@ -674,7 +676,7 @@ impl ContainerNode {
break 'render_title;
}
if let Some(ctx) = &ctx {
match text::render(ctx, rect.width(), th, &font, title.deref(), Color::GREY) {
match text::render(ctx, rect.width(), th, &font, title.deref(), color) {
Ok(t) => rd.titles.push(ContainerTitle {
x: rect.x1(),
y: rect.y1(),
@ -691,9 +693,6 @@ impl ContainerNode {
rd.underline_rects
.push(Rect::new_sized(0, th, cwidth, 1).unwrap());
}
if rd.active_title_rects.is_not_empty() {
rd.last_active_rect.take();
}
}
fn activate_child(self: &Rc<Self>, child: &NodeRef<ContainerChild>) {
@ -1151,7 +1150,7 @@ impl Node for ContainerNode {
Some(s) => s,
_ => return,
};
if seat_data.y > self.state.theme.title_height.get() {
if seat_data.y > self.state.theme.sizes.title_height.get() {
return;
}
let cur_mc = match self.mono_child.get() {

View file

@ -8,7 +8,6 @@ use {
render::{Renderer, Texture},
state::State,
text,
theme::Color,
tree::{
walker::NodeVisitor, ContainingNode, FindTreeResult, FoundNode, Node, NodeId,
StackedNode, ToplevelNode, WorkspaceNode,
@ -144,8 +143,8 @@ impl FloatNode {
};
let pos = self.position.get();
let theme = &self.state.theme;
let bw = theme.border_width.get();
let th = theme.title_height.get();
let bw = theme.sizes.border_width.get();
let th = theme.sizes.title_height.get();
let cpos = Rect::new_sized(
pos.x1() + bw,
pos.y1() + bw + th + 1,
@ -167,8 +166,12 @@ impl FloatNode {
fn render_title(&self) {
self.render_titles_scheduled.set(false);
let theme = &self.state.theme;
let th = theme.title_height.get();
let bw = theme.border_width.get();
let th = theme.sizes.title_height.get();
let tc = match self.active.get() {
true => theme.colors.focused_title_text.get(),
false => theme.colors.unfocused_title_text.get(),
};
let bw = theme.sizes.border_width.get();
let font = theme.font.borrow_mut();
let title = self.title.borrow_mut();
self.title_texture.set(None);
@ -180,8 +183,7 @@ impl FloatNode {
Some(c) => c,
_ => return,
};
let texture = match text::render(&ctx, pos.width() - 2 * bw, th, &font, &title, Color::GREY)
{
let texture = match text::render(&ctx, pos.width() - 2 * bw, th, &font, &title, tc) {
Ok(t) => t,
Err(e) => {
log::error!("Could not render title {}: {}", title, ErrorFmt(e));
@ -193,8 +195,8 @@ impl FloatNode {
fn pointer_move(self: &Rc<Self>, seat: &Rc<WlSeatGlobal>, x: i32, y: i32) {
let theme = &self.state.theme;
let bw = theme.border_width.get();
let th = theme.title_height.get();
let bw = theme.sizes.border_width.get();
let th = theme.sizes.title_height.get();
let mut seats = self.seats.borrow_mut();
let seat_state = seats.entry(seat.id()).or_insert_with(|| SeatState {
cursor: KnownCursor::Default,
@ -370,8 +372,8 @@ impl Node for FloatNode {
fn node_find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
let theme = &self.state.theme;
let th = theme.title_height.get();
let bw = theme.border_width.get();
let th = theme.sizes.title_height.get();
let bw = theme.sizes.border_width.get();
let pos = self.position.get();
if x < bw || x >= pos.width() - bw {
return FindTreeResult::AcceptsInput;

View file

@ -12,7 +12,6 @@ use {
render::{Renderer, Texture},
state::State,
text,
theme::Color,
tree::{walker::NodeVisitor, FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode},
utils::{
clonecell::CloneCell, errorfmt::ErrorFmt, linkedlist::LinkedList, scroller::Scroller,
@ -53,6 +52,13 @@ impl OutputNode {
}
}
pub fn on_spaces_changed(self: &Rc<Self>) {
self.update_render_data();
if let Some(c) = self.workspace.get() {
c.change_extents(&self.workspace_rect());
}
}
pub fn update_render_data(&self) {
let mut rd = self.render_data.borrow_mut();
rd.titles.clear();
@ -61,7 +67,8 @@ impl OutputNode {
rd.status = None;
let mut pos = 0;
let font = self.state.theme.font.borrow_mut();
let th = self.state.theme.title_height.get();
let theme = &self.state.theme;
let th = theme.sizes.title_height.get();
let active_id = self.workspace.get().map(|w| w.id);
let width = self.global.pos.get().width();
rd.underline = Rect::new_sized(0, th, width, 1).unwrap();
@ -72,14 +79,17 @@ impl OutputNode {
if th == 0 || ws.name.is_empty() {
break 'create_texture;
}
let title =
match text::render_fitting(&ctx, th, &font, &ws.name, Color::GREY, false) {
Ok(t) => t,
Err(e) => {
log::error!("Could not render title {}: {}", ws.name, ErrorFmt(e));
break 'create_texture;
}
};
let tc = match active_id == Some(ws.id) {
true => theme.colors.focused_title_text.get(),
false => theme.colors.unfocused_title_text.get(),
};
let title = match text::render_fitting(&ctx, th, &font, &ws.name, tc, false) {
Ok(t) => t,
Err(e) => {
log::error!("Could not render title {}: {}", ws.name, ErrorFmt(e));
break 'create_texture;
}
};
let mut x = pos + 1;
if title.width() + 2 > title_width {
title_width = title.width() + 2;
@ -110,7 +120,8 @@ impl OutputNode {
if status.is_empty() {
break 'set_status;
}
let title = match text::render_fitting(&ctx, th, &font, &status, Color::GREY, true) {
let tc = self.state.theme.colors.bar_text.get();
let title = match text::render_fitting(&ctx, th, &font, &status, tc, true) {
Ok(t) => t,
Err(e) => {
log::error!("Could not render status {}: {}", status, ErrorFmt(e));
@ -205,7 +216,7 @@ impl OutputNode {
fn workspace_rect(&self) -> Rect {
let rect = self.global.pos.get();
let th = self.state.theme.title_height.get();
let th = self.state.theme.sizes.title_height.get();
Rect::new_sized(
rect.x1(),
rect.y1() + th + 1,
@ -384,7 +395,7 @@ impl Node for OutputNode {
}
}
}
let bar_height = self.state.theme.title_height.get() + 1;
let bar_height = self.state.theme.sizes.title_height.get() + 1;
if y >= bar_height {
y -= bar_height;
let len = tree.len();

View file

@ -8,7 +8,6 @@ use {
render::{Renderer, Texture},
state::State,
text,
theme::Color,
tree::{FindTreeResult, FoundNode, Node, NodeId, NodeVisitor, ToplevelData, ToplevelNode},
utils::{clonecell::CloneCell, errorfmt::ErrorFmt},
},
@ -54,7 +53,7 @@ impl PlaceholderNode {
rect.height(),
&font,
"Fullscreen",
Color::GREY,
self.toplevel.state.theme.colors.unfocused_title_text.get(),
false,
) {
Ok(t) => {