Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
warfaj committed Oct 18, 2023
1 parent 0218942 commit b8457b0
Showing 1 changed file with 56 additions and 19 deletions.
75 changes: 56 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,70 @@ Writing Pax is intended to feel familiar and the language borrows many ideas fro
Following is a simple Pax component called `IncrementMe`:

```rust
//File: increment-me.rs

//File: lib.rs
use pax_lang::*;
use pax_std::{Text};
use pax_std::forms::{Button, ArgsButtonSubmit};
use pax_std::layout::{Stacker};
use pax_lang::api::*;
use pax_std::primitives::*;
use pax_std::types::*;
use pax_std::types::text::*;
use pax_std::components::Stacker;

/// Defines the Pax component `IncrementMe`, with template & settings specified in `increment-me.pax`.
#[derive(Pax)]
#[file("increment-me.pax")]
#[main]
#[file("increment-me.pax")]
pub struct IncrementMe {
pub num_clicks: Property<i64>
pub num_clicks: Property<u32>,
pub message: Property<String>,
}

impl IncrementMe {
pub async fn increment(&self, args: ArgsButtonSubmit) {
let old_num_clicks = self.num_clicks.get();
self.num_clicks.set(old_num_clicks + 1);
}
}
pub fn handle_did_mount(&mut self, ctx: RuntimeContext) {
self.num_clicks.set(0);
self.message.set("0 clicks".to_string());
}
pub fn increment(&mut self, ctx: RuntimeContext, args: ArgsClick){
let old_num_clicks = self.num_clicks.get();
self.num_clicks.set(old_num_clicks + 1);
self.message.set(format!("{} clicks", self.num_clicks.get()));
}

}
```
```rust
//File: increment-me.pax
//increment-me.pax
<Text text={self.message} class=centered id=text class=centered />
<Rectangle class=centered class=small @click=self.increment
fill={Fill::Solid(Color::rgba(0.0,0.0,0.0,1.0))}
corner_radii={RectangleCornerRadii::radii(10.0,10.0,10.0,10.0)}
/>

@handlers{
did_mount:handle_did_mount
}

<Stacker cells=2>
<Text text={"I have been clicked " + self.num_clicks + " times."}></Text>
<Button @submit=self.increment>"Increment me!"</Button>
</Stacker>
@settings {
.centered {
x: 50%
y: 50%
anchor_x: 50%
anchor_y: 50%
}
.small {
width: 120px
height: 120px
}
#text {
style: {
font: {Font::system("Times New Roman", FontStyle::Normal, FontWeight::Bold)},
font_size: 32px,
fill: {Color::rgba(1.0, 1.0, 1.0, 1.0)},
align_vertical: TextAlignVertical::Center,
align_horizontal: TextAlignHorizontal::Center,
align_multiline: TextAlignHorizontal::Center
}
}
}
```

Any Pax component like the example above may be included inside other Pax components, or may be mounted as the root of a stand-alone app.
Expand Down Expand Up @@ -107,8 +144,8 @@ Read more in [The Pax Docs](https://docs.pax.dev/)
### To build Pax projects as native macOS apps

- Building macOS apps requires running a Mac with macOS. This is a constraint enforced technically and legally by Apple.
- Install xcode `>=14.3` and Xcode command line utils: `xcode-select --install`
- SDK Version `macosx13.3`, Xcode version `>=14.3`
- Install xcode `>=15.0` and Xcode command line utils: `xcode-select --install`
- SDK Version `macosx13.3`, Xcode version `>=15.0`
- Current Minimum Deployment `13.0`
- Install all necessary build architectures for Rust, so that binaries can be built for both Intel and Apple Silicon macs
```
Expand Down

0 comments on commit b8457b0

Please sign in to comment.