Skip to content

Commit

Permalink
feat: add Stack widget (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamilsan authored Nov 4, 2023
1 parent 801e88f commit b892f48
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lerni"
version = "0.0.2"
version = "0.0.3"
edition = "2021"
license = "MIT"
description = "Lerni content framework"
Expand Down Expand Up @@ -50,6 +50,10 @@ crate-type = ["cdylib"]
name = "rows_cols"
crate-type = ["cdylib"]

[[example]]
name = "stack"
crate-type = ["cdylib"]

[[example]]
name = "svg"
crate-type = ["cdylib"]
Expand Down
4 changes: 4 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ <h1>Lerni Examples</h1>
<a href="/svg/">SVG</a>
(<a href="https://github.com/lerni-edu/lerni/blob/master/examples/svg.rs" target="_blank">source</a>)
</li>
<li>
<a href="/stack/">Stack</a>
(<a href="https://github.com/lerni-edu/lerni/blob/master/examples/stack.rs" target="_blank">source</a>)
</li>
</ul>
</div>
</body>
Expand Down
15 changes: 15 additions & 0 deletions dist/stack/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en" class="has-background-light">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Lerni "Stack" Example</title>
<link rel="stylesheet" href="/css/bulma.min.css" />
<link rel="stylesheet" href="/css/fas.min.css" />
<link rel="preload" href="/stack/stack_bg.wasm" as="fetch" type="application/wasm" crossorigin="" />
<link rel="modulepreload" href="/stack/stack.js" />
</head>
<body>
<script type="module">import init from '/stack/stack.js';init('/stack/stack_bg.wasm');</script>
</body>
</html>
19 changes: 19 additions & 0 deletions examples/stack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use leptos::*;
use lerni::*;

#[component]
pub fn StackExample() -> impl IntoView {
view! {
<Slide>
<Stack count=2>
<SvgFile width=128 height=64 scale=2.0 src=include_str!("logo.svg") />
<Label font_size=96 valign=VAlign::Top>"Hello,"</Label>
</Stack>
</Slide>
}
}

#[wasm_bindgen(start)]
pub fn main() {
lerni::start(StackExample);
}
2 changes: 1 addition & 1 deletion examples/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lerni::*;
#[component]
pub fn SvgExample() -> impl IntoView {
view! {
<Slide background_image="/img/lerni-bg.svg".into()>
<Slide background_image="/img/lerni-bg.svg">
<Grid cols=3 rows=3 border_width=4 padding=20>
<SvgFile width=128 height=64 src=include_str!("logo.svg") />
<Svg width=128 height=64 scale=3.0>{include!("logo.svg-rs")}</Svg>
Expand Down
1 change: 1 addition & 0 deletions scripts/examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ grid \
hello_world \
pointer \
rows_cols \
stack \
svg \
text \
"
Expand Down
2 changes: 2 additions & 0 deletions src/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod label;
mod row;
mod slide;
mod slideshow;
mod stack;
mod svg;
mod text;

Expand All @@ -17,6 +18,7 @@ pub use label::Label;
pub use row::Row;
pub use slide::Slide;
pub use slideshow::SlideShow;
pub use stack::Stack;
pub use svg::{Svg, SvgFile};
pub use text::Text;

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/slide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn Slide(
#[prop(default = WIDTH)] width: i32,
#[prop(default = HEIGHT)] height: i32,
#[prop(optional)] background_color: Color,
#[prop(optional)] background_image: String,
#[prop(optional, into)] background_image: String,
#[prop(optional)] pointer: MaybeSignal<bool>,
#[prop(optional)] blur: MaybeSignal<bool>,
#[prop(default = 15)] blur_radius: i32,
Expand Down
24 changes: 24 additions & 0 deletions src/widgets/stack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use leptos::*;

use crate::{use_frame, use_frames, Frame};

/// Stack of widgets.
#[component]
pub fn Stack(count: usize, children: Children) -> impl IntoView {
let f = use_frame();
{
let frames = use_frames();
let mut frames = frames.borrow_mut();
for _ in 0..count {
let frame = Frame {
x: f.x,
y: f.y,
width: f.width,
height: f.height,
};
frames.push(frame);
}
}

children().nodes.into_iter().take(count).collect_view()
}

0 comments on commit b892f48

Please sign in to comment.