Modifica PageComponent por ComponentTrait

This commit is contained in:
Manuel Cillero 2022-04-30 09:46:03 +02:00
parent cd7020c77d
commit 37d0254055
18 changed files with 32 additions and 32 deletions

View file

@ -10,7 +10,7 @@ pub struct Block {
template : String,
}
impl PageComponent for Block {
impl ComponentTrait for Block {
fn new() -> Self {
Block {
renderable: render_always,
@ -59,7 +59,7 @@ impl Block {
// Block CONTAINER.
pub fn add(mut self, component: impl PageComponent) -> Self {
pub fn add(mut self, component: impl ComponentTrait) -> Self {
self.components.add(component);
self
}

View file

@ -7,7 +7,7 @@ pub struct Chunck {
template : String,
}
impl PageComponent for Chunck {
impl ComponentTrait for Chunck {
fn new() -> Self {
Chunck {
renderable: render_always,

View file

@ -13,7 +13,7 @@ pub struct Container {
template : String,
}
impl PageComponent for Container {
impl ComponentTrait for Container {
fn new() -> Self {
Container {
renderable : render_always,
@ -109,7 +109,7 @@ impl Container {
// Container CONTAINER.
pub fn add(mut self, component: impl PageComponent) -> Self {
pub fn add(mut self, component: impl ComponentTrait) -> Self {
self.components.add(component);
self
}

View file

@ -14,7 +14,7 @@ pub struct Button {
template : String,
}
impl PageComponent for Button {
impl ComponentTrait for Button {
fn new() -> Self {
Button {
renderable : render_always,

View file

@ -17,7 +17,7 @@ pub struct Date {
template : String,
}
impl PageComponent for Date {
impl ComponentTrait for Date {
fn new() -> Self {
Date {
renderable : render_always,

View file

@ -14,7 +14,7 @@ pub struct Form {
template : String,
}
impl PageComponent for Form {
impl ComponentTrait for Form {
fn new() -> Self {
Form {
renderable: render_always,
@ -68,7 +68,7 @@ impl Form {
// Form CONTAINER.
pub fn add(mut self, element: impl PageComponent) -> Self {
pub fn add(mut self, element: impl ComponentTrait) -> Self {
self.elements.add(element);
self
}

View file

@ -6,7 +6,7 @@ pub struct Hidden {
value : OptAttr,
}
impl PageComponent for Hidden {
impl ComponentTrait for Hidden {
fn new() -> Self {
Hidden {
weight: 0,

View file

@ -23,7 +23,7 @@ pub struct Input {
template : String,
}
impl PageComponent for Input {
impl ComponentTrait for Input {
fn new() -> Self {
Input {
renderable : render_always,

View file

@ -9,7 +9,7 @@ pub struct Column {
template : String,
}
impl PageComponent for Column {
impl ComponentTrait for Column {
fn new() -> Self {
Column {
renderable: render_always,
@ -54,7 +54,7 @@ impl Column {
// Column CONTAINER.
pub fn add(mut self, component: impl PageComponent) -> Self {
pub fn add(mut self, component: impl ComponentTrait) -> Self {
self.components.add(component);
self
}

View file

@ -9,7 +9,7 @@ pub struct Row {
template : String,
}
impl PageComponent for Row {
impl ComponentTrait for Row {
fn new() -> Self {
Row {
renderable: render_always,

View file

@ -9,7 +9,7 @@ pub struct Image {
template : String,
}
impl PageComponent for Image {
impl ComponentTrait for Image {
fn new() -> Self {
Image {
renderable: render_always,

View file

@ -20,7 +20,7 @@ pub struct MenuItem {
item_type : MenuItemType,
}
impl PageComponent for MenuItem {
impl ComponentTrait for MenuItem {
fn new() -> Self {
MenuItem {
renderable: render_always,
@ -179,7 +179,7 @@ pub struct Menu {
template : String,
}
impl PageComponent for Menu {
impl ComponentTrait for Menu {
fn new() -> Self {
Menu {
renderable: render_always,

View file

@ -34,7 +34,7 @@ impl ThemeTrait for BulmixTheme {
fn before_render_component(
&self,
component: &mut dyn PageComponent,
component: &mut dyn ComponentTrait,
_assets: &mut PageAssets
) {
match component.name() {

View file

@ -5,7 +5,7 @@ use std::any::type_name;
pub use std::any::Any as AnyComponent;
pub trait PageComponent: AnyComponent + Send + Sync {
pub trait ComponentTrait: AnyComponent + Send + Sync {
fn new() -> Self where Self: Sized;
@ -47,10 +47,10 @@ pub trait PageComponent: AnyComponent + Send + Sync {
fn as_mut_any(&mut self) -> &mut dyn AnyComponent;
}
pub fn component_ref<T: 'static>(component: &dyn PageComponent) -> &T {
pub fn component_ref<T: 'static>(component: &dyn ComponentTrait) -> &T {
component.as_ref_any().downcast_ref::<T>().unwrap()
}
pub fn component_mut<T: 'static>(component: &mut dyn PageComponent) -> &mut T {
pub fn component_mut<T: 'static>(component: &mut dyn ComponentTrait) -> &mut T {
component.as_mut_any().downcast_mut::<T>().unwrap()
}

View file

@ -1,23 +1,23 @@
use crate::html::{Markup, html};
use crate::response::page::{PageAssets, PageComponent, render_component};
use crate::response::page::{PageAssets, ComponentTrait, render_component};
use std::sync::{Arc, RwLock};
#[derive(Clone)]
pub struct PageContainer(Vec<Arc<RwLock<dyn PageComponent>>>);
pub struct PageContainer(Vec<Arc<RwLock<dyn ComponentTrait>>>);
impl PageContainer {
pub fn new() -> Self {
PageContainer(Vec::new())
}
pub fn new_with(component: impl PageComponent) -> Self {
pub fn new_with(component: impl ComponentTrait) -> Self {
let mut container = PageContainer::new();
container.add(component);
container
}
pub fn add(&mut self, component: impl PageComponent) {
pub fn add(&mut self, component: impl ComponentTrait) {
self.0.push(Arc::new(RwLock::new(component)));
}

View file

@ -9,7 +9,7 @@ pub use assets::{
mod component;
pub use component::{
AnyComponent,
PageComponent,
ComponentTrait,
component_ref,
component_mut,
};

View file

@ -100,7 +100,7 @@ impl<'a> Page<'a> {
pub fn add_to(
&mut self,
region: &'a str,
component: impl PageComponent
component: impl ComponentTrait
) -> &mut Self {
if let Some(regions) = self.regions.get_mut(region) {
regions.add(component);
@ -187,7 +187,7 @@ impl<'a> Page<'a> {
}
}
pub fn render_component(component: &mut dyn PageComponent, assets: &mut PageAssets) -> Markup {
pub fn render_component(component: &mut dyn ComponentTrait, assets: &mut PageAssets) -> Markup {
component.before_render(assets);
assets.theme().before_render_component(component, assets);
match component.is_renderable() {
@ -201,7 +201,7 @@ pub fn render_component(component: &mut dyn PageComponent, assets: &mut PageAsse
}
}
pub fn add_component_to(region: &'static str, component: impl PageComponent) {
pub fn add_component_to(region: &'static str, component: impl ComponentTrait) {
let mut hmap = COMPONENTS.write().unwrap();
if let Some(regions) = hmap.get_mut(region) {
regions.add(component);

View file

@ -1,7 +1,7 @@
use crate::{app, concat_string};
use crate::config::SETTINGS;
use crate::html::{Markup, html};
use crate::response::page::{Favicon, Page, PageAssets, PageComponent};
use crate::response::page::{ComponentTrait, Favicon, Page, PageAssets};
use crate::base::component::Chunck;
/// Los temas deben implementar este "trait".
@ -77,7 +77,7 @@ pub trait ThemeTrait: Send + Sync {
#[allow(unused_variables)]
fn before_render_component(
&self,
component: &mut dyn PageComponent,
component: &mut dyn ComponentTrait,
assets: &mut PageAssets
) {
/*
@ -96,7 +96,7 @@ pub trait ThemeTrait: Send + Sync {
#[allow(unused_variables)]
fn render_component(
&self,
component: &dyn PageComponent,
component: &dyn ComponentTrait,
assets: &mut PageAssets
) -> Option<Markup> {
None