Giter VIP home page Giter VIP logo

Comments (7)

nazmulidris avatar nazmulidris commented on May 27, 2024

This commit 9072d962a9e643cdf868803a23bbbe01dac57ae2 is the first step towards assembling the "React JSX"-like syntax from scratch. It makes the following changes.

Associated commit in r3bl-org/r3bl-cmdr@9072d962a9e643cdf868803a23bbbe01dac57ae2

Original code:

tw_surface.box_start(TWBoxProps {
  styles: tw_surface.stylesheet.find_styles_by_ids(vec!["style1"]),
  id: COL_1_ID.into(),
  dir: Direction::Vertical,
  req_size: (50, 100).try_into()?,
})?;

Next, use the box_props! macro:

tw_surface.box_start(box_props! {
  COL_1_ID,
  Direction::Vertical,
  (50, 100).try_into()?,
  get_styles! { from: tw_surface.stylesheet => ["style1", "style2"] }
})?;

Finally, use the box_start! macro:

box_start! {
  in: tw_surface,
  COL_1_ID,
  Direction::Vertical,
  (50, 100).try_into()?,
  ["style1", "style2"]
};

from r3bl-open-core.

nazmulidris avatar nazmulidris commented on May 27, 2024

This commit de38450 adds the following functionality.

Associated commit in r3bl-org/r3bl-cmdr@8024029e4d5ead398c61ae5f6f1ed31188943929

Use render_component macro to simplify this:

if let Some(shared_component) = self.component_registry.get(COL_2_ID) {
  let current_box = tw_surface.current_box()?;
  let queue = shared_component
    .write()
    .await
    .render(&self.has_focus, current_box, state, shared_store)
    .await?;
  tw_surface.render_buffer += queue;
}

into this:

render_component! {
  in: tw_surface,
  from: self.component_registry,
  id: COL_1_ID,
  has_focus: self.has_focus,
  state: state,
  shared_store: shared_store
};

from r3bl-open-core.

nazmulidris avatar nazmulidris commented on May 27, 2024

This commit f65dc6e moves all the JSX-like syntax stuff into RSX module:
https://github.com/r3bl-org/r3bl-rs-utils/blob/main/src/tui/rsx

from r3bl-open-core.

nazmulidris avatar nazmulidris commented on May 27, 2024

These commits: [ 1d50f2e and r3bl-org/r3bl-cmdr@590e749788da1afeb46340823782c9e619d68357 ] introduce the make_box! macro. This is the start of the RSX declarative style of syntax for creating layout.

This macro is possible due to TT munching in declarative macros: https://veykril.github.io/tlborm/decl-macros/patterns/tt-muncher.html

Here's the new code.

make_box! {
  in:    tw_surface,
  id:    COL_1_ID,
  dir:   Direction::Vertical,
  size:  (50, 100).try_into()?,
  style: ["style1", "style2"],
  render: {
    from:         self.component_registry,
    component_id: COL_1_ID,
    has_focus:    self.has_focus,
    state:        state,
    shared_store: shared_store
  }
}

Here's the old code it replaces:

box_start! {
  in: tw_surface,
  COL_1_ID,
  Direction::Vertical,
  (50, 100).try_into()?,
  ["style1", "style2"]
};
render_component! {
  in: tw_surface,
  from: self.component_registry,
  id: COL_1_ID,
  has_focus: self.has_focus,
  state: state,
  shared_store: shared_store
};
tw_surface.box_end()?;

And here's the original code w/out macros:

tw_surface.box_start(TWBoxProps {
  styles: tw_surface.stylesheet.find_styles_by_ids(vec!["style2"]),
  id: COL_2_ID.to_string(),
  dir: Direction::Vertical,
  req_size: (50, 100).try_into()?,
})?;

// OPTIMIZE: macro?
if let Some(shared_component) = self.component_registry.get(COL_2_ID) {
  let current_box = tw_surface.current_box()?;
  let queue = shared_component
    .write()
    .await
    .render(&self.has_focus, current_box, state, shared_store)
    .await?;
  tw_surface.render_buffer += queue;
}

tw_surface.box_end()?;

from r3bl-open-core.

nazmulidris avatar nazmulidris commented on May 27, 2024

The box_start! macro is further simplified by 0a560d8 and r3bl-org/r3bl-cmdr@5b13bde38a4377ed6a72d7efe81698231642b2dd.

make_box! {
  in:    tw_surface,
  id:    COL_1_ID,
  dir:   Direction::Vertical,
  size:  (50, 100).try_into()?,
  style: ["style1"],
  render: {
    from:         self.component_registry,
    has_focus:    self.has_focus,
    state:        state,
    shared_store: shared_store
  }
}

from r3bl-open-core.

nazmulidris avatar nazmulidris commented on May 27, 2024

All the macros are now cleaned up so they all have clearly identified fields. So in:, id:, dir:, etc. are all consistently passed thru.

from r3bl-open-core.

nazmulidris avatar nazmulidris commented on May 27, 2024

Add a new macro surface_start to make it a little easier to work w/ Surface. Rename TWSurface -> Surface. Drop the TW prefix on all names; except for when they collide w/ other common names like Box and Command.

let mut surface = surface_start! {
  stylesheet: style_helpers::create_stylesheet()?,
  pos: (0, 0).into(),
  size: (window_size.cols, window_size.rows - 1).into(), // Leave row at bottom for message.
};

self
  .create_main_container(&mut surface, state, shared_store)
  .await?;

surface.surface_end()?;

status_bar_helpers::render(&mut surface.render_buffer, window_size);

surface.render_buffer

✅ The following commits add this functionality:

  1. b30e686
    r3bl-org/r3bl-cmdr@12238df194ed8032f7ce28205a28f51029e4d5d5
  2. 16a1ebe r3b-org/r3bl-cmdr@7bc1499349dca61f3412cc79129386cf508f4b2b

from r3bl-open-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.