fix clippy in TUI

This commit is contained in:
Evan Almloff committed 2023-01-28 15:06:03 -06:00
1 parent 9efff74c0c
commit ec31014966
6 files changed
+24 -51

No files matched your search

+6 -6
View File
@@ -1,4 +1,4 @@
use crate::node::PreventDefault; use crate::prevent_default::PreventDefault;
use dioxus_native_core::{ use dioxus_native_core::{
node_ref::{AttributeMaskBuilder, NodeMaskBuilder}, node_ref::{AttributeMaskBuilder, NodeMaskBuilder},
@@ -75,10 +75,10 @@ impl Pass for Focus {
fn pass<'a>( fn pass<'a>(
&mut self, &mut self,
node_view: NodeView, node_view: NodeView,
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>, _: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>, _: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>, _: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
context: &SendAnyMap, _: &SendAnyMap,
) -> bool { ) -> bool {
let new = Focus { let new = Focus {
level: if let Some(a) = node_view level: if let Some(a) = node_view
@@ -291,7 +291,7 @@ impl FocusState {
let mut node = rdom.get_mut_raw(old).unwrap(); let mut node = rdom.get_mut_raw(old).unwrap();
node.get_mut::<Focused>().unwrap().0 = false; node.get_mut::<Focused>().unwrap().0 = false;
} }
let mut node = &mut rdom.get_mut_raw(id).unwrap(); let mut node = rdom.get_mut_raw(id).unwrap();
node.get_mut::<Focused>().unwrap().0 = true; node.get_mut::<Focused>().unwrap().0 = true;
self.focus_level = node.get::<Focus>().unwrap().level; self.focus_level = node.get::<Focus>().unwrap().level;
// reset the position to the currently focused element // reset the position to the currently focused element
+2 -2
View File
@@ -54,8 +54,8 @@ impl Pass for TaffyLayout {
fn pass<'a>( fn pass<'a>(
&mut self, &mut self,
node_view: NodeView, node_view: NodeView,
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>, _: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>, _: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>, children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
ctx: &SendAnyMap, ctx: &SendAnyMap,
) -> bool { ) -> bool {
+3 -4
View File
@@ -7,7 +7,7 @@ use crossterm::{
}; };
use dioxus_core::*; use dioxus_core::*;
use dioxus_native_core::{node_ref::NodeMaskBuilder, real_dom::NodeImmutable, Pass}; use dioxus_native_core::{node_ref::NodeMaskBuilder, real_dom::NodeImmutable, Pass};
use dioxus_native_core::{real_dom::RealDom, FxDashSet, NodeId, NodeMask, SendAnyMap}; use dioxus_native_core::{real_dom::RealDom, FxDashSet, NodeId, SendAnyMap};
use focus::FocusState; use focus::FocusState;
use futures::{ use futures::{
channel::mpsc::{UnboundedReceiver, UnboundedSender}, channel::mpsc::{UnboundedReceiver, UnboundedSender},
@@ -30,8 +30,8 @@ mod config;
mod focus; mod focus;
mod hooks; mod hooks;
mod layout; mod layout;
mod node;
pub mod prelude; pub mod prelude;
mod prevent_default;
pub mod query; pub mod query;
mod render; mod render;
mod style; mod style;
@@ -41,7 +41,6 @@ mod widgets;
pub use config::*; pub use config::*;
pub use hooks::*; pub use hooks::*;
pub(crate) use node::*;
// the layout space has a multiplier of 10 to minimize rounding errors // the layout space has a multiplier of 10 to minimize rounding errors
pub(crate) fn screen_to_layout_space(screen: u16) -> f32 { pub(crate) fn screen_to_layout_space(screen: u16) -> f32 {
@@ -215,7 +214,7 @@ fn render_vdom(
// size is guaranteed to not change when rendering // size is guaranteed to not change when rendering
resize(frame.size(), &mut taffy, &rdom); resize(frame.size(), &mut taffy, &rdom);
let root = rdom.get(NodeId(0)).unwrap(); let root = rdom.get(NodeId(0)).unwrap();
render::render_vnode(frame, &taffy, &rdom, root, cfg, Point::ZERO); render::render_vnode(frame, &taffy, root, cfg, Point::ZERO);
})?; })?;
execute!(terminal.backend_mut(), RestorePosition, Show).unwrap(); execute!(terminal.backend_mut(), RestorePosition, Show).unwrap();
} else { } else {
@@ -1,17 +1,5 @@
use crate::focus::Focus;
use crate::layout::TaffyLayout;
use crate::style_attributes::StyleModifier;
use dioxus_native_core::{node_ref::NodeView, Dependancy, Pass, SendAnyMap}; use dioxus_native_core::{node_ref::NodeView, Dependancy, Pass, SendAnyMap};
#[derive(Debug, Clone, Default)]
pub(crate) struct NodeState {
pub layout: TaffyLayout,
pub style: StyleModifier,
pub prevent_default: PreventDefault,
pub focus: Focus,
pub focused: bool,
}
#[derive(PartialEq, Debug, Clone, Copy)] #[derive(PartialEq, Debug, Clone, Copy)]
pub(crate) enum PreventDefault { pub(crate) enum PreventDefault {
Focus, Focus,
@@ -52,10 +40,10 @@ impl Pass for PreventDefault {
fn pass<'a>( fn pass<'a>(
&mut self, &mut self,
node_view: NodeView, node_view: NodeView,
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>, _: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>, _: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>, _: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
context: &SendAnyMap, _: &SendAnyMap,
) -> bool { ) -> bool {
let new = match node_view.attributes().and_then(|mut attrs| { let new = match node_view.attributes().and_then(|mut attrs| {
attrs attrs
+6 -20
View File
@@ -1,15 +1,11 @@
use dioxus_native_core::{real_dom::NodeImmutable, NodeRef, RealDom}; use dioxus_native_core::{real_dom::NodeImmutable, NodeRef};
use std::io::Stdout; use std::io::Stdout;
use taffy::{ use taffy::{
geometry::Point, geometry::Point,
prelude::{Dimension, Layout, Size}, prelude::{Dimension, Layout, Size},
Taffy, Taffy,
}; };
use tui::{ use tui::{backend::CrosstermBackend, layout::Rect, style::Color};
backend::CrosstermBackend,
layout::Rect,
style::{Color, Style},
};
use crate::{ use crate::{
focus::Focused, focus::Focused,
@@ -26,7 +22,6 @@ const RADIUS_MULTIPLIER: [f32; 2] = [1.0, 0.5];
pub(crate) fn render_vnode( pub(crate) fn render_vnode(
frame: &mut tui::Frame<CrosstermBackend<Stdout>>, frame: &mut tui::Frame<CrosstermBackend<Stdout>>,
layout: &Taffy, layout: &Taffy,
rdom: &RealDom,
node: NodeRef, node: NodeRef,
cfg: Config, cfg: Config,
parent_location: Point<f32>, parent_location: Point<f32>,
@@ -91,7 +86,7 @@ pub(crate) fn render_vnode(
} }
for c in node.children().unwrap() { for c in node.children().unwrap() {
render_vnode(frame, layout, rdom, c, cfg, location); render_vnode(frame, layout, c, cfg, location);
} }
} }
NodeType::Placeholder => unreachable!(), NodeType::Placeholder => unreachable!(),
@@ -123,10 +118,7 @@ impl RinkWidget for NodeRef<'_> {
[0, 1] => Direction::Down, [0, 1] => Direction::Down,
[0, -1] => Direction::Up, [0, -1] => Direction::Up,
[a, b] => { [a, b] => {
panic!( panic!("draw({before:?} {current:?} {after:?}) {a}, {b} no cell adjacent")
"draw({:?} {:?} {:?}) {}, {} no cell adjacent",
before, current, after, a, b
)
} }
}; };
let end_dir = match [after[0] - current[0], after[1] - current[1]] { let end_dir = match [after[0] - current[0], after[1] - current[1]] {
@@ -135,10 +127,7 @@ impl RinkWidget for NodeRef<'_> {
[0, 1] => Direction::Down, [0, 1] => Direction::Down,
[0, -1] => Direction::Up, [0, -1] => Direction::Up,
[a, b] => { [a, b] => {
panic!( panic!("draw({before:?} {current:?} {after:?}) {a}, {b} no cell adjacent")
"draw({:?} {:?} {:?}) {}, {} no cell adjacent",
before, current, after, a, b
)
} }
}; };
@@ -159,10 +148,7 @@ impl RinkWidget for NodeRef<'_> {
[Direction::Left, Direction::Up] => symbols.bottom_right, [Direction::Left, Direction::Up] => symbols.bottom_right,
[Direction::Left, Direction::Right] => symbols.horizontal, [Direction::Left, Direction::Right] => symbols.horizontal,
[Direction::Left, Direction::Down] => symbols.top_right, [Direction::Left, Direction::Down] => symbols.top_right,
_ => panic!( _ => panic!("{before:?} {current:?} {after:?} cannont connect cell to itself"),
"{:?} {:?} {:?} cannont connect cell to itself",
before, current, after
),
} }
.to_string(); .to_string();
buf.set( buf.set(
+3 -3
View File
@@ -58,10 +58,10 @@ impl Pass for StyleModifier {
fn pass<'a>( fn pass<'a>(
&mut self, &mut self,
node_view: NodeView, node_view: NodeView,
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>, _: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>, parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>, _: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
context: &SendAnyMap, _: &SendAnyMap,
) -> bool { ) -> bool {
let mut new = StyleModifier::default(); let mut new = StyleModifier::default();
if parent.is_some() { if parent.is_some() {