Programming isn’t my primary job role at work, but I use Rust for building small applications for work. Every time I get back into programming with Iced, new cool changes have been implemented. So, I am constantly learning.
I’m trying to build a MouseArea interaction to eventually develop a functionality for a Drag & Drop from one application to another. I created a container with a Text label and TextInput. Then, wrapped into a MouseArea for the mouse interaction. The .on_relase() is transmitting the Message correctly for a println!(). I wanted to try interactions for the active Iced window. Simply, trying to resize the window with MouseArea.on_release(). I don’t think I am understanding the window::Action. I can see the println!() message, but there is no window action. I would appreciate help explaining what I am missing:
struct AppState {
trigger: String,
bin_word: Option<BinWord>,
window_id: Id,
clipboard: Clipboard,
}
impl Default for AppState {
fn default() -> Self {
AppState {
bin_word: None,
trigger: String::default(),
window_id: Id::unique(),
clipboard: Clipboard::unconnected(),
}
}
}
#[derive(Debug, Clone)]
enum Message {
TriggerChanged(String),
TriggerSubmitted(String),
TriggerDropped,
}
fn update(app_state: &mut AppState, message: Message) {
match message {
Message::TriggerChanged(value) => {app_state.trigger = String::from(value.trim())},
TriggerSubmitted(mut value) => {
value = value.trim().to_string();
let trigger = value.parse::<u32>().unwrap_or_else(|_| 4294967295u32);
app_state.bin_word = Some(BinWord::trigger_to_word(trigger));
app_state.trigger = String::from(value);
},
TriggerDropped => {
println!("WindowId = {}", app_state.window_id);
Action::ToggleMaximize(app_state.window_id);
}
}
}
fn view(app_state: &AppState) -> Element<Message> {
//let mut trigger_row: Row<Message> = Row::new();
let trigger_textinput = TextInput::new("4294967295", &app_state.trigger.to_string())
.on_input(Message::TriggerChanged)
.on_submit(TriggerSubmitted(String::from(&app_state.trigger)))
.on_paste(TriggerSubmitted)
.width(Length::Fixed(150.0));
let trigger_row = row!["Trigger: ",trigger_textinput]
.spacing(10);
let trigger_container = Container::new(trigger_row)
.padding(10.0);
let text_input_area = MouseArea::new(trigger_container)
.on_release(TriggerDropped);
match &app_state.bin_word {
None => {
column![
Space::with_height(Length::Fixed(10.0)),
text_input_area,
]
.padding(10.0)
.into()
}
Some(bin_word) => {
//let bin_word_row: Row<Message> = Row::new();
column![
Space::with_height(Length::Fixed(10.0)),
text_input_area,
Space::with_height(Length::Fixed(10.0)),
binword_display(bin_word),
]
.into()
}
}
}