💄 redo the GUI with `Flex`

This is way better
main
_ 2021-10-10 19:37:58 +00:00
parent de248f2382
commit 63f9dcef97
3 changed files with 55 additions and 114 deletions

57
Cargo.lock generated
View File

@ -345,36 +345,22 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "fltk"
version = "1.1.11"
version = "1.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "471fefc1fc3e019d314d542637f5bf48bd72a678f5e9052167b9ac7bea7b0a38"
checksum = "0953c34fd5b0c6ac1b615fdcda8845c81ed364165b115ddac46ae8953d456640"
dependencies = [
"bitflags",
"fltk-derive",
"fltk-sys",
"lazy_static",
"objc",
"raw-window-handle",
]
[[package]]
name = "fltk-derive"
version = "1.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712f09c29760a17e14a2f0d08a36b78bab82d5fbb3b2c3e17f3420f239351364"
dependencies = [
"quote",
"syn",
"paste",
]
[[package]]
name = "fltk-sys"
version = "1.1.11"
version = "1.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc5eabad4839df806d102049c44586233743cf6607e2d2829155bb9fe45775e"
checksum = "e2df700440c014123cc1644fbef7d33dcdda18cdd80373a7552a9d5cec47ca63"
dependencies = [
"cmake",
"libc",
]
[[package]]
@ -774,15 +760,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
dependencies = [
"libc",
]
[[package]]
name = "maplit"
version = "1.0.2"
@ -924,15 +901,6 @@ dependencies = [
"libc",
]
[[package]]
name = "objc"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
dependencies = [
"malloc_buf",
]
[[package]]
name = "once_cell"
version = "1.8.0"
@ -1009,6 +977,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "paste"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58"
[[package]]
name = "pem"
version = "0.8.3"
@ -1472,15 +1446,6 @@ dependencies = [
"rand_core",
]
[[package]]
name = "raw-window-handle"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a441a7a6c80ad6473bd4b74ec1c9a4c951794285bf941c2126f607c72e48211"
dependencies = [
"libc",
]
[[package]]
name = "rcgen"
version = "0.8.13"

View File

@ -9,7 +9,7 @@ license = "AGPL-3.0"
[dependencies]
anyhow = "1.0.38"
fltk = "1.1.1"
fltk = "1.2.7"
quic_demo = { path = "../quic_demo" }
quinn = "0.7.2"
reqwest = "0.11.4"

View File

@ -1,10 +1,13 @@
use std::str::FromStr;
use std::{
str::FromStr,
};
use fltk::{
app,
button::Button,
enums::CallbackTrigger,
frame::Frame,
group::Flex,
input::*,
prelude::*,
window::Window
@ -48,6 +51,7 @@ struct Port {
}
struct GuiPort {
row: fltk::group::Flex,
input_client_port: Input,
input_server_id: Input,
input_server_port: Input,
@ -121,59 +125,38 @@ fn main () -> anyhow::Result <()> {
let mut wind = Window::new (100, 100, 800, 600, None)
.with_label (&window_title);
let margin = 10;
let h = 30;
let mut x = margin;
let mut y = margin;
let mut col = Flex::default ().column ().size_of_parent ();
let frame_status = Frame::new (x, y, 800 - 20, h, "Forwarding 0 ports");
y += h + margin;
x = margin;
let mut frame_status = Frame::default ().with_label ("Forwarding 0 ports");
col.set_size (&mut frame_status, 30);
{
let w = 80;
Frame::new (x, y, w, h, "Local port");
x += w + margin;
let mut row = Flex::default ().row ();
let w = 120;
Frame::new (x, y, w, h, "Server ID");
x += w + margin;
let mut l = Frame::default ().with_label ("Local port");
row.set_size (&mut l, 80);
let mut l = Frame::default ().with_label ("Server ID");
row.set_size (&mut l, 120);
let mut l = Frame::default ().with_label ("Server port");
row.set_size (&mut l, 80);
row.end ();
let w = 80;
Frame::new (x, y, w, h, "Server port");
// x += w + margin;
col.set_size (&mut row, 30);
}
y += h + margin;
x = margin;
let gui_port_0 = GuiPort::new (fltk_tx, &mut x, y, 0);
y += h + margin;
x = margin;
let gui_port_1 = GuiPort::new (fltk_tx, &mut x, y, 1);
y += h + margin;
x = margin;
let gui_port_2 = GuiPort::new (fltk_tx, &mut x, y, 2);
// y += h + margin;
// x = margin;
let ports = vec! [
let ports = (0..3)
.map (|i| {
let mut gui = GuiPort::new (fltk_tx, i);
col.add (&gui.row);
col.set_size (&mut gui.row, 30);
Port {
gui: gui_port_0,
gui,
forwarding_instance: None,
},
Port {
gui: gui_port_1,
forwarding_instance: None,
},
Port {
gui: gui_port_2,
forwarding_instance: None,
},
];
}
}).collect ();
col.end ();
let mut gui_client = GuiClient {
rt: &rt,
@ -181,8 +164,6 @@ fn main () -> anyhow::Result <()> {
ports,
};
// y += h + margin;
wind.end ();
wind.show ();
@ -239,29 +220,21 @@ fn set_active <W: WidgetExt> (w: &mut W, b: bool) {
}
impl GuiPort {
fn new (fltk_tx: fltk::app::Sender <Message>, x: &mut i32, y: i32, port_idx: usize) -> Self {
let margin = 10;
let h = 30;
fn new (fltk_tx: fltk::app::Sender <Message>, port_idx: usize) -> Self {
let w = 80;
let mut input_client_port = Input::new (*x, y, w, h, "");
*x += w + margin;
let mut row = Flex::default ().row ();
let w = 120;
let mut input_server_id = Input::new (*x, y, w, h, "");
*x += w + margin;
let mut input_client_port = Input::default ();
let mut input_server_id = Input::default ();
let mut input_server_port = Input::default ();
let mut but_open = Button::default ().with_label ("Open");
let mut but_close = Button::default ().with_label ("Close");
let w = 80;
let mut input_server_port = Input::new (*x, y, w, h, "");
*x += w + margin;
let w = 80;
let mut but_open = Button::new (*x, y, w, h, "Open");
*x += w + margin;
let w = 80;
let mut but_close = Button::new (*x, y, w, h, "Close");
// *x += w + margin;
row.set_size (&mut input_client_port, 80);
row.set_size (&mut input_server_id, 120);
row.set_size (&mut input_server_port, 80);
row.set_size (&mut but_open, 80);
row.set_size (&mut but_close, 80);
input_client_port.set_value ("5901");
input_server_id.set_value ("bogus_server");
@ -275,7 +248,10 @@ impl GuiPort {
set_active (&mut but_open, true);
set_active (&mut but_close, false);
row.end ();
Self {
row,
input_client_port,
input_server_id,
input_server_port,