Placing child window. FLTK

I am in learning of FLTK now. So i decided to write small program with FLTK. But I faced the problem I don't know how to solve. The problem is displaying of a child window. The main window should contains child window and logic of the program.Child window contains widgets for user authorization and If authorization is successful child window should be hide with

Widget.hide()

method. But when i placed windows like that


child_window.end()
main_window.end()
main_window.show()
child_window()

I got collisions between child's window widgets and main's window widgets. So I changed window placing.

child_window.end()
child_window()
main_window.end()
main_window.show()

No collisions now, all widgets of a child window work properly. But now when child window is hide I got empty main window without any widgets. What I am doing wrong?

The minimal code example

use fltk::{prelude::*, *};


fn main() {


  let app = app::App::default().with_scheme(app::Scheme::Gtk);
  
  //the main window starts here
  let mut window = window::Window::new(460, 200, 400, 400, "");
  window.set_color(enums::Color::White);

  //child window starts here
  let mut reg_and_log = window::Window::default()
                        .with_size(400, 400)
                        .center_of(&window);

  reg_and_log.set_color(enums::Color::White);
  
 
  let mut log_column = group::Flex::default()
                         .with_size(122, 118)
                         .with_pos(215, 110) 
                         .with_type(group::FlexType::Column); 

  let mut login = input::Input::default() 
                    .with_label("login");

  let mut login_password = input::SecretInput::default()
                             .with_label("password");

  let mut login_button = button::Button::default()
                           .with_size(120, 35)
                           .with_label("confirm");

  let mut login_reg = button::Button::default()
                        .with_size(120, 35) 
                        .with_label("registration");

  login_button.visible_focus(false);
  login_button.set_color(enums::Color::White);

  login_reg.visible_focus(false);
  login_reg.set_color(enums::Color::White); 

  log_column.end();
  
  reg_and_log.end(); 
  //child window ends here


  let column = group::Flex::default()
                  .with_size(150, 100)
                  .with_type(group::FlexType::Column)
                  .with_pos(70, 70);

  let mut label = frame::Frame::default()
                  .with_size(70, 40)
                  .with_label("");

  let mut input = input::Input::default()
                  .with_size(70, 40)
                  .with_label(&format!("{} x {}", 2, 2));

  let mut button = button::Button::default()
                   .with_size(70, 40)
                   .with_label("confirm");
 
  button.visible_focus(false);
  button.set_color(enums::Color::White);

  column.end();

 
  let mut label_row = group::Flex::default()
                      .with_size(134, 26)
                      .with_pos(233, 82);  
  
  label_row.set_pad(13);
 
  let mut first_label = frame::Frame::default()
                        .with_size(60, 12)
                        .with_label("");
                      
  first_label.set_label_size(10);

  let mut second_label = frame::Frame::default()
                        .with_size(60, 12)
                        .with_label("");
                      
  second_label.set_label_size(10); 

  label_row.end();
 

  let mut row = group::Flex::default()
                   .with_size(130, 29)
                   .with_pos(235, 105);
 
  row.set_pad(15);


  let mut first = menu::Choice::default()
                    .with_size(60, 20);
 
  first.add_choice("1 |2 |3 |4 |5 |6 |7 |8 |9 |10"); 
  first.set_color(enums::Color::White);
  first.set_value(1);
  first.visible_focus(false); 

  let mut second = menu::Choice::default()
                    .with_size(60, 20);

  second.add_choice("1 |2 |3 |4 |5 |6 |7 |8 |9 |10");
  second.set_color(enums::Color::White);
  second.set_value(0);
  second.visible_focus(false);

  row.end(); 
    
  //main window ends here
  window.end(); 
  window.show();
  reg_and_log.make_current();  

  
  login_button.set_callback(move |_| {
    
    reg_and_log.hide();

  }); 




  app.run().unwrap();



}

window



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations