cargo fmt

This commit is contained in:
Kenny Levinsen
2023-01-12 00:13:27 +01:00
parent be6ee9899c
commit b2a9475e4c
8 changed files with 170 additions and 142 deletions
+1 -1
View File
@@ -16,5 +16,5 @@ pub const XKB_KEY_End: u32 = 0xff57; /* EOL */
pub const XKB_KEY_a: u32 = 0x0061; /* U+0061 LATIN SMALL LETTER A */ pub const XKB_KEY_a: u32 = 0x0061; /* U+0061 LATIN SMALL LETTER A */
pub const XKB_KEY_e: u32 = 0x0065; /* U+0065 LATIN SMALL LETTER E */ pub const XKB_KEY_e: u32 = 0x0065; /* U+0065 LATIN SMALL LETTER E */
//pub const XKB_KEY_c: u32 = 0x0063; /* U+0063 LATIN SMALL LETTER C */ //pub const XKB_KEY_c: u32 = 0x0063; /* U+0063 LATIN SMALL LETTER C */
pub const XKB_KEY_k: u32 = 0x006b; /* U+006B LATIN SMALL LETTER K */ pub const XKB_KEY_k: u32 = 0x006b; /* U+006B LATIN SMALL LETTER K */
pub const XKB_KEY_u: u32 = 0x0075; /* U+0075 LATIN SMALL LETTER U */ pub const XKB_KEY_u: u32 = 0x0075; /* U+0075 LATIN SMALL LETTER U */
+16 -9
View File
@@ -30,11 +30,11 @@ use color::Color;
use fonts::FontMap; use fonts::FontMap;
use keyboard::Keyboard; use keyboard::Keyboard;
use widgets::{ use widgets::{
Battery, Backlight, Clock, Date, Geometry, HorizontalLayout, IndexedLayout, Interface, Layout, Line, Backlight, Battery, Clock, Date, Geometry, HorizontalLayout, IndexedLayout, Interface, Layout,
Margin, VerticalLayout, Widget, WidgetUpdater, Line, Margin, VerticalLayout, Widget, WidgetUpdater,
}; };
use std::{cell::RefCell, env, mem, rc::Rc, thread, process::exit}; use std::{cell::RefCell, env, mem, process::exit, rc::Rc, thread};
enum MaybeFontMap { enum MaybeFontMap {
Waiting(thread::JoinHandle<FontMap>), Waiting(thread::JoinHandle<FontMap>),
@@ -143,7 +143,7 @@ fn main() {
let bufmgr = BufferManager { let bufmgr = BufferManager {
buffers: Vec::new(), buffers: Vec::new(),
}; };
let (ping_sender, ping_source) = calloop::ping::make_ping().unwrap(); let (ping_sender, ping_source) = calloop::ping::make_ping().unwrap();
let clock = Box::new(Clock::new()); let clock = Box::new(Clock::new());
@@ -212,7 +212,7 @@ fn main() {
for _ in 0..state.widgets.len() { for _ in 0..state.widgets.len() {
damage.push(Geometry::new()); damage.push(Geometry::new());
} }
while state.running { while state.running {
event_loop event_loop
.dispatch(None, &mut state) .dispatch(None, &mut state)
@@ -461,11 +461,19 @@ impl Dispatch<xdg_toplevel::XdgToplevel, ()> for State {
_: &QueueHandle<Self>, _: &QueueHandle<Self>,
) { ) {
match event { match event {
xdg_toplevel::Event::Configure { width, height, states, .. } => { xdg_toplevel::Event::Configure {
width,
height,
states,
..
} => {
if (width, height) == (0, 0) { if (width, height) == (0, 0) {
return; return;
} }
let activated = states.iter().find(|&st| *st as u32 == xdg_toplevel::State::Activated as u32).is_some(); let activated = states
.iter()
.find(|&st| *st as u32 == xdg_toplevel::State::Activated as u32)
.is_some();
if activated { if activated {
state.activated = true; state.activated = true;
@@ -473,7 +481,6 @@ impl Dispatch<xdg_toplevel::XdgToplevel, ()> for State {
exit(0); exit(0);
} }
if state.dimensions != (width, height) { if state.dimensions != (width, height) {
state.bufmgr.clear_buffers(); state.bufmgr.clear_buffers();
state.dimensions = (width, height); state.dimensions = (width, height);
@@ -486,7 +493,7 @@ impl Dispatch<xdg_toplevel::XdgToplevel, ()> for State {
widget: Box::new(IndexedLayout { widget_idx: 1 }), widget: Box::new(IndexedLayout { widget_idx: 1 }),
margin: (16, 8, 0, 0), margin: (16, 8, 0, 0),
}), }),
Box::new(VerticalLayout{ Box::new(VerticalLayout {
widgets: vec![ widgets: vec![
Box::new(Margin { Box::new(Margin {
widget: Box::new(IndexedLayout { widget_idx: 2 }), widget: Box::new(IndexedLayout { widget_idx: 2 }),
+3 -6
View File
@@ -1,15 +1,12 @@
use std::{ use std::{
fs, fs,
io::{ErrorKind, Error}, io::{Error, ErrorKind},
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use crate::{ use crate::{
color::Color, color::Color,
widgets::bar_widget::{ widgets::bar_widget::{BarWidget, BarWidgetImpl},
BarWidget,
BarWidgetImpl,
},
}; };
fn read_file_as_u64(path: &Path) -> Result<u64, Error> { fn read_file_as_u64(path: &Path) -> Result<u64, Error> {
@@ -33,7 +30,7 @@ impl Backlight {
} }
pub fn new(path: &str) -> BarWidget { pub fn new(path: &str) -> BarWidget {
let mut dev = Backlight{ let mut dev = Backlight {
device_path: Path::new("/sys/class/backlight").to_path_buf().join(path), device_path: Path::new("/sys/class/backlight").to_path_buf().join(path),
cur: 0, cur: 0,
max: 0, max: 0,
+1 -5
View File
@@ -1,7 +1,4 @@
use std::{ use std::{cmp::min, default::Default};
cmp::min,
default::Default,
};
use crate::{ use crate::{
buffer::BufferView, buffer::BufferView,
@@ -94,4 +91,3 @@ impl Widget for BarWidget {
self.geometry self.geometry
} }
} }
+69 -60
View File
@@ -1,25 +1,19 @@
use std::{ use std::{
sync::{Arc, Mutex},
thread, thread,
time::Duration, time::Duration,
sync::{Arc, Mutex},
}; };
use calloop::ping::Ping; use calloop::ping::Ping;
use dbus::blocking::{ use dbus::blocking::{
stdintf::org_freedesktop_dbus::{Properties, PropertiesPropertiesChanged},
LocalConnection, LocalConnection,
stdintf::org_freedesktop_dbus::{
Properties,
PropertiesPropertiesChanged,
},
}; };
use crate::{ use crate::{
color::Color, color::Color,
widgets::bar_widget::{ widgets::bar_widget::{BarWidget, BarWidgetImpl},
BarWidget,
BarWidgetImpl,
},
}; };
enum UpowerBatteryState { enum UpowerBatteryState {
@@ -40,59 +34,75 @@ fn start_monitor(inner: Arc<Mutex<InnerBattery>>, ping: Ping) {
thread::Builder::new() thread::Builder::new()
.name("battmon".to_string()) .name("battmon".to_string())
.spawn(move || { .spawn(move || {
let conn = LocalConnection::new_system().unwrap(); let conn = LocalConnection::new_system().unwrap();
let device_path = "/org/freedesktop/UPower/devices/DisplayDevice"; let device_path = "/org/freedesktop/UPower/devices/DisplayDevice";
let proxy = conn.with_proxy("org.freedesktop.UPower", device_path, Duration::from_millis(500)); let proxy = conn.with_proxy(
"org.freedesktop.UPower",
device_path,
Duration::from_millis(500),
);
let capacity: f64 = proxy.get("org.freedesktop.UPower.Device", "Percentage").expect("unable to get property"); let capacity: f64 = proxy
let state: u32 = proxy.get("org.freedesktop.UPower.Device", "State").expect("unable to get state"); .get("org.freedesktop.UPower.Device", "Percentage")
.expect("unable to get property");
let state: u32 = proxy
.get("org.freedesktop.UPower.Device", "State")
.expect("unable to get state");
{ {
let mut inner = inner.lock().unwrap(); let mut inner = inner.lock().unwrap();
inner.value = capacity as f32 / 100.; inner.value = capacity as f32 / 100.;
inner.state = match state { inner.state = match state {
1 => UpowerBatteryState::Charging, 1 => UpowerBatteryState::Charging,
2 => UpowerBatteryState::Discharging, 2 => UpowerBatteryState::Discharging,
3 => UpowerBatteryState::Empty, 3 => UpowerBatteryState::Empty,
4 => UpowerBatteryState::Full, 4 => UpowerBatteryState::Full,
5 => UpowerBatteryState::NotCharging, 5 => UpowerBatteryState::NotCharging,
6 => UpowerBatteryState::Discharging, 6 => UpowerBatteryState::Discharging,
_ => UpowerBatteryState::Unknown, _ => UpowerBatteryState::Unknown,
}
}
proxy.match_signal(move |c: PropertiesPropertiesChanged, _: &LocalConnection, _: &dbus::Message| {
if c.interface_name != "org.freedesktop.UPower.Device" {
return true;
}
let mut inner = inner.lock().unwrap();
for (key, value) in c.changed_properties {
match key.as_str() {
"State" => {
inner.state = match value.0.as_u64().unwrap() {
1 => UpowerBatteryState::Charging,
2 => UpowerBatteryState::Discharging,
3 => UpowerBatteryState::Empty,
4 => UpowerBatteryState::Full,
5 => UpowerBatteryState::NotCharging,
6 => UpowerBatteryState::Discharging,
_ => UpowerBatteryState::Unknown,
};
ping.ping();
},
"Percentage" => {
inner.value = value.0.as_f64().unwrap() as f32 / 100.;
ping.ping();
},
_ => (),
} }
} }
true
}).unwrap();
loop { conn.process(Duration::from_millis(60000)).unwrap(); } proxy
}).unwrap(); .match_signal(
move |c: PropertiesPropertiesChanged,
_: &LocalConnection,
_: &dbus::Message| {
if c.interface_name != "org.freedesktop.UPower.Device" {
return true;
}
let mut inner = inner.lock().unwrap();
for (key, value) in c.changed_properties {
match key.as_str() {
"State" => {
inner.state = match value.0.as_u64().unwrap() {
1 => UpowerBatteryState::Charging,
2 => UpowerBatteryState::Discharging,
3 => UpowerBatteryState::Empty,
4 => UpowerBatteryState::Full,
5 => UpowerBatteryState::NotCharging,
6 => UpowerBatteryState::Discharging,
_ => UpowerBatteryState::Unknown,
};
ping.ping();
}
"Percentage" => {
inner.value = value.0.as_f64().unwrap() as f32 / 100.;
ping.ping();
}
_ => (),
}
}
true
},
)
.unwrap();
loop {
conn.process(Duration::from_millis(60000)).unwrap();
}
})
.unwrap();
} }
pub struct Battery { pub struct Battery {
@@ -102,8 +112,8 @@ pub struct Battery {
impl Battery { impl Battery {
pub fn new(ping: Ping) -> BarWidget { pub fn new(ping: Ping) -> BarWidget {
let battery = Battery{ let battery = Battery {
inner: Arc::new(Mutex::new(InnerBattery{ inner: Arc::new(Mutex::new(InnerBattery {
value: 0., value: 0.,
state: UpowerBatteryState::Unknown, state: UpowerBatteryState::Unknown,
})), })),
@@ -114,7 +124,6 @@ impl Battery {
} }
} }
impl BarWidgetImpl for Battery { impl BarWidgetImpl for Battery {
fn get_dirty(&self) -> bool { fn get_dirty(&self) -> bool {
self.dirty self.dirty
+73 -55
View File
@@ -110,11 +110,11 @@ impl Prompt {
"!" => { "!" => {
self.mode = PromptMode::Shell; self.mode = PromptMode::Shell;
return; return;
}, }
"=" => { "=" => {
self.mode = PromptMode::Calc; self.mode = PromptMode::Calc;
return; return;
}, }
_ => (), _ => (),
} }
} }
@@ -159,7 +159,9 @@ impl Prompt {
fn clear_right(&mut self) { fn clear_right(&mut self) {
let indices: Vec<(usize, &str)> = self.input.grapheme_indices(true).collect(); let indices: Vec<(usize, &str)> = self.input.grapheme_indices(true).collect();
if !indices.is_empty() { if !indices.is_empty() {
self.input = indices[0..self.cursor].iter().fold("".into(), |acc, el| acc + el.1); self.input = indices[0..self.cursor]
.iter()
.fold("".into(), |acc, el| acc + el.1);
} else { } else {
self.mode = PromptMode::Normal; self.mode = PromptMode::Normal;
} }
@@ -168,7 +170,9 @@ impl Prompt {
fn clear_left(&mut self) { fn clear_left(&mut self) {
let indices: Vec<(usize, &str)> = self.input.grapheme_indices(true).collect(); let indices: Vec<(usize, &str)> = self.input.grapheme_indices(true).collect();
if !indices.is_empty() { if !indices.is_empty() {
self.input = indices[self.cursor..indices.len()].iter().fold("".into(), |acc, el| acc + el.1); self.input = indices[self.cursor..indices.len()]
.iter()
.fold("".into(), |acc, el| acc + el.1);
self.cursor = 0; self.cursor = 0;
} else { } else {
self.mode = PromptMode::Normal; self.mode = PromptMode::Normal;
@@ -186,7 +190,12 @@ impl Prompt {
trait InterfaceWidget { trait InterfaceWidget {
fn trigger(&mut self, intf: &InnerInterface); fn trigger(&mut self, intf: &InnerInterface);
fn draw(&mut self, intf: &InnerInterface, fonts: &mut FontMap, view: &mut BufferView) -> Geometry; fn draw(
&mut self,
intf: &InnerInterface,
fonts: &mut FontMap,
view: &mut BufferView,
) -> Geometry;
fn update(&mut self, intf: &InnerInterface); fn update(&mut self, intf: &InnerInterface);
} }
@@ -266,7 +275,12 @@ impl InterfaceWidget for Launcher {
self.matches = matcher.matches(); self.matches = matcher.matches();
} }
fn draw(&mut self, intf: &InnerInterface, fonts: &mut FontMap, view: &mut BufferView) -> Geometry { fn draw(
&mut self,
intf: &InnerInterface,
fonts: &mut FontMap,
view: &mut BufferView,
) -> Geometry {
let fg = Color::new(1., 1., 1., 1.); let fg = Color::new(1., 1., 1., 1.);
let bg = Color::new(0., 0., 0., 1.); let bg = Color::new(0., 0., 0., 1.);
@@ -290,13 +304,8 @@ impl InterfaceWidget for Launcher {
.unwrap(); .unwrap();
let font = fonts.get_font(LAUNCHER_FONT, LAUNCHER_SIZE); let font = fonts.get_font(LAUNCHER_FONT, LAUNCHER_SIZE);
font.auto_draw_text( font.auto_draw_text(&mut prompt_line, &bg, &fg, ">")
&mut prompt_line, .unwrap();
&bg,
&fg,
">",
)
.unwrap();
// Draw entries // Draw entries
let dimfg = Color::new(0.5, 0.5, 0.5, 1.0); let dimfg = Color::new(0.5, 0.5, 0.5, 1.0);
@@ -331,8 +340,11 @@ impl InterfaceWidget for Launcher {
} }
} }
let content_height = min(intf.geometry.height, (self.matches.len() + 1) as u32 * line_height + 16); let content_height = min(
Geometry{ intf.geometry.height,
(self.matches.len() + 1) as u32 * line_height + 16,
);
Geometry {
x: intf.geometry.x, x: intf.geometry.x,
y: intf.geometry.y + intf.geometry.height - content_height, y: intf.geometry.y + intf.geometry.height - content_height,
width: intf.geometry.width, width: intf.geometry.width,
@@ -341,7 +353,7 @@ impl InterfaceWidget for Launcher {
} }
} }
struct Shell (); struct Shell();
impl InterfaceWidget for Shell { impl InterfaceWidget for Shell {
fn trigger(&mut self, intf: &InnerInterface) { fn trigger(&mut self, intf: &InnerInterface) {
@@ -359,7 +371,12 @@ impl InterfaceWidget for Shell {
fn update(&mut self, _intf: &InnerInterface) {} fn update(&mut self, _intf: &InnerInterface) {}
fn draw(&mut self, intf: &InnerInterface, fonts: &mut FontMap, view: &mut BufferView) -> Geometry { fn draw(
&mut self,
intf: &InnerInterface,
fonts: &mut FontMap,
view: &mut BufferView,
) -> Geometry {
let fg = Color::new(1., 1., 1., 1.); let fg = Color::new(1., 1., 1., 1.);
let bg = Color::new(0., 0., 0., 1.); let bg = Color::new(0., 0., 0., 1.);
@@ -382,15 +399,10 @@ impl InterfaceWidget for Shell {
) )
.unwrap(); .unwrap();
let font = fonts.get_font(LAUNCHER_FONT, LAUNCHER_SIZE); let font = fonts.get_font(LAUNCHER_FONT, LAUNCHER_SIZE);
font.auto_draw_text( font.auto_draw_text(&mut prompt_line, &bg, &Color::new(1., 0.75, 0.5, 1.), "!")
&mut prompt_line, .unwrap();
&bg,
&Color::new(1., 0.75, 0.5, 1.),
"!",
)
.unwrap();
Geometry{ Geometry {
x: intf.geometry.x, x: intf.geometry.x,
y: intf.geometry.y + intf.geometry.height - line_height, y: intf.geometry.y + intf.geometry.height - line_height,
width: intf.geometry.width, width: intf.geometry.width,
@@ -412,16 +424,22 @@ impl InterfaceWidget for Calc {
} }
fn update(&mut self, intf: &InnerInterface) { fn update(&mut self, intf: &InnerInterface) {
let res = rcalc_lib::parse::eval(&intf.prompt.input, &mut rcalc_lib::parse::CalcState::new()) let res =
.map(|x| format!("{}", x)) rcalc_lib::parse::eval(&intf.prompt.input, &mut rcalc_lib::parse::CalcState::new())
.map_err(|x| format!("{}", x)); .map(|x| format!("{}", x))
.map_err(|x| format!("{}", x));
self.result = match res { self.result = match res {
Ok(v) => Some(v), Ok(v) => Some(v),
Err(_) => None, Err(_) => None,
}; };
} }
fn draw(&mut self, intf: &InnerInterface, fonts: &mut FontMap, view: &mut BufferView) -> Geometry { fn draw(
&mut self,
intf: &InnerInterface,
fonts: &mut FontMap,
view: &mut BufferView,
) -> Geometry {
let fg = Color::new(1., 1., 1., 1.); let fg = Color::new(1., 1., 1., 1.);
let bg = Color::new(0., 0., 0., 1.); let bg = Color::new(0., 0., 0., 1.);
@@ -435,28 +453,25 @@ impl InterfaceWidget for Calc {
// Draw prompt // Draw prompt
let font = fonts.get_font(LAUNCHER_FONT, LAUNCHER_SIZE); let font = fonts.get_font(LAUNCHER_FONT, LAUNCHER_SIZE);
let res_off = font.auto_draw_text_with_cursor( let res_off = font
&mut prompt_line, .auto_draw_text_with_cursor(
&bg, &mut prompt_line,
&fg, &bg,
&format!(" {} ", &intf.prompt.input), &fg,
intf.prompt.cursor + 3, &format!(" {} ", &intf.prompt.input),
) intf.prompt.cursor + 3,
.unwrap(); )
.unwrap();
let font = fonts.get_font(LAUNCHER_FONT, LAUNCHER_SIZE); let font = fonts.get_font(LAUNCHER_FONT, LAUNCHER_SIZE);
font.auto_draw_text( font.auto_draw_text(&mut prompt_line, &bg, &Color::new(1., 0.75, 0.5, 1.), "=")
&mut prompt_line, .unwrap();
&bg,
&Color::new(1., 0.75, 0.5, 1.),
"=",
)
.unwrap();
if let Some(res) = &self.result { if let Some(res) = &self.result {
let resfg = Color::new(1.0, 0.65, 0., 1.0); let resfg = Color::new(1.0, 0.65, 0., 1.0);
let mut result_line = view.offset((res_off.0, prompt_offset)).unwrap(); let mut result_line = view.offset((res_off.0, prompt_offset)).unwrap();
font.auto_draw_text(&mut result_line, &bg, &resfg, &format!(" = {}", &res)).unwrap(); font.auto_draw_text(&mut result_line, &bg, &resfg, &format!(" = {}", &res))
.unwrap();
} }
for m in self.old.iter().rev() { for m in self.old.iter().rev() {
@@ -466,11 +481,15 @@ impl InterfaceWidget for Calc {
} }
prompt_offset -= LAUNCHER_SIZE.ceil() as u32; prompt_offset -= LAUNCHER_SIZE.ceil() as u32;
let mut result_line = view.offset((0, prompt_offset)).unwrap(); let mut result_line = view.offset((0, prompt_offset)).unwrap();
font.auto_draw_text(&mut result_line, &bg, &dimfg, &m).unwrap(); font.auto_draw_text(&mut result_line, &bg, &dimfg, &m)
.unwrap();
} }
let content_height = min(intf.geometry.height, (self.old.len() + 1) as u32 * line_height + 16); let content_height = min(
Geometry{ intf.geometry.height,
(self.old.len() + 1) as u32 * line_height + 16,
);
Geometry {
x: intf.geometry.x, x: intf.geometry.x,
y: intf.geometry.y + intf.geometry.height - content_height, y: intf.geometry.y + intf.geometry.height - content_height,
width: intf.geometry.width, width: intf.geometry.width,
@@ -495,14 +514,14 @@ pub struct Interface {
impl Interface { impl Interface {
pub fn new() -> Interface { pub fn new() -> Interface {
Interface{ Interface {
launcher: Launcher::new(), launcher: Launcher::new(),
shell: Shell{}, shell: Shell {},
calc: Calc{ calc: Calc {
old: Vec::new(), old: Vec::new(),
result: None, result: None,
}, },
inner: InnerInterface{ inner: InnerInterface {
dirty: false, dirty: false,
geometry: Default::default(), geometry: Default::default(),
selection: 0, selection: 0,
@@ -554,12 +573,12 @@ impl Widget for Interface {
self.inner.prompt.clear_left(); self.inner.prompt.clear_left();
self.inner.selection = 0; self.inner.selection = 0;
widget.update(&self.inner); widget.update(&self.inner);
}, }
keysyms::XKB_KEY_k if event.modifiers.ctrl => { keysyms::XKB_KEY_k if event.modifiers.ctrl => {
self.inner.prompt.clear_right(); self.inner.prompt.clear_right();
self.inner.selection = 0; self.inner.selection = 0;
widget.update(&self.inner); widget.update(&self.inner);
}, }
keysyms::XKB_KEY_Home => self.inner.prompt.home(), keysyms::XKB_KEY_Home => self.inner.prompt.home(),
keysyms::XKB_KEY_End => self.inner.prompt.end(), keysyms::XKB_KEY_End => self.inner.prompt.end(),
keysyms::XKB_KEY_BackSpace => { keysyms::XKB_KEY_BackSpace => {
@@ -599,4 +618,3 @@ impl Widget for Interface {
self.launcher.next_token = Some(token.to_string()); self.launcher.next_token = Some(token.to_string());
} }
} }
+2 -2
View File
@@ -1,14 +1,14 @@
mod backlight;
mod bar_widget; mod bar_widget;
mod battery; mod battery;
mod backlight;
mod clock; mod clock;
mod date; mod date;
mod launcher; mod launcher;
mod line; mod line;
mod widget; mod widget;
pub use battery::Battery;
pub use backlight::Backlight; pub use backlight::Backlight;
pub use battery::Battery;
pub use clock::Clock; pub use clock::Clock;
pub use date::Date; pub use date::Date;
pub use launcher::Interface; pub use launcher::Interface;
+5 -4
View File
@@ -1,4 +1,4 @@
use std::cmp::{min, max}; use std::cmp::{max, min};
use std::fmt; use std::fmt;
use crate::{buffer::BufferView, fonts::FontMap, keyboard::KeyEvent}; use crate::{buffer::BufferView, fonts::FontMap, keyboard::KeyEvent};
@@ -23,7 +23,7 @@ impl fmt::Display for Geometry {
impl Geometry { impl Geometry {
pub fn new() -> Geometry { pub fn new() -> Geometry {
Geometry{ Geometry {
x: 0, x: 0,
y: 0, y: 0,
width: 0, width: 0,
@@ -35,7 +35,8 @@ impl Geometry {
let x = min(self.x, other.x); let x = min(self.x, other.x);
let y = min(self.y, other.y); let y = min(self.y, other.y);
Geometry { Geometry {
x, y, x,
y,
width: max(self.width + self.x, other.width + other.x) - x, width: max(self.width + self.x, other.width + other.x) - x,
height: max(self.height + self.y, other.height + other.height) - y, height: max(self.height + self.y, other.height + other.height) - y,
} }
@@ -148,7 +149,7 @@ impl<U> Layout<U> for Margin<U> {
geometry: &Geometry, geometry: &Geometry,
user_data: &mut U, user_data: &mut U,
) -> Geometry { ) -> Geometry {
let geo = Geometry{ let geo = Geometry {
x: geometry.x + self.margin.0, x: geometry.x + self.margin.0,
y: geometry.y + self.margin.1, y: geometry.y + self.margin.1,
width: geometry.width - self.margin.0 - self.margin.2, width: geometry.width - self.margin.0 - self.margin.2,