-
-
Notifications
You must be signed in to change notification settings - Fork 79
Open
Description
I just went through the mini tutorial in the README.md, and I really like this library to provide structure to my GTK-rs applications, but I need to use a gtk::TextView and when I tried to make it work with the view! macro it failed.
Code:
pub struct Model{
file_contents: String,
// … more things
}
//in view!
gtk::TextView{
text: {
let text_buffer = TextBuffer::new(None);
text_buffer.set_text(self.model.file_contents);
Some(text_buffer)
}
}Error:
error: expected identifier
--> src/main.rs:60:25
|
60 | let text_buffer = TextBuffer::new(None);
| ^^^
Versions of my dependencies:
[dependencies]
relm = "0.21.0"
relm-derive = "0.21.0"
gtk = "0.9.2"MCVE (might have some other trivial errors and isn't complete (I wanted to make a trivial notepad clone to try out the library), but it demonstrates the issue):
use std::path::PathBuf;
use gtk::Orientation;
use relm_derive::{widget, Msg};
use relm::Widget;
use gtk::prelude::*;
#[derive(Msg)]
pub enum Msg{
OpenButton,
OpenFile,
SaveButton
}
pub struct Model{
path: Option<PathBuf>,
file_contents: String
}
#[widget]
impl Widget for Win{
fn model() -> Model{
Model{
path: None,
file_contents: "".into()
}
}
fn update(&mut self, event: Msg) {
match event{
Msg::OpenButton => {},
Msg::OpenFile => {},
Msg::SaveButton => {}
}
}
view!{
gtk::Window {
gtk::Box {
orientation: Orientation::Vertical,
gtk::Box {
orientation: Orientation::Horizontal,
gtk::Button {
clicked => Msg::OpenButton,
label: "Open"
},
gtk::Button {
clicked => Msg::SaveButton,
label: "Save"
},
gtk::Label {
text: match &self.model.path {
Some(path) => &path.into_os_string().into_string().unwrap_or("Improper OS string in path".into()),
None => "File Not Saved".into()
}
}
},
gtk::TextView{
text: {
let text_buffer = TextBuffer::new(None);
text_buffer.set_text(self.model.file_contents);
Some(text_buffer)
}
}
}
}
}
}
fn main() {
Win::run(()).unwrap();
}I assume that this means that the view! macro doesn't support blocks, but given this, I don't see how I can use a gtk::TextView.
Metadata
Metadata
Assignees
Labels
No labels