✏️ [pagetop] Mejor uso de traits en módulos/comp.

This commit is contained in:
Manuel Cillero 2023-02-03 14:40:36 +01:00
parent ce4a97b18f
commit 3839d1c51c
16 changed files with 92 additions and 72 deletions

View file

@ -38,15 +38,17 @@ pub struct Anchor {
template : String,
}
impl ModuleTrait for Anchor {
fn handle(&self) -> Handle {
COMPONENT_ANCHOR
}
}
impl ComponentTrait for Anchor {
fn new() -> Self {
Anchor::default()
}
fn handle(&self) -> Handle {
COMPONENT_ANCHOR
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -16,15 +16,17 @@ pub struct Block {
template : String,
}
impl ModuleTrait for Block {
fn handle(&self) -> Handle {
COMPONENT_BLOCK
}
}
impl ComponentTrait for Block {
fn new() -> Self {
Block::default().with_classes(ClassesOp::SetDefault, "block")
}
fn handle(&self) -> Handle {
COMPONENT_BLOCK
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -27,6 +27,12 @@ pub struct Container {
template : String,
}
impl ModuleTrait for Container {
fn handle(&self) -> Handle {
COMPONENT_CONTAINER
}
}
impl ComponentTrait for Container {
fn new() -> Self {
Container::default()
@ -34,10 +40,6 @@ impl ComponentTrait for Container {
.with_inner_classes(ClassesOp::SetDefault, "container")
}
fn handle(&self) -> Handle {
COMPONENT_CONTAINER
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -24,6 +24,12 @@ pub struct Button {
template : String,
}
impl ModuleTrait for Button {
fn handle(&self) -> Handle {
COMPONENT_BUTTON
}
}
impl ComponentTrait for Button {
fn new() -> Self {
Button::default()
@ -31,10 +37,6 @@ impl ComponentTrait for Button {
.with_classes(ClassesOp::AddFirst, "form-button")
}
fn handle(&self) -> Handle {
COMPONENT_BUTTON
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -21,6 +21,12 @@ pub struct Date {
template : String,
}
impl ModuleTrait for Date {
fn handle(&self) -> Handle {
COMPONENT_DATE
}
}
impl ComponentTrait for Date {
fn new() -> Self {
Date::default()
@ -28,10 +34,6 @@ impl ComponentTrait for Date {
.with_classes(ClassesOp::AddFirst, "form-type-date")
}
fn handle(&self) -> Handle {
COMPONENT_DATE
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -25,6 +25,12 @@ pub struct Form {
template : String,
}
impl ModuleTrait for Form {
fn handle(&self) -> Handle {
COMPONENT_FORM
}
}
impl ComponentTrait for Form {
fn new() -> Self {
Form::default()
@ -32,10 +38,6 @@ impl ComponentTrait for Form {
.with_charset("UTF-8")
}
fn handle(&self) -> Handle {
COMPONENT_FORM
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -10,15 +10,17 @@ pub struct Hidden {
value : AttributeValue,
}
impl ModuleTrait for Hidden {
fn handle(&self) -> Handle {
COMPONENT_HIDDEN
}
}
impl ComponentTrait for Hidden {
fn new() -> Self {
Hidden::default()
}
fn handle(&self) -> Handle {
COMPONENT_HIDDEN
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -36,6 +36,12 @@ pub struct Input {
template : String,
}
impl ModuleTrait for Input {
fn handle(&self) -> Handle {
COMPONENT_INPUT
}
}
impl ComponentTrait for Input {
fn new() -> Self {
Input::default()
@ -45,10 +51,6 @@ impl ComponentTrait for Input {
.with_maxlength(Some(128))
}
fn handle(&self) -> Handle {
COMPONENT_INPUT
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -48,15 +48,17 @@ pub struct Column {
template : String,
}
impl ModuleTrait for Column {
fn handle(&self) -> Handle {
COMPONENT_COLUMN
}
}
impl ComponentTrait for Column {
fn new() -> Self {
Column::default().with_classes(ClassesOp::SetDefault, SIZE__DEFAULT)
}
fn handle(&self) -> Handle {
COMPONENT_COLUMN
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -15,15 +15,17 @@ pub struct Row {
template : String,
}
impl ModuleTrait for Row {
fn handle(&self) -> Handle {
COMPONENT_ROW
}
}
impl ComponentTrait for Row {
fn new() -> Self {
Row::default().with_classes(ClassesOp::SetDefault, "row")
}
fn handle(&self) -> Handle {
COMPONENT_ROW
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -38,15 +38,17 @@ pub struct Heading {
template : String,
}
impl ModuleTrait for Heading {
fn handle(&self) -> Handle {
COMPONENT_HEADING
}
}
impl ComponentTrait for Heading {
fn new() -> Self {
Heading::default()
}
fn handle(&self) -> Handle {
COMPONENT_HEADING
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -11,15 +11,17 @@ pub struct Html {
template : String,
}
impl ModuleTrait for Html {
fn handle(&self) -> Handle {
COMPONENT_HTML
}
}
impl ComponentTrait for Html {
fn new() -> Self {
Html::default()
}
fn handle(&self) -> Handle {
COMPONENT_HTML
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -11,15 +11,17 @@ pub struct Icon {
classes : Classes,
}
impl ModuleTrait for Icon {
fn handle(&self) -> Handle {
COMPONENT_ICON
}
}
impl ComponentTrait for Icon {
fn new() -> Self {
Icon::default().with_classes(ClassesOp::SetDefault, "bi-question-circle-fill")
}
fn handle(&self) -> Handle {
COMPONENT_ICON
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -13,15 +13,17 @@ pub struct Image {
template : String,
}
impl ModuleTrait for Image {
fn handle(&self) -> Handle {
COMPONENT_IMAGE
}
}
impl ComponentTrait for Image {
fn new() -> Self {
Image::default().with_classes(ClassesOp::SetDefault, "img-fluid")
}
fn handle(&self) -> Handle {
COMPONENT_IMAGE
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -25,15 +25,17 @@ pub struct Paragraph {
template : String,
}
impl ModuleTrait for Paragraph {
fn handle(&self) -> Handle {
COMPONENT_PARAGRAPH
}
}
impl ComponentTrait for Paragraph {
fn new() -> Self {
Paragraph::default()
}
fn handle(&self) -> Handle {
COMPONENT_PARAGRAPH
}
fn weight(&self) -> isize {
self.weight
}

View file

@ -1,7 +1,7 @@
use super::RenderContext;
use crate::core::module::ModuleTrait;
use crate::html::{html, Markup};
use crate::util::{single_type_name, Handle};
pub use std::any::Any as AnyComponent;
@ -9,21 +9,11 @@ pub trait BaseComponent {
fn render(&mut self, rcx: &mut RenderContext) -> Markup;
}
pub trait ComponentTrait: AnyComponent + BaseComponent + Send + Sync {
pub trait ComponentTrait: AnyComponent + BaseComponent + ModuleTrait + Send + Sync {
fn new() -> Self
where
Self: Sized;
fn handle(&self) -> Handle;
fn name(&self) -> String {
single_type_name::<Self>().to_owned()
}
fn description(&self) -> Option<String> {
None
}
fn weight(&self) -> isize {
0
}