Enter detection on libui-rs?

I know this is a small library, but digging through it i cant seem to find a solution for enter detection. i tried scanning for a newline char, but that didnt work, does enter even place any characters?
i wanna be able to press enter while focusing on the textbox, and have it do the same thing as submit

image

#![cfg_attr(not(test), windows_subsystem = "windows")]
#![cfg_attr(test, windows_subsystem = "console")]

use std::{cell::RefCell, rc::Rc};

use libui::{
    controls::{Button, Entry, Label, VerticalBox},
    prelude::{LayoutStrategy, TextEntry, Window, WindowType},
    UI,
};

const WINDOW_NAME: &str = "Input";
const WINDOW_DIMENSIONS: (i32, i32) = (300, 200);

fn main() -> anyhow::Result<()> {
    let (window_width, window_height) = WINDOW_DIMENSIONS;

    let ui = UI::init()?;

    let mut win = Window::new(
        &ui,
        WINDOW_NAME,
        window_width,
        window_height,
        WindowType::NoMenubar,
    );

    let mut layout = VerticalBox::new();

    let mut entry = Entry::new();
    let input = Rc::new(RefCell::new(String::new()));

    let label = Label::new(&input.borrow());

    entry.on_changed({
        let mut label = label.clone();
        let mut entry = entry.clone();
        let input = input.clone();
        move |text| {
            let mut input = input.borrow_mut();
            if text.contains('\n') {
                label.set_text(text.trim());
                entry.set_value("");
                *input = String::new();
            }
            *input = text;
        }
    });

    let mut button = Button::new("Submit");

    button.on_clicked({
        let mut entry = entry.clone();
        let input = input.clone();
        let mut label = label.clone();
        move |_| {
            label.set_text(&input.borrow());
            entry.set_value("");
            *input.borrow_mut() = String::new()
        }
    });

    layout.append(entry, LayoutStrategy::Compact);
    layout.append(button, LayoutStrategy::Compact);
    layout.append(label, LayoutStrategy::Compact);

    win.set_child(layout);
    win.show();
    ui.main();

    Ok(())
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.