Skip to content

Commit

Permalink
Bugfix: Load showcase stylesheets with include macro and style tag on…
Browse files Browse the repository at this point in the history
… example change (#992)

Bugfix: Loading showcase stylesheets into styletage allows styles for
different examples to be loaded after selection.
  • Loading branch information
rharriso authored Mar 4, 2020
1 parent 686c5d6 commit a94f630
Show file tree
Hide file tree
Showing 5 changed files with 545 additions and 8 deletions.
5 changes: 3 additions & 2 deletions examples/game_of_life/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ impl Cellule {

fn wrap(coord: isize, range: isize) -> usize {
let result = if coord < 0 {
(coord + range)
coord + range
} else if coord >= range {
(coord - range)
coord - range
} else {
coord
};
Expand Down Expand Up @@ -160,6 +160,7 @@ impl Component for Model {
let callback = link.callback(|_| Msg::Tick);
let mut interval = IntervalService::new();
let handle = interval.spawn(Duration::from_millis(200), callback);

Model {
link,
active: false,
Expand Down
2 changes: 1 addition & 1 deletion examples/game_of_life/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ body {
line-height: 1.4em;
color: #4d4d4d;
min-width: 230px;
max-width: 550px;
max-width: 1000px;
margin: 0 auto;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
Expand Down
14 changes: 14 additions & 0 deletions examples/showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl Component for Model {
fn view(&self) -> Html {
html! {
<div id="fullscreen">
<style>{ self.view_style() }</style>
<div id="left_pane">
<h2>{ "Yew showcase" }</h2>
<Select<Scene>
Expand Down Expand Up @@ -130,6 +131,19 @@ impl Model {
}
}
}

fn view_style(&self) -> &str {
if let Some(scene) = self.scene.as_ref() {
match scene {
Scene::GameOfLife => { include_str!("../../game_of_life/static/styles.css") },
Scene::LargeTable => { include_str!("../../large_table/static/styles.css") },
Scene::Todomvc => { include_str!("../static/todomvc.css") },
_ => { "" },
}
} else {
""
}
}
}

fn main() {
Expand Down
11 changes: 6 additions & 5 deletions examples/showcase/static/styles.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
html, body, #fullscreen {
width: 100%;
display: flex;
flex-direction: row;
}

#left_pane {
position: absolute;
width: 20%;
display: flex;
flex-direction: column;
}

#right_pane {
position: absolute;
width: 80%;
left: 20%;
display: flex;
}
Loading

0 comments on commit a94f630

Please sign in to comment.