You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello Good day, i am working on a library based on eframe/egui to integrate GUI into my custom language, the aim i am trying to achieve is to create multi window ability where user can create a multiple form like form1, form2 and etc by calling createform just like winform. show_form is used for showing form which is equivalent to winform show(), runapp is use for starting the application which is equivalent to winform Application.run. Now when i tried to run this script:
importguifunctiononclick()gui.showform(form2)endfunctionsetformtogui.form("This is First",500,500)setlabeltogui.label(form,"This is test",200,30,200,50,false)gui.setbackcolor(label,"blue")gui.setfontname(label,"Algerian")gui.settextalignment(label,"center")gui.setpadding(label,20,0,0,0)setbuttontogui.button(form,"Show Form 2",onclick,250,80)gui.setautosize(button,false)gui.settextalignment(button,"center")setform2togui.form("This is First",500,500)//gui.showform(form2)gui.runapp(form)
if i click the button to it can show the form it will just freeze/hook and become unresponsive i.e the form1 which is the main entry, but i try that gui.showform that is outside onclick it will just popup and go down when the app started, i have tried many trial to solve the issue but can't find solution. Please help review and solve thank you, i have been on this thing for almost five days now. Below are code related to the form from the library
lazy_static::lazy_static! {static ref COMMAND_QUEUE:Mutex<VecDeque<Command>> = Mutex::new(VecDeque::new());static ref FORMS:RwLock<HashMap<String,FormSettings>> = RwLock::new(HashMap::new());static ref CONTROLS:RwLock<HashMap<String,ControlSettings>> = RwLock::new(HashMap::new());static ref EXIT_SENDER:RwLock<Option<Sender<()>>> = RwLock::new(None);static ref TEXT_UPDATE_SENDERS:RwLock<HashMap<String,Sender<(String,String)>>> = RwLock::new(HashMap::new());static ref MSGBOX_RESULT:RwLock<Option<(String,String)>> = RwLock::new(None);}#[derive(Clone,Debug)]enumDockStyle{None,Top,Bottom,Left,Right,Fill,}#[derive(Clone,Debug)]structFormSettings{title:String,width:f32,height:f32,visible:bool,bg_color:Color32,maximized:bool,fullscreen:bool,startposition:String,// e.g., "centerscreen" or "manual"resizable:bool,position:Option<(f32,f32)>,// For manual positioningborder:bool,controls_order:Vec<String>,}// Create Form pubfncreateform(args:Vec<Value>) -> Result<Value,String>{if args.len() != 3{returnErr(format!("createform() expects 3 arguments, got {}", args.len()));}let title = match&args[0]{Value::String(s) => s.clone(),
_ => returnErr("createform() expects a string for title".to_string()),};let width = match&args[1]{Value::Number(n) => *n asf32,
_ => returnErr("createform() expects a number for width".to_string()),};let height = match&args[2]{Value::Number(n) => *n asf32,
_ => returnErr("createform() expects a number for height".to_string()),};let form_id = Uuid::new_v4().to_string();let settings = FormSettings{
title,
width,
height,visible:false,bg_color:Color32::from_rgb(230,230,230),// Light gray backgroundmaximized:false,fullscreen:false,startposition:"centerscreen".to_string(),resizable:true,position:None,border:true,controls_order:Vec::new(),};println!("Created form {} with visible: {}", form_id, settings.visible);FORMS.write().unwrap().insert(form_id.clone(), settings);Ok(Value::FormObject(form_id))}pubfnrunapp(args:Vec<Value>) -> Result<Value,String>{if args.len() != 1{returnErr(format!("runapp() expects 1 argument, got {}", args.len()));}let form_id = match&args[0]{Value::FormObject(id) => id.clone(),
_ => returnErr("runapp() expects a Form identifier".to_string()),};// Fix: Set the main form to visible{letmut forms = FORMS.write().unwrap();ifletSome(settings) = forms.get_mut(&form_id){
settings.visible = true;// Added to ensure the main form is visible}else{returnErr("Form not found".to_string());}}let(exit_tx, exit_rx) = channel();{letmut exit_sender = EXIT_SENDER.write().unwrap();*exit_sender = Some(exit_tx);}let forms = FORMS.read().unwrap();let form_settings = forms.get(&form_id).ok_or("Form not found".to_string())?
.clone();letmut viewport = egui::ViewportBuilder::default().with_maximized(form_settings.maximized).with_fullscreen(form_settings.fullscreen).with_resizable(form_settings.resizable).with_decorations(form_settings.border);if !form_settings.maximized && !form_settings.fullscreen{
viewport = viewport.with_inner_size([form_settings.width, form_settings.height]);}if form_settings.startposition == "manual"{ifletSome((x, y)) = form_settings.position{
viewport = viewport.with_position([x, y]);}}let options = eframe::NativeOptions{centered:true,
viewport,
..Default::default()};println!("Launching app - Maximized: {}, Fullscreen: {}, Border: {}, Size: {:?}",
form_settings.maximized,
form_settings.fullscreen,
form_settings.border,if form_settings.maximized || form_settings.fullscreen {"Max/Full".to_string()} else {
format!("{}x{}", form_settings.width, form_settings.height)});
eframe::run_native(&form_settings.title,
options,Box::new(|cc| Ok(Box::new(MyApp::new(form_id.clone(), exit_rx, cc)))),).map_err(|e| format!("Failed to run app: {}", e))?;{letmut exit_sender = EXIT_SENDER.write().unwrap();*exit_sender = None;}Ok(Value::Null)}
The App
structMyApp{form_id:String,exit_rx:Arc<Mutex<Receiver<()>>>,textbox_texts:HashMap<String,String>,text_update_rx:Receiver<(String,String)>,shown_viewports:HashSet<String>,}implMyApp{fnnew(form_id:String,exit_rx:Receiver<()>,cc:&eframe::CreationContext<'_>) -> Self{// Define custom fontsletmut fonts = FontDefinitions::default();let exe_path = std::env::current_exe().expect("Failed to get executable path");let exe_dir = exe_path.parent().expect("Failed to get executable directory");let fonts_dir = exe_dir.join("fonts");// List of font files to load from the 'fonts' subfolderlet font_files = [("SegoeUI","SegoeUI.ttf"),("SegoeUIBold","SegoeUIBold.ttf"),("SegoeUIItalic","SegoeUIItalic.ttf"),("SegoeUIBoldItalic","SegoeUIBoldItalic.ttf"),("SansSerif","SansSerif.otf"),("Algerian","algerian.ttf")];for(font_name, file_name)in font_files.iter(){let font_path = fonts_dir.join(file_name);if font_path.exists(){match fs::read(&font_path){Ok(font_data) => {
fonts.font_data.insert(
font_name.to_string(),FontData::from_owned(font_data).into(),);
fonts.families.insert(FontFamily::Name(font_name.to_string().into()),vec![font_name.to_string()],);}Err(e) => eprintln!("Failed to load font {}: {}", font_path.display(), e),}}else{eprintln!("Font file not found: {}", font_path.display());}}// Set the fonts in the egui context
cc.egui_ctx.set_fonts(fonts);let(text_update_tx, text_update_rx) = channel();TEXT_UPDATE_SENDERS.write().unwrap().insert(form_id.clone(), text_update_tx);Self{
form_id,exit_rx:Arc::new(Mutex::new(exit_rx)),textbox_texts:HashMap::new(),
text_update_rx,shown_viewports:HashSet::new(),}}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello Good day, i am working on a library based on eframe/egui to integrate GUI into my custom language, the aim i am trying to achieve is to create multi window ability where user can create a multiple form like form1, form2 and etc by calling createform just like winform. show_form is used for showing form which is equivalent to winform show(), runapp is use for starting the application which is equivalent to winform Application.run. Now when i tried to run this script:
if i click the button to it can show the form it will just freeze/hook and become unresponsive i.e the form1 which is the main entry, but i try that gui.showform that is outside onclick it will just popup and go down when the app started, i have tried many trial to solve the issue but can't find solution. Please help review and solve thank you, i have been on this thing for almost five days now. Below are code related to the form from the library
The App
Update function
Show form code
Beta Was this translation helpful? Give feedback.
All reactions