mirror of
https://github.com/yewprint/yewprint
synced 2024-11-22 11:33:04 +00:00
Tree: clean-up: less pubs, impl Default if possible
This commit is contained in:
parent
f5992a3a83
commit
3c5a8af353
2 changed files with 37 additions and 43 deletions
31
src/app.rs
31
src/app.rs
|
@ -36,16 +36,8 @@ impl Component for App {
|
|||
let root_id = tree
|
||||
.insert(
|
||||
Node::new(NodeData {
|
||||
icon: None,
|
||||
icon_color: None,
|
||||
icon_intent: None,
|
||||
label: "".into(),
|
||||
secondary_label: None,
|
||||
is_selected: false,
|
||||
is_expanded: false,
|
||||
has_caret: true,
|
||||
disabled: false,
|
||||
data: 0,
|
||||
..Default::default()
|
||||
}),
|
||||
InsertBehavior::AsRoot,
|
||||
)
|
||||
|
@ -54,15 +46,10 @@ impl Component for App {
|
|||
.insert(
|
||||
Node::new(NodeData {
|
||||
icon: Some(IconName::FolderClose),
|
||||
icon_color: None,
|
||||
icon_intent: None,
|
||||
label: "Directory 1".into(),
|
||||
secondary_label: None,
|
||||
is_selected: false,
|
||||
is_expanded: false,
|
||||
has_caret: true,
|
||||
disabled: false,
|
||||
data: 1,
|
||||
..Default::default()
|
||||
}),
|
||||
InsertBehavior::UnderNode(&root_id),
|
||||
)
|
||||
|
@ -70,15 +57,9 @@ impl Component for App {
|
|||
tree.insert(
|
||||
Node::new(NodeData {
|
||||
icon: Some(IconName::Document),
|
||||
icon_color: None,
|
||||
icon_intent: None,
|
||||
label: "File 1".into(),
|
||||
secondary_label: None,
|
||||
is_selected: false,
|
||||
is_expanded: false,
|
||||
has_caret: false,
|
||||
disabled: false,
|
||||
data: 2,
|
||||
..Default::default()
|
||||
}),
|
||||
InsertBehavior::UnderNode(&root_id),
|
||||
)
|
||||
|
@ -86,15 +67,11 @@ impl Component for App {
|
|||
tree.insert(
|
||||
Node::new(NodeData {
|
||||
icon: Some(IconName::Tag),
|
||||
icon_color: None,
|
||||
icon_intent: Some(Intent::Primary),
|
||||
label: "File 2".into(),
|
||||
secondary_label: Some(html!(<Icon icon=IconName::EyeOpen />)),
|
||||
is_selected: false,
|
||||
is_expanded: false,
|
||||
has_caret: false,
|
||||
disabled: false,
|
||||
data: 3,
|
||||
..Default::default()
|
||||
}),
|
||||
InsertBehavior::UnderNode(&dir1),
|
||||
)
|
||||
|
|
49
src/tree.rs
49
src/tree.rs
|
@ -68,6 +68,23 @@ pub struct NodeData<T> {
|
|||
pub data: T,
|
||||
}
|
||||
|
||||
impl<T: Default> Default for NodeData<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
disabled: false,
|
||||
has_caret: false,
|
||||
icon: None,
|
||||
icon_color: None,
|
||||
icon_intent: None,
|
||||
is_expanded: false,
|
||||
is_selected: false,
|
||||
label: Default::default(),
|
||||
secondary_label: None,
|
||||
data: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Clone + PartialEq + 'static> Component for Tree<T> {
|
||||
type Message = ();
|
||||
type Properties = Props<T>;
|
||||
|
@ -170,26 +187,26 @@ impl<T: Clone> Tree<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct TreeNode {
|
||||
struct TreeNode {
|
||||
props: TreeNodeProps,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Properties)]
|
||||
pub struct TreeNodeProps {
|
||||
pub disabled: bool,
|
||||
pub has_caret: bool,
|
||||
pub icon: Option<IconName>,
|
||||
pub icon_color: Option<String>,
|
||||
pub icon_intent: Option<Intent>,
|
||||
pub is_expanded: bool,
|
||||
pub is_selected: bool,
|
||||
pub label: yew::virtual_dom::VNode,
|
||||
pub secondary_label: Option<yew::virtual_dom::VNode>,
|
||||
pub on_collapse: Option<Callback<MouseEvent>>,
|
||||
pub on_expand: Option<Callback<MouseEvent>>,
|
||||
pub onclick: Option<Callback<MouseEvent>>,
|
||||
pub children: html::Children,
|
||||
pub depth: u32,
|
||||
struct TreeNodeProps {
|
||||
disabled: bool,
|
||||
has_caret: bool,
|
||||
icon: Option<IconName>,
|
||||
icon_color: Option<String>,
|
||||
icon_intent: Option<Intent>,
|
||||
is_expanded: bool,
|
||||
is_selected: bool,
|
||||
label: yew::virtual_dom::VNode,
|
||||
secondary_label: Option<yew::virtual_dom::VNode>,
|
||||
on_collapse: Option<Callback<MouseEvent>>,
|
||||
on_expand: Option<Callback<MouseEvent>>,
|
||||
onclick: Option<Callback<MouseEvent>>,
|
||||
children: html::Children,
|
||||
depth: u32,
|
||||
}
|
||||
|
||||
impl Component for TreeNode {
|
||||
|
|
Loading…
Reference in a new issue