Last active
November 26, 2020 22:40
-
-
Save Autofire/f205afb1df6e7a33872fe125924846c6 to your computer and use it in GitHub Desktop.
Project which I cannot get text to update in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use orbtk::prelude::*; | |
pub use self::main_state::*; | |
pub use self::main_view::*; | |
mod main_state; | |
mod main_view; | |
fn main() { | |
Application::from_name("orbtk-sandbox") | |
.window(move |ctx| { | |
Window::new() | |
.title("orbtk-sandbox") | |
.position((100.0, 100.0)) | |
.size(300.0, 300.0) | |
.resizeable(true) | |
.child(MainView::new().title("Hello OrbTk").build(ctx)) | |
.build(ctx) | |
}) | |
.run(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use orbtk::prelude::*; | |
use crate::MainView; | |
pub enum Message { | |
Encrypt(String), | |
Decrypt(String), | |
Clear, | |
} | |
#[derive(Default, AsAny)] | |
pub struct MainState { | |
path: String | |
} | |
impl State for MainState { | |
//fn update(&mut self, _: &mut Registry, _: &mut Context) { | |
//} | |
fn messages( | |
&mut self, | |
mut messages: MessageReader, | |
_registry: &mut Registry, | |
ctx: &mut Context, | |
) { | |
for message in messages.read::<Message>() { | |
match message { | |
Message::Encrypt(p) => { | |
println!("Encrypt: {}", p); | |
self.path = p.clone(); | |
MainView::target_file_set(&mut ctx.widget(), String::from("Updated string")); | |
ctx.child("path_text") | |
.get_mut::<String>("text").push('a'); //= String::from("updated"); | |
}, | |
Message::Decrypt(p) => { | |
println!("Decrypt: {}", p); | |
}, | |
Message::Clear => { | |
println!("Clear"); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use orbtk::prelude::*; | |
use crate::{MainState, Message}; | |
widget!( | |
DropArea: DropHandler { | |
text: String | |
} | |
); | |
impl Template for DropArea { | |
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { | |
let test = Message::Encrypt(String::from("Hi")); | |
self.name("Drop Area") | |
.text("Hello") | |
.child(Stack::new() | |
.margin(10) | |
.spacing(10) | |
.child(ImageWidget::new() | |
.image("assets/dnd.png") | |
.h_align("center") | |
.build(ctx) | |
) | |
.child(TextBlock::new() | |
.text(id) | |
.id("path_text") | |
.h_align("center") | |
.build(ctx) | |
) | |
.build(ctx) | |
) | |
} | |
} | |
widget!( | |
MainView<MainState> { | |
title: String, | |
target_file: String | |
} | |
); | |
impl Template for MainView { | |
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { | |
let drop_page = DropArea::new() | |
.on_drop_file(move |states,path,_| { | |
println!("event triggered"); | |
println!("{}", path); | |
//DropArea::text_set(&mut sctx.get(), path); | |
states.send_message(Message::Encrypt(path), id); | |
true | |
}) | |
.text(("target_file", id)) | |
.v_align("center") | |
.h_align("center") | |
.build(ctx); | |
// This is only for testing purposes; my hunch was that having the | |
// text nested within an object might be at fault. Sadly it's not, | |
// but it makes testing convenient. | |
let test_button = Button::new() | |
.text(("target_file", id)) | |
.on_click(move |states, _| { | |
states.send_message(Message::Encrypt(String::from("Hello")), id); | |
true | |
}) | |
.build(ctx); | |
self.name("MainView") | |
.target_file("No file") | |
.child(test_button) | |
.child(drop_page) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment