Skip to content

Commit

Permalink
remove init fn
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Feb 19, 2024
1 parent bd42f68 commit 28ca8bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 66 deletions.
10 changes: 0 additions & 10 deletions frontends/rioterm/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,6 @@ impl RouteWindow {
let mut screen =
Screen::new(&winit_window, config, event_proxy, font_database).await?;

screen.init(
screen.state.named_colors.background.1,
&config.window.background_image,
);

Ok(Self {
is_focused: false,
is_occluded: false,
Expand Down Expand Up @@ -377,11 +372,6 @@ impl RouteWindow {
))
.expect("Screen not created");

screen.init(
screen.state.named_colors.background.1,
&config.window.background_image,
);

Self {
is_focused: false,
is_occluded: false,
Expand Down
87 changes: 31 additions & 56 deletions frontends/rioterm/src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Screen {
},
};

let sugarloaf: Sugarloaf = match Sugarloaf::new(
let mut sugarloaf: Sugarloaf = match Sugarloaf::new(
sugarloaf_window,
sugarloaf_renderer,
config.fonts.to_owned(),
Expand Down Expand Up @@ -189,6 +189,14 @@ impl Screen {
sugarloaf_errors,
)?;

sugarloaf.set_background_color(bg_color);
if let Some(image) = config.window.background_image {
sugarloaf.set_background_image(&image);
}

self.resize_all_contexts();
self.render();

Ok(Screen {
mouse_bindings: crate::bindings::default_mouse_bindings(),
modifiers: Modifiers::default(),
Expand Down Expand Up @@ -303,19 +311,21 @@ impl Screen {
self.mouse
.set_multiplier_and_divider(config.scroll.multiplier, config.scroll.divider);

let width = self.sugarloaf.layout.width_u32 as u16;
let height = self.sugarloaf.layout.height_u32 as u16;
let columns = self.sugarloaf.layout.columns;
let lines = self.sugarloaf.layout.lines;
self.resize_all_contexts(width, height, columns, lines);
self.resize_all_contexts();

let mut bg_color = self.state.named_colors.background.1;

if config.window.background_opacity < 1. {
bg_color.a = config.window.background_opacity as f64;
}

self.init(bg_color, &config.window.background_image);
self.sugarloaf
.set_background_color(screen.state.named_colors.background.1);
if let Some(image) = config.window.background_image {
self.sugarloaf.set_background_image(&image);
}

self.render();
}

#[inline]
Expand All @@ -335,24 +345,13 @@ impl Screen {
// and then updates again with correct bounds
// TODO: Refactor this logic
self.sugarloaf.layout.update();

let width = self.sugarloaf.layout.width_u32 as u16;
let height = self.sugarloaf.layout.height_u32 as u16;
let columns = self.sugarloaf.layout.columns;
let lines = self.sugarloaf.layout.lines;
self.resize_all_contexts(width, height, columns, lines);
self.resize_all_contexts();
}

#[inline]
pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize<u32>) -> &mut Self {
self.sugarloaf.resize(new_size.width, new_size.height);

self.resize_all_contexts(
new_size.width as u16,
new_size.height as u16,
self.sugarloaf.layout.columns,
self.sugarloaf.layout.lines,
);
self.resize_all_contexts();
self
}

Expand All @@ -364,27 +363,25 @@ impl Screen {
) -> &mut Self {
self.sugarloaf.rescale(new_scale);
self.sugarloaf.resize(new_size.width, new_size.height);

self
}

#[inline]
pub fn resize_all_contexts(
&mut self,
width: u16,
height: u16,
columns: usize,
lines: usize,
) {
for context in self.ctx().contexts() {
pub fn resize_all_contexts(&mut self) {
// whenever a resize update happens: it will stored in
// the next layout, so once the messenger.send_resize triggers
// the wakeup from pty it will also trigger a sugarloaf.render()
// and then eventually a render with the new layout computation.
let layout = self.sugarloaf.layout_next();
for context in self.ctx.contexts() {
let mut terminal = context.terminal.lock();
terminal.resize::<SugarloafLayout>(self.sugarloaf.layout);
terminal.resize::<SugarloafLayout>(layout);
drop(terminal);
let _ = context.messenger.send_resize(
width,
height,
columns as u16,
lines as u16,
layout.width as u16,
layout.height as u16,
layout.columns as u16,
layout.lines as u16,
);
}
}
Expand Down Expand Up @@ -1155,28 +1152,6 @@ impl Screen {
}
}

#[inline]
pub fn init(
&mut self,
color: ColorWGPU,
background_image: &Option<sugarloaf::ImageProperties>,
) {
let initial_columns = self.sugarloaf.layout.columns;

self.sugarloaf.set_background_color(color);
if let Some(image) = background_image {
self.sugarloaf.set_background_image(image);
}

if self.sugarloaf.layout.columns != initial_columns {
let width = self.sugarloaf.layout.width_u32 as u16;
let height = self.sugarloaf.layout.height_u32 as u16;
let columns = self.sugarloaf.layout.columns;
let lines = self.sugarloaf.layout.lines;
self.resize_all_contexts(width, height, columns, lines);
}
}

#[inline]
pub fn render_assistant(&mut self, assistant: &crate::routes::assistant::Assistant) {
crate::routes::assistant::screen(&mut self.sugarloaf, assistant);
Expand Down

0 comments on commit 28ca8bc

Please sign in to comment.