[Fix] replaced existentioal type to Box

This commit is contained in:
Andrey Tkachenko 2018-08-30 18:18:41 +04:00
parent f4862fefde
commit f5ce2c9564
8 changed files with 11 additions and 179 deletions

View File

@ -2,12 +2,6 @@ use crate::engine::Engine;
use crate::renderable::Renderable; use crate::renderable::Renderable;
use std::marker::PhantomData; use std::marker::PhantomData;
#[macro_export]
macro_rules! children {
($w:expr) => ($w);
($w1:expr, $($rest:tt)*) => (Children2::new($w1, children!($($rest)*)));
}
pub struct Children2<E, CH0, CH1> pub struct Children2<E, CH0, CH1>
where E: Engine, where E: Engine,
CH0: Renderable<E>, CH0: Renderable<E>,

View File

@ -1,4 +1,4 @@
#![feature(associated_type_defaults, never_type, unsize, specialization)] #![feature(proc_macro, associated_type_defaults, never_type, unsize, specialization)]
pub mod convert; pub mod convert;
pub mod engine; pub mod engine;
@ -6,12 +6,17 @@ pub mod context;
pub mod callback; pub mod callback;
pub mod component; pub mod component;
#[macro_use]
pub mod children; pub mod children;
pub mod renderable; pub mod renderable;
pub mod node; pub mod node;
pub mod view; pub mod view;
#[macro_export]
macro_rules! children {
($w:expr) => ($w);
($w1:expr, $($rest:tt)*) => (Children2::new($w1, children!($($rest)*)));
}
pub mod prelude { pub mod prelude {
pub use crate::convert::{MyFrom, MyInto}; pub use crate::convert::{MyFrom, MyInto};
pub use crate::engine::Engine; pub use crate::engine::Engine;

View File

@ -94,8 +94,8 @@ impl Component for Tabs {
} }
pub struct Header { pub struct Header {
props: HeaderProps, pub props: HeaderProps,
tabs_ctx: Option<TabsContext<DefaultContext>> pub tabs_ctx: Option<TabsContext<DefaultContext>>
} }
pub enum HeaderEvent { pub enum HeaderEvent {
@ -136,7 +136,7 @@ impl Component for Header {
} }
pub struct Body { pub struct Body {
props: BodyProps pub props: BodyProps
} }
#[derive(Default)] #[derive(Default)]
@ -151,7 +151,7 @@ impl Component for Body {
} }
pub struct Tab { pub struct Tab {
props: TabProps pub props: TabProps
} }
#[derive(Default)] #[derive(Default)]

View File

@ -1,3 +0,0 @@
/target
**/*.rs.bk
Cargo.lock

View File

@ -1,14 +0,0 @@
cargo-features = ["edition"]
[package]
name = "maple-stdweb-ui"
version = "0.1.0"
authors = ["Andrey Tkachenko <andreytkachenko64@gmail.com>"]
edition = "2018"
[dependencies]
maple-core = {path = "../maple-core"}
maple-stdweb = {path = "../maple-stdweb"}
maple-stdui = {path = "../maple-stdui"}
maple-macro = {path = "../maple-macro"}
maple-stdweb-ui = {path = "../maple-stdweb-ui"}

View File

@ -1,9 +0,0 @@
#![feature(proc_macro_non_items, existential_type)]
pub mod panel;
pub mod tabs;
pub use self::panel::*;
pub use self::tabs::*;
pub use maple_stdweb_ui::HtmlEngine;

View File

@ -1,30 +0,0 @@
use maple_core::prelude::*;
use super::HtmlEngine;
use maple_macro::view;
use maple_stdweb::*;
use maple_stdui::prelude::Panel;
impl View for Panel {
type InputContext = DefaultContext;
type OutputContext = DefaultContext;
fn receive_context(&mut self, ctx: Self::InputContext) -> Self::OutputContext {
ctx
}
}
impl ViewX for Panel {
type Engine = HtmlEngine;
type ChildrenEngine = HtmlEngine;
existential type Renderable: Renderable<Engine = HtmlEngine>;
fn build<C>(self, children: Option<C>) -> Self::Renderable
where C: Renderable<Engine = Self::ChildrenEngine> + 'static
{
view! {
<Div class="panel">
{ ...children }
</Div>
}
}
}

View File

@ -1,111 +0,0 @@
use maple_core::prelude::*;
use maple_macro::view;
use maple_stdweb::*;
use maple_stdui::prelude::tabs::*;
use super::HtmlEngine;
use std::ops::Deref;
use std::rc::Rc;
use std::cell::RefCell;
impl View for Tabs {
type InputContext = DefaultContext;
type OutputContext = TabsContext<DefaultContext>;
fn receive_context(&mut self, ctx: Self::InputContext) -> Self::OutputContext {
TabsContext::wrap(ctx)
}
}
impl Tabs {
pub fn build<C>(self, children: Option<C>) -> impl Renderable<Engine = HtmlEngine>
where C: Renderable<Engine = HtmlEngine> + 'static
{
view! {
<Div class="tabs">
{ ... children }
</Div>
}
}
}
impl View for Header {
type InputContext = TabsContext<DefaultContext>;
type OutputContext = DefaultContext;
fn receive_context(&mut self, ctx: Self::InputContext) -> Self::OutputContext {
self.tabs_ctx = Some(ctx.clone());
ctx.unwrap()
}
}
impl Header {
pub fn build<C>(self, _children: Option<C>) -> impl Renderable<Engine = HtmlEngine>
where C: Renderable<Engine = HtmlEngine> + 'static
{
let tabs = self.tabs_ctx.map(|ctx|
ctx.get_tabs()
.iter()
.enumerate()
.map(|(i, tab)| view! {
<Span class="tab-title" click={move |_| HeaderEvent::Click(i)}>
{match tab {
Some(val) => val,
None => "<No title>"
}}
</Span>
})
.collect::<Vec<_>>());
view! {
<Div class="tabs-header">
{ ...tabs }
</Div>
}
}
}
impl View for Body {
type InputContext = TabsContext<DefaultContext>;
type OutputContext = TabsBodyContext<DefaultContext>;
fn receive_context(&mut self, ctx: Self::InputContext) -> Self::OutputContext {
TabsBodyContext::wrap(ctx)
}
}
impl Body {
pub fn build<C>(self, children: Option<C>) -> impl Renderable<Engine = HtmlEngine>
where C: Renderable<Engine = HtmlEngine> + 'static
{
view! {
<Div class="tab">
{ ... children }
</Div>
}
}
}
impl View for Tab {
type InputContext = TabsBodyContext<DefaultContext>;
type OutputContext = DefaultContext;
fn receive_context(&mut self, ctx: Self::InputContext) -> Self::OutputContext {
ctx.add_tab(self.props.title);
ctx.unwrap().unwrap()
}
}
impl Tab {
pub fn build<C>(self, children: Option<C>) -> impl Renderable<Engine = HtmlEngine>
where C: Renderable<Engine = HtmlEngine> + 'static
{
view! {
<Div class="tab">
{ ... children }
</Div>
}
}
}