Skip to content

Commit

Permalink
fix other examples on sugarloaf
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Oct 15, 2024
1 parent 3b41612 commit 721bec5
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 55 deletions.
15 changes: 2 additions & 13 deletions frontends/rioterm/src/context/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,11 @@ impl<T: rio_backend::event::EventListener> ContextGrid<T> {
}
}

#[inline]
pub fn get_grid_item(&self, index: usize) -> &ContextGridItem<T> {
&self.inner[index]
}

#[inline]
pub fn len(&self) -> usize {
self.inner.len()
}

#[inline]
#[allow(unused)]
pub fn contexts(&self) -> &Vec<ContextGridItem<T>> {
&self.inner
}

#[inline]
pub fn contexts_mut(&mut self) -> &mut Vec<ContextGridItem<T>> {
&mut self.inner
Expand Down Expand Up @@ -162,7 +151,7 @@ impl<T: rio_backend::event::EventListener> ContextGrid<T> {

// 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],
Expand Down Expand Up @@ -239,7 +228,7 @@ impl<T: rio_backend::event::EventListener> ContextGrid<T> {
};
}

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);
Expand Down
2 changes: 1 addition & 1 deletion frontends/rioterm/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {

#[inline]
pub fn current(&self) -> &Context<T> {
&self.contexts[self.current_index].current()
self.contexts[self.current_index].current()
}

#[inline]
Expand Down
1 change: 1 addition & 0 deletions frontends/rioterm/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ impl Renderer {
}

#[inline]
#[allow(clippy::too_many_arguments)]
fn create_line(
&mut self,
builder: &mut Content,
Expand Down
4 changes: 2 additions & 2 deletions frontends/rioterm/src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 2 additions & 11 deletions sugarloaf/examples/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 3 additions & 10 deletions sugarloaf/examples/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 2 additions & 9 deletions sugarloaf/examples/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 2 additions & 9 deletions sugarloaf/examples/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down

0 comments on commit 721bec5

Please sign in to comment.