1
0
Fork 0
forked from wry/wry

autocommit 2022-02-19 23:48:18 CET

This commit is contained in:
Julian Orth 2022-02-19 23:48:18 +01:00
parent ae66acef73
commit 0f2fbcc5e7
6 changed files with 63 additions and 42 deletions

View file

@ -22,7 +22,7 @@ pub enum LogLevel {
Trace, Trace,
} }
#[derive(Encode, Decode, Copy, Clone, Debug)] #[derive(Encode, Decode, Copy, Clone, Debug, Eq, PartialEq)]
pub enum Direction { pub enum Direction {
Left, Left,
Down, Down,

View file

@ -629,7 +629,7 @@ impl Node for WlSurface {
self.xdg.get().map(|x| x.create_split(split)); self.xdg.get().map(|x| x.create_split(split));
} }
fn move_focus(&self, seat: &Rc<WlSeatGlobal>, direction: Direction) { fn move_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) {
let xdg = match self.xdg.get() { let xdg = match self.xdg.get() {
Some(x) => x, Some(x) => x,
_ => return, _ => return,

View file

@ -47,12 +47,14 @@ pub fn render(
}; };
let fd = FontDescription::from_string(font); let fd = FontDescription::from_string(font);
let layout = Layout::new(&pctx); let layout = Layout::new(&pctx);
layout.set_width(width * pango::SCALE); layout.set_width((width - 2).max(0) * pango::SCALE);
layout.set_ellipsize(EllipsizeMode::End); layout.set_ellipsize(EllipsizeMode::End);
layout.set_font_description(Some(&fd)); layout.set_font_description(Some(&fd));
layout.set_text(text); layout.set_text(text);
let font_height = layout.pixel_size().1;
cctx.set_operator(Operator::Source); cctx.set_operator(Operator::Source);
cctx.set_source_rgba(color.r as _, color.g as _, color.b as _, color.a as _); cctx.set_source_rgba(color.r as _, color.g as _, color.b as _, color.a as _);
cctx.move_to(1.0, ((height - font_height) / 2) as f64);
pangocairo::show_layout(&cctx, &layout); pangocairo::show_layout(&cctx, &layout);
let mut texture = None; let mut texture = None;
let _ = image.with_data(|d| unsafe { let _ = image.with_data(|d| unsafe {

View file

@ -15,6 +15,13 @@ impl Color {
b: 0.0, b: 0.0,
a: 1.0, a: 1.0,
}; };
pub const GREY: Self = Self {
r: 0.8,
g: 0.8,
b: 0.8,
a: 1.0,
};
} }
fn to_f32(c: u8) -> f32 { fn to_f32(c: u8) -> f32 {

View file

@ -14,7 +14,7 @@ use i4config::{Axis, Direction};
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::mem; use std::mem;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut, Sub};
use std::rc::Rc; use std::rc::Rc;
use crate::backend::KeyState; use crate::backend::KeyState;
@ -336,15 +336,16 @@ impl ContainerNode {
let new_content_size = self let new_content_size = self
.width .width
.get() .get()
.saturating_sub((nc - 1) as i32 * border_width); .sub((nc - 1) as i32 * border_width)
.max(0);
self.content_width.set(new_content_size); self.content_width.set(new_content_size);
self.content_height self.content_height
.set(self.height.get().saturating_sub(title_height + 1)); .set(self.height.get().sub(title_height + 1).max(0));
} }
ContainerSplit::Vertical => { ContainerSplit::Vertical => {
let new_content_size = self.height.get().saturating_sub( let new_content_size = self.height.get().sub(
title_height + 1 + (nc - 1) as i32 * (border_width + title_height + 1), title_height + 1 + (nc - 1) as i32 * (border_width + title_height + 1),
); ).max(0);
self.content_height.set(new_content_size); self.content_height.set(new_content_size);
self.content_width.set(self.width.get()); self.content_width.set(self.width.get());
} }
@ -448,7 +449,7 @@ impl ContainerNode {
title.push_str("["); title.push_str("[");
for (i, c) in self.children.iter().enumerate() { for (i, c) in self.children.iter().enumerate() {
if i > 0 { if i > 0 {
title.push_str(" "); title.push_str(", ");
} }
title.push_str(c.title.borrow_mut().deref()); title.push_str(c.title.borrow_mut().deref());
} }
@ -470,7 +471,8 @@ impl ContainerNode {
for c in self.children.iter() { for c in self.children.iter() {
c.title_texture.set(None); c.title_texture.set(None);
let title = c.title.borrow_mut(); let title = c.title.borrow_mut();
if title.is_empty() { let body = c.body.get();
if title.is_empty() || th == 0 || body.width() == 0 {
continue; continue;
} }
let ctx = match self.state.render_ctx.get() { let ctx = match self.state.render_ctx.get() {
@ -478,7 +480,7 @@ impl ContainerNode {
_ => continue, _ => continue,
}; };
let texture = let texture =
match text::render(&ctx, c.body.get().width(), th, &font, &title, Color::RED) { match text::render(&ctx, body.width(), th, &font, &title, Color::GREY) {
Ok(t) => t, Ok(t) => t,
Err(e) => { Err(e) => {
log::error!("Could not render title {}: {}", title, ErrorFmt(e)); log::error!("Could not render title {}: {}", title, ErrorFmt(e));
@ -541,6 +543,16 @@ impl Node for ContainerNode {
self.seat_state.destroy_node(self); self.seat_state.destroy_node(self);
} }
fn visit(self: Rc<Self>, visitor: &mut dyn NodeVisitor) {
visitor.visit_container(&self);
}
fn visit_children(&self, visitor: &mut dyn NodeVisitor) {
for child in self.children.iter() {
child.node.clone().visit(visitor);
}
}
fn child_title_changed(self: Rc<Self>, child: &dyn Node, title: &str) { fn child_title_changed(self: Rc<Self>, child: &dyn Node, title: &str) {
let child = match self.child_nodes.borrow_mut().get(&child.id()) { let child = match self.child_nodes.borrow_mut().get(&child.id()) {
Some(cn) => cn.to_ref(), Some(cn) => cn.to_ref(),
@ -557,26 +569,28 @@ impl Node for ContainerNode {
self.update_title(); self.update_title();
} }
fn focus_parent(&self, seat: &Rc<WlSeatGlobal>) { fn get_split(&self) -> Option<ContainerSplit> {
self.parent.get().focus_self(seat); Some(self.split.get())
} }
fn active_changed(&self, active: bool) { fn set_split(self: Rc<Self>, split: ContainerSplit) {
self.parent.get().child_active_changed(self, active); if self.split.replace(split) != split {
self.update_content_size();
self.schedule_layout();
self.update_title();
}
} }
fn focus_self(self: Rc<Self>, seat: &Rc<WlSeatGlobal>) { fn focus_self(self: Rc<Self>, seat: &Rc<WlSeatGlobal>) {
seat.focus_node(self); seat.focus_node(self);
} }
fn get_split(&self) -> Option<ContainerSplit> { fn move_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) {
Some(self.split.get()) if direction == Direction::Down {
} self.do_focus(seat, direction);
return;
fn set_split(self: Rc<Self>, split: ContainerSplit) { }
self.split.set(split); self.parent.get().move_focus_from_child(seat, &*self, direction);
self.update_content_size();
self.schedule_layout();
} }
fn do_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) { fn do_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) {
@ -643,6 +657,10 @@ impl Node for ContainerNode {
.unwrap() .unwrap()
} }
fn active_changed(&self, active: bool) {
self.parent.get().child_active_changed(self, active);
}
fn button(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState) { fn button(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState) {
if button != BTN_LEFT { if button != BTN_LEFT {
return; return;
@ -715,6 +733,10 @@ impl Node for ContainerNode {
} }
} }
fn focus_parent(&self, seat: &Rc<WlSeatGlobal>) {
self.parent.get().focus_self(seat);
}
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult { fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
let mut recurse = |content: Rect, child: NodeRef<ContainerChild>| { let mut recurse = |content: Rect, child: NodeRef<ContainerChild>| {
if content.contains(x, y) { if content.contains(x, y) {
@ -802,6 +824,14 @@ impl Node for ContainerNode {
} }
} }
fn child_active_changed(&self, child: &dyn Node, active: bool) {
let node = match self.child_nodes.borrow_mut().get(&child.id()) {
Some(l) => l.to_ref(),
None => return,
};
node.active.set(active);
}
fn enter(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, x: Fixed, y: Fixed) { fn enter(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, x: Fixed, y: Fixed) {
self.pointer_move(seat, x.round_down(), y.round_down()); self.pointer_move(seat, x.round_down(), y.round_down());
} }
@ -825,14 +855,6 @@ impl Node for ContainerNode {
self.pointer_move(seat, x.round_down(), y.round_down()); self.pointer_move(seat, x.round_down(), y.round_down());
} }
fn child_active_changed(&self, child: &dyn Node, active: bool) {
let node = match self.child_nodes.borrow_mut().get(&child.id()) {
Some(l) => l.to_ref(),
None => return,
};
node.active.set(active);
}
fn render(&self, renderer: &mut Renderer, x: i32, y: i32) { fn render(&self, renderer: &mut Renderer, x: i32, y: i32) {
renderer.render_container(self, x, y); renderer.render_container(self, x, y);
} }
@ -868,14 +890,4 @@ impl Node for ContainerNode {
} }
self.workspace.set(ws.clone()); self.workspace.set(ws.clone());
} }
fn visit(self: Rc<Self>, visitor: &mut dyn NodeVisitor) {
visitor.visit_container(&self);
}
fn visit_children(&self, visitor: &mut dyn NodeVisitor) {
for child in self.children.iter() {
child.node.clone().visit(visitor);
}
}
} }

View file

@ -105,7 +105,7 @@ pub trait Node {
let _ = direction; let _ = direction;
} }
fn move_focus(&self, seat: &Rc<WlSeatGlobal>, direction: Direction) { fn move_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) {
let _ = seat; let _ = seat;
let _ = direction; let _ = direction;
} }