Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next #60

Merged
merged 4 commits into from
Mar 13, 2024
Merged

Next #60

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/book-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
- run: mdbook build -d book
working-directory: ./

- name: Link Checker
uses: lycheeverse/[email protected]
with:
args: book
fail: true

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
# Only deploy when ref is next
Expand All @@ -60,4 +66,5 @@ jobs:
- uses: codespell-project/actions-codespell@master
with:
check_filenames: true
path: src
ignore_words_list: crate,statics,relm
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ members = [

[dev-dependencies]
rand = "0.8.5"
relm4 = "0.6.2"
relm4-components = "0.6.2"
relm4 = "0.7.0"
relm4-components = "0.7.0"
tokio = { version = "1.25", features = ["rt", "macros", "time", "rt-multi-thread", "sync"] }
tracker = "0.2.0"
10 changes: 5 additions & 5 deletions examples/alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl SimpleComponent for Alert {
// ANCHOR: init_model
fn init(
settings: AlertSettings,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Alert {
Expand Down Expand Up @@ -177,7 +177,7 @@ impl SimpleComponent for App {

connect_close_request[sender] => move |_| {
sender.input(AppMsg::CloseRequest);
gtk::Inhibit(true)
gtk::glib::Propagation::Stop
},

gtk::Box {
Expand Down Expand Up @@ -245,12 +245,12 @@ impl SimpleComponent for App {
}

// ANCHOR: app_init
fn init(_: (), root: &Self::Root, sender: ComponentSender<Self>) -> ComponentParts<Self> {
fn init(_: (), root: Self::Root, sender: ComponentSender<Self>) -> ComponentParts<Self> {
let model = App {
counter: 0,
alert_toggle: false,
dialog: Alert::builder()
.transient_for(root)
.transient_for(&root)
.launch(AlertSettings {
text: String::from("Do you want to quit without saving? (First alert)"),
secondary_text: Some(String::from("Your counter hasn't reached 42 yet")),
Expand All @@ -262,7 +262,7 @@ impl SimpleComponent for App {
})
.forward(sender.input_sender(), convert_alert_response),
second_dialog: Alert::builder()
.transient_for(root)
.transient_for(&root)
.launch(AlertSettings {
text: String::from("Do you want to quit without saving? (Second alert)"),
secondary_text: Some(String::from("Your counter hasn't reached 42 yet")),
Expand Down
4 changes: 2 additions & 2 deletions examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ impl AsyncComponent for App {
}

// ANCHOR: init_loading_widgets
fn init_loading_widgets(root: &mut Self::Root) -> Option<LoadingWidgets> {
fn init_loading_widgets(root: Self::Root) -> Option<LoadingWidgets> {
view! {
#[local_ref]
#[local]
root {
set_title: Some("Simple app"),
set_default_size: (300, 100),
Expand Down
4 changes: 2 additions & 2 deletions examples/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Component for CommandModel {
}

// Initialize the UI.
fn init(_: Self::Init, _: &Self::Root, _: ComponentSender<Self>) -> ComponentParts<Self> {
fn init(_: Self::Init, _: Self::Root, _: ComponentSender<Self>) -> ComponentParts<Self> {
todo!()
}

Expand Down Expand Up @@ -99,7 +99,7 @@ impl Component for SyncCommandModel {
}

// Initialize the UI.
fn init(_: Self::Init, _: &Self::Root, _: ComponentSender<Self>) -> ComponentParts<Self> {
fn init(_: Self::Init, _: Self::Root, _: ComponentSender<Self>) -> ComponentParts<Self> {
todo!()
}

Expand Down
10 changes: 5 additions & 5 deletions examples/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl SimpleComponent for HeaderModel {

fn init(
_params: Self::Init,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = HeaderModel;
Expand Down Expand Up @@ -127,7 +127,7 @@ impl SimpleComponent for DialogModel {

fn init(
params: Self::Init,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = DialogModel { hidden: params };
Expand Down Expand Up @@ -191,7 +191,7 @@ impl SimpleComponent for AppModel {
},
connect_close_request[sender] => move |_| {
sender.input(AppMsg::CloseRequest);
gtk::Inhibit(true)
gtk::glib::Propagation::Stop
}
}
}
Expand All @@ -200,7 +200,7 @@ impl SimpleComponent for AppModel {
// ANCHOR: app_init
fn init(
params: Self::Init,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
// ANCHOR: forward
Expand All @@ -215,7 +215,7 @@ impl SimpleComponent for AppModel {
// ANCHOR_END: forward

let dialog = DialogModel::builder()
.transient_for(root)
.transient_for(&root)
.launch(true)
.forward(sender.input_sender(), |msg| match msg {
DialogOutput::Close => AppMsg::Close,
Expand Down
34 changes: 16 additions & 18 deletions examples/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ impl FactoryComponent for Counter {
type Input = CounterMsg;
type Output = CounterOutput;
type CommandOutput = ();
type Widgets = CounterWidgets;
type ParentInput = AppMsg;
type ParentWidget = gtk::Box;
// ANCHOR_END: factory_impl_start

// ANCHOR: factory_view
view! {
root = gtk::Box {
#[root]
gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
set_spacing: 10,

Expand All @@ -69,39 +68,29 @@ impl FactoryComponent for Counter {
gtk::Button {
set_label: "Up",
connect_clicked[sender, index] => move |_| {
sender.output(CounterOutput::MoveUp(index.clone()))
sender.output(CounterOutput::MoveUp(index.clone())).unwrap();
}
},

#[name(move_down_button)]
gtk::Button {
set_label: "Down",
connect_clicked[sender, index] => move |_| {
sender.output(CounterOutput::MoveDown(index.clone()))
sender.output(CounterOutput::MoveDown(index.clone())).unwrap();
}
},

#[name(to_front_button)]
gtk::Button {
set_label: "To Start",
connect_clicked[sender, index] => move |_| {
sender.output(CounterOutput::SendFront(index.clone()))
sender.output(CounterOutput::SendFront(index.clone())).unwrap();
}
}
}
}
// ANCHOR_END: factory_view

// ANCHOR: output_to_parent
fn forward_to_parent(output: Self::Output) -> Option<AppMsg> {
Some(match output {
CounterOutput::SendFront(index) => AppMsg::SendFront(index),
CounterOutput::MoveUp(index) => AppMsg::MoveUp(index),
CounterOutput::MoveDown(index) => AppMsg::MoveDown(index),
})
}
// ANCHOR_END: output_to_parent

// ANCHOR: factory_init_model
fn init_model(value: Self::Init, _index: &DynamicIndex, _sender: FactorySender<Self>) -> Self {
Self { value }
Expand Down Expand Up @@ -180,10 +169,19 @@ impl SimpleComponent for App {
// Initialize the UI.
fn init(
counter: Self::Init,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let counters = FactoryVecDeque::new(gtk::Box::default(), sender.input_sender());
// ANCHOR: output_to_parent
let counters = FactoryVecDeque::builder()
.launch(gtk::Box::default())
.forward(sender.input_sender(), |output| match output {
CounterOutput::SendFront(index) => AppMsg::SendFront(index),
CounterOutput::MoveUp(index) => AppMsg::MoveUp(index),
CounterOutput::MoveDown(index) => AppMsg::MoveDown(index),
});
// ANCHOR_END: output_to_parent

let model = App {
created_widgets: counter,
counters,
Expand Down
2 changes: 1 addition & 1 deletion examples/libadwaita/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"

[dev-dependencies]
rand = "0.8.4"
relm4 = { version = "0.6.0", features = ["libadwaita"] }
relm4 = { version = "0.7.0-beta.2", features = ["libadwaita"] }

[[example]]
name = "simple_manual"
Expand Down
2 changes: 1 addition & 1 deletion examples/libadwaita/simple_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl SimpleComponent for AppModel {

fn init(
counter: Self::Init,
window: &Self::Root,
window: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = AppModel { counter };
Expand Down
2 changes: 1 addition & 1 deletion examples/macro_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl SimpleComponent for AppModel {
// Initialize the UI.
fn init(
init: Self::Init,
renamed_root: &Self::Root,
renamed_root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let counter = AppModel {
Expand Down
10 changes: 3 additions & 7 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,14 @@ impl SimpleComponent for AppModel {

gtk::Button {
set_label: "Increment",
connect_clicked[sender] => move |_| {
sender.input(AppMsg::Increment);
}
connect_clicked => AppMsg::Increment
},

// ANCHOR: widget_assign_fn
gtk::Button::with_label("Decrement") {
// ANCHOR_END: widget_assign_fn
// ANCHOR: connect
connect_clicked[sender] => move |_| {
sender.input(AppMsg::Decrement);
}
connect_clicked => AppMsg::Decrement
// ANCHOR_END: connect
},

Expand All @@ -64,7 +60,7 @@ impl SimpleComponent for AppModel {
// Initialize the UI.
fn init(
counter: Self::Init,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = AppModel { counter };
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl SimpleComponent for AppModel {
/// Initialize the UI and model.
fn init(
counter: Self::Init,
window: &Self::Root,
window: Self::Root,
sender: ComponentSender<Self>,
) -> relm4::ComponentParts<Self> {
let model = AppModel { counter };
Expand Down
2 changes: 1 addition & 1 deletion examples/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl SimpleComponent for AppModel {
}

// Initialize the UI.
fn init(_: Self::Init, _: &Self::Root, _: ComponentSender<Self>) -> ComponentParts<Self> {
fn init(_: Self::Init, _: Self::Root, _: ComponentSender<Self>) -> ComponentParts<Self> {
todo!()
}

Expand Down
9 changes: 4 additions & 5 deletions examples/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl SimpleComponent for AppModel {
// Initialize the UI.
fn init(
_params: Self::Init,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
// ANCHOR: model_init
Expand All @@ -113,12 +113,8 @@ impl SimpleComponent for AppModel {
};
// ANCHOR_END: model_init

// ANCHOR: post_init
relm4::set_global_css(".identical { background: #00ad5c; }");

// Insert the macro code generation here
let widgets = view_output!();
// ANCHOR_END: post_init

ComponentParts { model, widgets }
}
Expand All @@ -141,8 +137,11 @@ impl SimpleComponent for AppModel {
// ANCHOR_END: update
}

// ANCHOR: main
fn main() {
let app = RelmApp::new("relm4.test.simple");
app.set_global_css(".identical { background: #00ad5c; }");
app.run::<AppModel>(());
}
// ANCHOR_END: main
// ANCHOR_END: all
2 changes: 1 addition & 1 deletion examples/widget_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl SimpleComponent for AppModel {

fn init(
counter: Self::Init,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Self { counter };
Expand Down
2 changes: 1 addition & 1 deletion examples/widget_template_nested_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl SimpleComponent for AppModel {

fn init(
_init_param: Self::Init,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Self {
Expand Down
2 changes: 1 addition & 1 deletion examples/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl SimpleComponent for AppModel {
}

// ANCHOR: worker_construction
fn init(_: (), root: &Self::Root, sender: ComponentSender<Self>) -> ComponentParts<Self> {
fn init(_: (), root: Self::Root, sender: ComponentSender<Self>) -> ComponentParts<Self> {
let model = AppModel {
counter: 0,
worker: AsyncHandler::builder()
Expand Down
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
- [0.2 to 0.4](migrations/0_2_to_0_4.md)
- [0.4 to 0.5](migrations/0_4_to_0_5.md)
- [0.5 to 0.6](migrations/0_5_to_0_6.md)
- [0.6 to 0.7](migrations/0_6_to_0_7.md)
Loading
Loading