Run cargo fmt
This commit is contained in:
parent
00bc4d1e88
commit
8cc988d374
25 changed files with 732 additions and 731 deletions
|
|
@ -1,8 +1,8 @@
|
|||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||
|
||||
use super::text;
|
||||
use cosmic::{
|
||||
iced_native::{
|
||||
{Color, Element, Length, Point, Rectangle, Shell, Size},
|
||||
clipboard::Clipboard,
|
||||
event::{Event, Status},
|
||||
image,
|
||||
|
|
@ -11,21 +11,12 @@ use cosmic::{
|
|||
mouse::{self, Button, Event as MouseEvent, ScrollDelta},
|
||||
renderer,
|
||||
widget::{self, tree, Widget},
|
||||
Padding
|
||||
Padding, {Color, Element, Length, Point, Rectangle, Shell, Size},
|
||||
},
|
||||
theme::Theme,
|
||||
};
|
||||
use cosmic_text::{
|
||||
Action,
|
||||
Edit,
|
||||
SwashCache,
|
||||
};
|
||||
use std::{
|
||||
cmp,
|
||||
sync::Mutex,
|
||||
time::Instant,
|
||||
};
|
||||
use super::text;
|
||||
use cosmic_text::{Action, Edit, SwashCache};
|
||||
use std::{cmp, sync::Mutex, time::Instant};
|
||||
|
||||
pub struct Appearance {
|
||||
background_color: Option<Color>,
|
||||
|
|
@ -68,7 +59,6 @@ impl<'a, Editor> TextBox<'a, Editor> {
|
|||
self.padding = padding.into();
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn text_box<'a, Editor>(editor: &'a Mutex<Editor>) -> TextBox<'a, Editor> {
|
||||
|
|
@ -97,11 +87,7 @@ where
|
|||
Length::Fill
|
||||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
_renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
) -> layout::Node {
|
||||
fn layout(&self, _renderer: &Renderer, limits: &layout::Limits) -> layout::Node {
|
||||
let limits = limits.width(Length::Fill).height(Length::Fill);
|
||||
|
||||
//TODO: allow lazy shape
|
||||
|
|
@ -160,7 +146,7 @@ where
|
|||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
background_color
|
||||
background_color,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -173,8 +159,10 @@ where
|
|||
|
||||
let mut editor = self.editor.lock().unwrap();
|
||||
|
||||
let view_w = cmp::min(viewport.width as i32, layout.bounds().width as i32) - self.padding.horizontal() as i32;
|
||||
let view_h = cmp::min(viewport.height as i32, layout.bounds().height as i32) - self.padding.vertical() as i32;
|
||||
let view_w = cmp::min(viewport.width as i32, layout.bounds().width as i32)
|
||||
- self.padding.horizontal() as i32;
|
||||
let view_h = cmp::min(viewport.height as i32, layout.bounds().height as i32)
|
||||
- self.padding.vertical() as i32;
|
||||
editor.buffer_mut().set_size(view_w, view_h);
|
||||
|
||||
editor.shape_as_needed();
|
||||
|
|
@ -183,41 +171,51 @@ where
|
|||
|
||||
let mut pixels = vec![0; view_w as usize * view_h as usize * 4];
|
||||
|
||||
editor.draw(&mut state.cache.lock().unwrap(), text_color, |x, y, w, h, color| {
|
||||
if w <= 0 || h <= 0 {
|
||||
// Do not draw invalid sized rectangles
|
||||
return;
|
||||
}
|
||||
editor.draw(
|
||||
&mut state.cache.lock().unwrap(),
|
||||
text_color,
|
||||
|x, y, w, h, color| {
|
||||
if w <= 0 || h <= 0 {
|
||||
// Do not draw invalid sized rectangles
|
||||
return;
|
||||
}
|
||||
|
||||
if w > 1 || h > 1 {
|
||||
// Draw rectangles with optimized quad renderer
|
||||
renderer.fill_quad(
|
||||
renderer::Quad {
|
||||
bounds: Rectangle::new(
|
||||
layout.position() + [x as f32, y as f32].into() + [self.padding.left as f32, self.padding.top as f32].into(),
|
||||
Size::new(w as f32 , h as f32)
|
||||
if w > 1 || h > 1 {
|
||||
// Draw rectangles with optimized quad renderer
|
||||
renderer.fill_quad(
|
||||
renderer::Quad {
|
||||
bounds: Rectangle::new(
|
||||
layout.position()
|
||||
+ [x as f32, y as f32].into()
|
||||
+ [self.padding.left as f32, self.padding.top as f32].into(),
|
||||
Size::new(w as f32, h as f32),
|
||||
),
|
||||
border_radius: 0.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
Color::from_rgba8(
|
||||
color.r(),
|
||||
color.g(),
|
||||
color.b(),
|
||||
(color.a() as f32) / 255.0,
|
||||
),
|
||||
border_radius: 0.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
Color::from_rgba8(
|
||||
color.r(),
|
||||
color.g(),
|
||||
color.b(),
|
||||
(color.a() as f32) / 255.0
|
||||
)
|
||||
);
|
||||
} else {
|
||||
text::draw_pixel(&mut pixels, view_w, view_h, x, y, color);
|
||||
}
|
||||
});
|
||||
);
|
||||
} else {
|
||||
text::draw_pixel(&mut pixels, view_w, view_h, x, y, color);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let handle = image::Handle::from_pixels(view_w as u32, view_h as u32, pixels);
|
||||
image::Renderer::draw(renderer, handle, Rectangle::new(
|
||||
layout.position() + [self.padding.left as f32, self.padding.top as f32].into(),
|
||||
Size::new(view_w as f32, view_h as f32)
|
||||
));
|
||||
image::Renderer::draw(
|
||||
renderer,
|
||||
handle,
|
||||
Rectangle::new(
|
||||
layout.position() + [self.padding.left as f32, self.padding.top as f32].into(),
|
||||
Size::new(view_w as f32, view_h as f32),
|
||||
),
|
||||
);
|
||||
|
||||
let duration = instant.elapsed();
|
||||
log::debug!("redraw {}, {}: {:?}", view_w, view_h, duration);
|
||||
|
|
@ -238,101 +236,107 @@ where
|
|||
|
||||
let mut status = Status::Ignored;
|
||||
match event {
|
||||
Event::Keyboard(KeyEvent::KeyPressed { key_code, modifiers }) => match key_code {
|
||||
Event::Keyboard(KeyEvent::KeyPressed {
|
||||
key_code,
|
||||
modifiers,
|
||||
}) => match key_code {
|
||||
KeyCode::Left => {
|
||||
editor.action(Action::Left);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::Right => {
|
||||
editor.action(Action::Right);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::Up => {
|
||||
editor.action(Action::Up);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::Down => {
|
||||
editor.action(Action::Down);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::Home => {
|
||||
editor.action(Action::Home);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::End => {
|
||||
editor.action(Action::End);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::PageUp => {
|
||||
editor.action(Action::PageUp);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::PageDown => {
|
||||
editor.action(Action::PageDown);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::Escape => {
|
||||
editor.action(Action::Escape);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
editor.action(Action::Enter);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
editor.action(Action::Backspace);
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
KeyCode::Delete => {
|
||||
editor.action(Action::Delete);
|
||||
status = Status::Captured;
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
Event::Keyboard(KeyEvent::CharacterReceived(character)) => {
|
||||
editor.action(Action::Insert(character));
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
Event::Mouse(MouseEvent::ButtonPressed(Button::Left)) => {
|
||||
if layout.bounds().contains(cursor_position) {
|
||||
editor.action(Action::Click {
|
||||
x: (cursor_position.x - layout.bounds().x) as i32 - self.padding.left as i32,
|
||||
x: (cursor_position.x - layout.bounds().x) as i32
|
||||
- self.padding.left as i32,
|
||||
y: (cursor_position.y - layout.bounds().y) as i32 - self.padding.top as i32,
|
||||
});
|
||||
state.is_dragging = true;
|
||||
status = Status::Captured;
|
||||
}
|
||||
},
|
||||
}
|
||||
Event::Mouse(MouseEvent::ButtonReleased(Button::Left)) => {
|
||||
state.is_dragging = false;
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
Event::Mouse(MouseEvent::CursorMoved { .. }) => {
|
||||
if state.is_dragging {
|
||||
editor.action(Action::Drag {
|
||||
x: (cursor_position.x - layout.bounds().x) as i32 - self.padding.left as i32,
|
||||
x: (cursor_position.x - layout.bounds().x) as i32
|
||||
- self.padding.left as i32,
|
||||
y: (cursor_position.y - layout.bounds().y) as i32 - self.padding.top as i32,
|
||||
});
|
||||
status = Status::Captured;
|
||||
}
|
||||
},
|
||||
}
|
||||
Event::Mouse(MouseEvent::WheelScrolled { delta }) => match delta {
|
||||
ScrollDelta::Lines { x, y } => {
|
||||
editor.action(Action::Scroll {
|
||||
lines: (-y * 6.0) as i32,
|
||||
});
|
||||
status = Status::Captured;
|
||||
},
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => ()
|
||||
_ => (),
|
||||
}
|
||||
|
||||
status
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'editor, Editor, Message, Renderer> From<TextBox<'a, Editor>> for Element<'a, Message, Renderer>
|
||||
impl<'a, 'editor, Editor, Message, Renderer> From<TextBox<'a, Editor>>
|
||||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: renderer::Renderer + image::Renderer<Handle = image::Handle>,
|
||||
Renderer::Theme: StyleSheet,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue