user-interfacerusttexteditegui

egui::TextEdit::singleline with macroquad - not able to edit text


Trying to experiment with egui and macroquad, but can't get elements enabled for edit.

From the standard example:

use macroquad::prelude::*;

#[macroquad::main("")]
async fn main() {
    loop {
        clear_background(BLACK);
        
        egui_macroquad::ui(|egui_ctx| {
            egui_macroquad::egui::Window::new("egui ❤ macroquad").show(egui_ctx, |ui| {
                ui.colored_label(egui_macroquad::egui::Color32::WHITE, "Test");
                ui.add(egui_macroquad::egui::TextEdit::singleline(&mut "ku").text_color(egui_macroquad::egui::Color32::RED));
            });
        });

        egui_macroquad::draw();
        next_frame().await
    }
}

In Cargo.toml:

[dependencies]
macroquad = "0.3.25"
egui-macroquad = "0.12.0"

As result:

enter image description here

I see the TextEdit::singleline widget, but can't edit it. Should I enable it somehow or something else?


Solution

  • Found the solution. Mutable "String" variable must be defined and used for TextEdit::singleline:

    use macroquad::prelude::*;
    
    #[macroquad::main("")]
    async fn main() {
        let mut kuku: String = "ku".to_string();
        loop {
            clear_background(BLACK);
            
            egui_macroquad::ui(|egui_ctx| {
                egui_macroquad::egui::Window::new("egui ❤ macroquad").show(egui_ctx, |ui| {
                    ui.colored_label(egui_macroquad::egui::Color32::WHITE, "Test");
                    ui.add(egui_macroquad::egui::TextEdit::singleline(&mut kuku).text_color(egui_macroquad::egui::Color32::RED));
                });
            });
    
            egui_macroquad::draw();
            next_frame().await
        }
    }
    

    Now it works, because it takes the values from the widget and assign them to the variable "kuku".