Skip to content

Commit

Permalink
Take the label into account for child properties
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Jan 2, 2018
1 parent 7a5ece1 commit 35c0f28
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 34 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
name = "relm"
readme = "README.adoc"
repository = "https://github.com/antoyo/relm"
version = "0.11.0"
version = "0.12.0"
[badges.appveyor]
branch = "master"
repository = "antoyo/relm"
Expand All @@ -27,11 +27,11 @@ libc = "^0.2.22"

[dependencies.relm-core]
path = "relm-core"
version = "^0.11.0"
version = "^0.12.0"

[dependencies.relm-state]
path = "relm-state"
version = "^0.11.0"
version = "^0.12.0"

[dev-dependencies]
chrono = "^0.3.0"
Expand All @@ -42,15 +42,15 @@ version = "^0.3.0"

[dev-dependencies.relm-attributes]
path = "relm-attributes"
version = "^0.11.0"
version = "^0.12.0"

[dev-dependencies.relm-derive]
path = "relm-derive"
version = "^0.11.0"
version = "^0.12.0"

[dev-dependencies.relm-test]
path = "relm-test"
version = "^0.11.0"
version = "^0.12.0"

[features]
nightly = []
Expand Down
2 changes: 1 addition & 1 deletion examples/buttons-child-attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Widget for Win {
label: "-",
},
gtk::Button {
packing: {
child: {
expand: false,
fill: true,
pack_type: PackType::Start,
Expand Down
2 changes: 1 addition & 1 deletion examples/child-prop-attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Widget for Button {

view! {
gtk::Button {
packing: {
child: {
expand: false,
fill: true,
pack_type: PackType::Start,
Expand Down
2 changes: 1 addition & 1 deletion examples/container-attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Widget for Win {
gtk::Window {
VBox {
gtk::Button {
packing: {
child: {
padding: 20,
},
clicked => Increment,
Expand Down
154 changes: 154 additions & 0 deletions examples/grid-attributes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright (c) 2017 Boucher, Antoni <bouanto@zoho.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#![feature(proc_macro)]

extern crate gtk;
#[macro_use]
extern crate relm;
extern crate relm_attributes;
#[macro_use]
extern crate relm_derive;

use gtk::{
ButtonExt,
GridExt,
Inhibit,
LabelExt,
WidgetExt,
};
use relm::Widget;
use relm_attributes::widget;

use self::Msg::*;

#[derive(Msg)]
pub enum Msg {
Quit,
}

#[widget]
impl Widget for Win {
fn model() -> () {
}

fn update(&mut self, event: Msg) {
match event {
Quit => gtk::main_quit(),
}
}

view! {
gtk::Window {
gtk::Grid {
gtk::Button {
label: "7",
cell: {
left_attach: 0,
top_attach: 0,
},
},
gtk::Button {
label: "8",
cell: {
left_attach: 1,
top_attach: 0,
},
},
gtk::Button {
label: "9",
cell: {
left_attach: 2,
top_attach: 0,
},
},
gtk::Button {
label: "4",
cell: {
left_attach: 0,
top_attach: 1,
},
},
gtk::Button {
label: "5",
cell: {
left_attach: 1,
top_attach: 1,
},
},
gtk::Button {
label: "6",
cell: {
left_attach: 2,
top_attach: 1,
},
},
gtk::Button {
label: "1",
cell: {
left_attach: 0,
top_attach: 2,
},
},
gtk::Button {
label: "2",
cell: {
left_attach: 1,
top_attach: 2,
},
},
gtk::Button {
label: "3",
cell: {
left_attach: 2,
top_attach: 2,
},
},
gtk::Button {
label: "+/-",
cell: {
left_attach: 0,
top_attach: 3,
},
},
gtk::Button {
label: "0",
cell: {
left_attach: 1,
top_attach: 3,
},
},
gtk::Button {
label: ".",
cell: {
left_attach: 2,
top_attach: 3,
},
}
},
delete_event(_, _) => (Quit, Inhibit(false))
}
}
}

fn main() {
Win::run(()).unwrap();
}
2 changes: 1 addition & 1 deletion examples/multi-container-attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Widget for SplitBox {
},
#[container="right"]
MyFrame {
packing: {
child: {
padding: 10,
},
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Widget for Win {
gtk::Window {
gtk::Notebook {
gtk::Button {
tab: {
child: {
tab_label: Some("First Button"),
},
label: "+",
Expand Down
4 changes: 2 additions & 2 deletions relm-attributes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ documentation = "https://docs.rs/relm-attributes/"
license = "MIT"
name = "relm-attributes"
repository = "https://github.com/antoyo/relm"
version = "0.11.0"
version = "0.12.0"

[dependencies]
env_logger = "^0.4.2"
Expand All @@ -15,7 +15,7 @@ syn = "^0.11.9"

[dependencies.relm-gen-widget]
path = "../relm-gen-widget"
version = "^0.11.0"
version = "^0.12.0"

[lib]
proc-macro = true
2 changes: 1 addition & 1 deletion relm-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ documentation = "https://docs.rs/relm-core/"
license = "MIT"
name = "relm-core"
repository = "https://github.com/antoyo/relm"
version = "0.11.0"
version = "0.12.0"

[dependencies]
futures = "^0.1.14"
Expand Down
4 changes: 2 additions & 2 deletions relm-derive-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ description = "Common derive implementation internally used by relm crates"
license = "MIT"
name = "relm-derive-common"
repository = "https://github.com/antoyo/relm"
version = "0.11.0"
version = "0.12.0"

[dependencies]
quote = "^0.3.15"
syn = "^0.11.11"

[dependencies.relm-gen-widget]
path = "../relm-gen-widget"
version = "^0.11.0"
version = "^0.12.0"
4 changes: 2 additions & 2 deletions relm-derive-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["Antoni Boucher <bouanto@zoho.com>"]
description = "Custom derive required by the relm-state crate."
license = "MIT"
name = "relm-derive-state"
version = "0.11.0"
version = "0.12.0"
repository = "https://github.com/antoyo/relm"

[lib]
Expand All @@ -14,4 +14,4 @@ syn = "^0.11.8"

[dependencies.relm-derive-common]
path = "../relm-derive-common"
version = "^0.11.0"
version = "^0.12.0"
6 changes: 3 additions & 3 deletions relm-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ documentation = "https://docs.rs/relm-derive/"
license = "MIT"
name = "relm-derive"
repository = "https://github.com/antoyo/relm"
version = "0.11.0"
version = "0.12.0"

[lib]
proc-macro = true
Expand All @@ -16,8 +16,8 @@ syn = "^0.11.8"

[dependencies.relm-derive-common]
path = "../relm-derive-common"
version = "^0.11.0"
version = "^0.12.0"

[dependencies.relm-gen-widget]
path = "../relm-gen-widget"
version = "^0.11.0"
version = "^0.12.0"
2 changes: 1 addition & 1 deletion relm-gen-widget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ documentation = "https://docs.rs/relm-gen-widget/"
license = "MIT"
name = "relm-gen-widget"
repository = "https://github.com/antoyo/relm"
version = "0.11.0"
version = "0.12.0"

[dependencies]
lazy_static = "^0.2.4"
Expand Down
4 changes: 2 additions & 2 deletions relm-gen-widget/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,8 @@ fn gen_set_child_prop_calls(widget: &Widget, parent: Option<&Ident>, parent_widg
let widget_name = &widget.name;
let mut child_properties = vec![];
if let Some(parent) = parent {
for (key, value) in &widget.child_properties {
let property_func = Ident::new(format!("set_child_{}", key));
for (&(ref ident, ref key), value) in &widget.child_properties {
let property_func = Ident::new(format!("set_{}_{}", ident, key));
let parent =
if parent_widget_type == IsGtk {
quote! {
Expand Down
4 changes: 2 additions & 2 deletions relm-gen-widget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ fn get_second_param_type(sig: &MethodSig) -> Ty {
fn gen_set_child_prop_calls(widget: &Widget) -> Option<ImplItem> {
let mut tokens = Tokens::new();
let widget_name = &widget.name;
for (key, value) in &widget.child_properties {
let property_func = Ident::new(format!("set_child_{}", key));
for (&(ref ident, ref key), value) in &widget.child_properties {
let property_func = Ident::new(format!("set_{}_{}", ident, key));
tokens.append(quote! {
parent.#property_func(&self.#widget_name, #value);
});
Expand Down
Loading

0 comments on commit 35c0f28

Please sign in to comment.