Skip to content

Commit

Permalink
Pass context to text nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jul 10, 2024
1 parent 5f972b9 commit 01e0bc5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/blitz-masonry/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![windows_subsystem = "windows"]

use blitz_masonry::Element;
use blitz_masonry::{Element, Text};
use masonry::app_driver::{AppDriver, DriverCtx};
use masonry::widget::{Label, RootWidget};
use masonry::{Action, WidgetId};
Expand All @@ -14,7 +14,7 @@ impl AppDriver for Driver {

pub fn main() {
let mut h1 = Element::new("h1");
h1.append_child(Label::new("Hello, World!"));
h1.append_child(Text::new("Hello, World!"));

let mut div = Element::new("div");
div.font_size = Some(100.0);
Expand Down
16 changes: 13 additions & 3 deletions packages/blitz-masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ use masonry::{
};
use smallvec::{smallvec, SmallVec};

mod text;
pub use self::text::Text;

mod viewport;
use self::viewport::Viewport;

pub enum Node {
Element(WidgetPod<Element>),
Text(WidgetPod<Label>),
Text(WidgetPod<Text>),
}

impl From<Element> for Node {
Expand All @@ -24,8 +27,8 @@ impl From<Element> for Node {
}
}

impl From<Label> for Node {
fn from(value: Label) -> Self {
impl From<Text> for Node {
fn from(value: Text) -> Self {
Node::Text(WidgetPod::new(value))
}
}
Expand Down Expand Up @@ -85,6 +88,13 @@ impl Widget for Element {
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, event: &StatusChange) {}

fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
let cx = Context::current().unwrap_or_default();
dbg!(&cx);
if let Some(font_size) = self.font_size {
cx.inner.borrow_mut().font_size = font_size;
}
cx.enter();

for child in &mut self.children {
match child {
Node::Element(elem) => elem.lifecycle(ctx, event),
Expand Down

0 comments on commit 01e0bc5

Please sign in to comment.