♻️ refactor: use `add_port` in initialization, too
parent
17ed6cc4c5
commit
b71d4c16a1
|
@ -111,6 +111,23 @@ impl GuiClient <'_> {
|
|||
|
||||
self.frame_status.set_label (&format! ("Forwarding {} ports", open_ports));
|
||||
}
|
||||
|
||||
pub fn add_port (
|
||||
&mut self,
|
||||
ports_col: &mut Flex,
|
||||
fltk_tx: fltk::app::Sender <Message>
|
||||
) {
|
||||
let mut gui = GuiPort::new (fltk_tx, self.ports.len ());
|
||||
ports_col.add (&gui.row);
|
||||
ports_col.set_size (&mut gui.row, 30);
|
||||
|
||||
let port = Port {
|
||||
gui,
|
||||
forwarding_instance: None,
|
||||
};
|
||||
|
||||
self.ports.push (port);
|
||||
}
|
||||
}
|
||||
|
||||
fn main () -> anyhow::Result <()> {
|
||||
|
@ -147,18 +164,6 @@ fn main () -> anyhow::Result <()> {
|
|||
}
|
||||
|
||||
let mut ports_col = Flex::default ().column ();
|
||||
|
||||
let ports = (0..3)
|
||||
.map (|i| {
|
||||
let mut gui = GuiPort::new (fltk_tx, i);
|
||||
ports_col.set_size (&mut gui.row, 30);
|
||||
|
||||
Port {
|
||||
gui,
|
||||
forwarding_instance: None,
|
||||
}
|
||||
}).collect ();
|
||||
|
||||
ports_col.end ();
|
||||
|
||||
let mut but_add_port = Button::default ().with_label ("+");
|
||||
|
@ -171,9 +176,12 @@ fn main () -> anyhow::Result <()> {
|
|||
let mut gui_client = GuiClient {
|
||||
rt: &rt,
|
||||
frame_status,
|
||||
ports,
|
||||
ports: Default::default (),
|
||||
};
|
||||
|
||||
gui_client.add_port (&mut ports_col, fltk_tx);
|
||||
ports_col.recalc ();
|
||||
|
||||
gui_client.sync_status ();
|
||||
|
||||
wind.end ();
|
||||
|
@ -216,16 +224,7 @@ fn main () -> anyhow::Result <()> {
|
|||
gui_client.close_port (port_idx)?;
|
||||
},
|
||||
Some (Message::AddPort) => {
|
||||
let mut gui = GuiPort::new (fltk_tx, gui_client.ports.len ());
|
||||
ports_col.add (&gui.row);
|
||||
ports_col.set_size (&mut gui.row, 30);
|
||||
|
||||
let port = Port {
|
||||
gui,
|
||||
forwarding_instance: None,
|
||||
};
|
||||
|
||||
gui_client.ports.push (port);
|
||||
gui_client.add_port (&mut ports_col, fltk_tx);
|
||||
ports_col.recalc ();
|
||||
ports_col.redraw ();
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue