From e404ede2b314df3d30a6b0db3fa7c0acb59c9782 Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Mon, 14 Oct 2024 21:42:23 +0200 Subject: [PATCH] fix other examples on sugarloaf --- frontends/rioterm/src/context/grid.rs | 15 ++------------- frontends/rioterm/src/context/mod.rs | 2 +- frontends/rioterm/src/renderer/mod.rs | 1 + frontends/rioterm/src/screen/mod.rs | 4 ++-- sugarloaf/examples/image.rs | 13 ++----------- sugarloaf/examples/shapes.rs | 13 +++---------- sugarloaf/examples/text.rs | 11 ++--------- sugarloaf/examples/transparent.rs | 11 ++--------- 8 files changed, 15 insertions(+), 55 deletions(-) diff --git a/frontends/rioterm/src/context/grid.rs b/frontends/rioterm/src/context/grid.rs index fbf0f2e45c..5c86d16a8b 100644 --- a/frontends/rioterm/src/context/grid.rs +++ b/frontends/rioterm/src/context/grid.rs @@ -94,22 +94,11 @@ impl ContextGrid { } } - #[inline] - pub fn get_grid_item(&self, index: usize) -> &ContextGridItem { - &self.inner[index] - } - #[inline] pub fn len(&self) -> usize { self.inner.len() } - #[inline] - #[allow(unused)] - pub fn contexts(&self) -> &Vec> { - &self.inner - } - #[inline] pub fn contexts_mut(&mut self) -> &mut Vec> { &mut self.inner @@ -162,7 +151,7 @@ impl ContextGrid { // In case there's only 1 context then ignore quad if len == 1 { - if let Some(item) = self.inner.get(0) { + if let Some(item) = self.inner.first() { objects.push(Object::RichText(RichText { id: item.val.rich_text_id, position: [self.margin.x, self.margin.top_y], @@ -239,7 +228,7 @@ impl ContextGrid { }; } - pub fn rescale(&mut self, new_scale: f32, sugarloaf: &Sugarloaf) { + pub fn rescale(&mut self, sugarloaf: &Sugarloaf) { for context in &mut self.inner { let layout = sugarloaf.rich_text_layout(&context.val.rich_text_id); context.val.dimension.update_dimensions(layout.dimensions); diff --git a/frontends/rioterm/src/context/mod.rs b/frontends/rioterm/src/context/mod.rs index 2ae6fea8de..bacec62f4c 100644 --- a/frontends/rioterm/src/context/mod.rs +++ b/frontends/rioterm/src/context/mod.rs @@ -757,7 +757,7 @@ impl ContextManager { #[inline] pub fn current(&self) -> &Context { - &self.contexts[self.current_index].current() + self.contexts[self.current_index].current() } #[inline] diff --git a/frontends/rioterm/src/renderer/mod.rs b/frontends/rioterm/src/renderer/mod.rs index c8e28e280e..e7c196c2a5 100644 --- a/frontends/rioterm/src/renderer/mod.rs +++ b/frontends/rioterm/src/renderer/mod.rs @@ -241,6 +241,7 @@ impl Renderer { } #[inline] + #[allow(clippy::too_many_arguments)] fn create_line( &mut self, builder: &mut Content, diff --git a/frontends/rioterm/src/screen/mod.rs b/frontends/rioterm/src/screen/mod.rs index e8b0cc8057..60d6f46493 100644 --- a/frontends/rioterm/src/screen/mod.rs +++ b/frontends/rioterm/src/screen/mod.rs @@ -355,7 +355,7 @@ impl Screen<'_> { for context in self.ctx().contexts() { // TODO: Should loop all let mut terminal = context.current().terminal.lock(); - let shape = config.cursor.shape.into(); + let shape = config.cursor.shape; terminal.cursor_shape = shape; terminal.default_cursor_shape = shape; terminal.blinking_cursor = config.cursor.blinking; @@ -422,7 +422,7 @@ impl Screen<'_> { self.resize_all_contexts(); self.context_manager .current_grid_mut() - .rescale(new_scale, &self.sugarloaf); + .rescale(&self.sugarloaf); self.context_manager .current_grid_mut() .resize(new_size.width as f32, new_size.height as f32); diff --git a/sugarloaf/examples/image.rs b/sugarloaf/examples/image.rs index 11edc5c49e..ee20455ef0 100644 --- a/sugarloaf/examples/image.rs +++ b/sugarloaf/examples/image.rs @@ -7,9 +7,7 @@ use rio_window::{ dpi::LogicalSize, event::WindowEvent, event_loop::EventLoop, window::WindowAttributes, }; use std::error::Error; -use sugarloaf::{ - layout::SugarloafLayout, Sugarloaf, SugarloafWindow, SugarloafWindowSize, -}; +use sugarloaf::{layout::RootStyle, Sugarloaf, SugarloafWindow, SugarloafWindowSize}; fn main() { let width = 400.0; @@ -55,14 +53,7 @@ impl ApplicationHandler for Application { let scale_factor = window.scale_factor(); let font_size = 25.; - let sugarloaf_layout = SugarloafLayout::new( - self.width, - self.height, - (10.0, 10.0, 0.0), - scale_factor as f32, - font_size, - 1.0, - ); + let sugarloaf_layout = RootStyle::new(scale_factor as f32, font_size, 1.0); let size = window.inner_size(); let sugarloaf_window = SugarloafWindow { diff --git a/sugarloaf/examples/shapes.rs b/sugarloaf/examples/shapes.rs index 0e375f0513..433fc99d76 100644 --- a/sugarloaf/examples/shapes.rs +++ b/sugarloaf/examples/shapes.rs @@ -8,8 +8,8 @@ use rio_window::{ }; use std::error::Error; use sugarloaf::{ - layout::SugarloafLayout, ComposedQuad, Object, Quad, Rect, Sugarloaf, - SugarloafWindow, SugarloafWindowSize, + layout::RootStyle, ComposedQuad, Object, Quad, Rect, Sugarloaf, SugarloafWindow, + SugarloafWindowSize, }; fn main() { @@ -56,14 +56,7 @@ impl ApplicationHandler for Application { let scale_factor = window.scale_factor(); let font_size = 25.; - let sugarloaf_layout = SugarloafLayout::new( - self.width, - self.height, - (10.0, 10.0, 0.0), - scale_factor as f32, - font_size, - 1.0, - ); + let sugarloaf_layout = RootStyle::new(scale_factor as f32, font_size, 1.0); let size = window.inner_size(); let sugarloaf_window = SugarloafWindow { diff --git a/sugarloaf/examples/text.rs b/sugarloaf/examples/text.rs index f81170a958..0fbf22a8ff 100644 --- a/sugarloaf/examples/text.rs +++ b/sugarloaf/examples/text.rs @@ -8,7 +8,7 @@ use rio_window::{ }; use std::error::Error; use sugarloaf::{ - layout::SugarloafLayout, FragmentStyle, FragmentStyleDecoration, Object, RichText, + layout::RootStyle, FragmentStyle, FragmentStyleDecoration, Object, RichText, Sugarloaf, SugarloafWindow, SugarloafWindowSize, UnderlineInfo, UnderlineShape, }; @@ -56,14 +56,7 @@ impl ApplicationHandler for Application { let scale_factor = window.scale_factor(); let font_size = 25.; - let sugarloaf_layout = SugarloafLayout::new( - self.width, - self.height, - (10.0, 10.0, 0.0), - scale_factor as f32, - font_size, - 1.0, - ); + let sugarloaf_layout = RootStyle::new(scale_factor as f32, font_size, 1.0); let size = window.inner_size(); let sugarloaf_window = SugarloafWindow { diff --git a/sugarloaf/examples/transparent.rs b/sugarloaf/examples/transparent.rs index 5d741bb3cd..16f05167f7 100644 --- a/sugarloaf/examples/transparent.rs +++ b/sugarloaf/examples/transparent.rs @@ -8,7 +8,7 @@ use rio_window::{ dpi::LogicalSize, event::Event, event_loop::EventLoop, window::WindowAttributes, }; use sugarloaf::components::rect::Rect; -use sugarloaf::layout::SugarloafLayout; +use sugarloaf::layout::RootStyle; use sugarloaf::{Object, Sugarloaf, SugarloafWindow, SugarloafWindowSize}; fn main() { @@ -28,14 +28,7 @@ fn main() { let font_size = 60.; let line_height = 1.0; - let sugarloaf_layout = SugarloafLayout::new( - width as f32, - height as f32, - (0.0, 0.0, 0.0), - scale_factor as f32, - font_size, - line_height, - ); + let sugarloaf_layout = RootStyle::new(scale_factor as f32, font_size, line_height); let size = window.inner_size(); let sugarloaf_window = SugarloafWindow {