Add autoscroll
This commit is contained in:
parent
a9110c9197
commit
5f41ee6bdf
2 changed files with 10 additions and 4 deletions
|
@ -8,5 +8,5 @@ edition = "2021"
|
|||
[dependencies]
|
||||
serialport = "*"
|
||||
gtk = { version = "*", features = ["v3_24"] }
|
||||
anyhow = { version = "1.0", features = ["backtrace"] }
|
||||
anyhow = { version = "1.0.65", features = ["backtrace"] }
|
||||
glib = "*"
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
|
||||
use gtk::{prelude::*, TextView};
|
||||
use gtk::{prelude::*, PolicyType, TextView};
|
||||
use gtk::{Application, ApplicationWindow};
|
||||
|
||||
use gtk::{Button, Entry, Orientation};
|
||||
use gtk::{Button, Entry, Orientation, ScrolledWindow};
|
||||
|
||||
use glib;
|
||||
|
||||
|
@ -34,12 +34,16 @@ fn main() {
|
|||
let vid = Entry::builder().text("0x16c0").editable(true).build();
|
||||
let connect_button = Button::with_label("Connect");
|
||||
let serial_info = TextView::new();
|
||||
let scrolled_window = ScrolledWindow::builder()
|
||||
.vscrollbar_policy(PolicyType::Automatic)
|
||||
.child(&serial_info)
|
||||
.build();
|
||||
|
||||
top_bar_box.pack_end(&connect_button, true, true, 3);
|
||||
top_bar_box.pack_end(&vid, true, true, 3);
|
||||
top_bar_box.pack_end(&pid, true, true, 3);
|
||||
|
||||
master_box.pack_end(&serial_info, true, true, 3);
|
||||
master_box.pack_end(&scrolled_window, true, true, 3);
|
||||
master_box.pack_end(&top_bar_box, false, true, 3);
|
||||
|
||||
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||
|
@ -90,6 +94,7 @@ fn main() {
|
|||
|
||||
if let Ok(port) = Port::open(usb_id, serialport_settings) {
|
||||
CONNECTED.store(true, SeqCst);
|
||||
|
||||
unsafe {
|
||||
PORT = Some(port);
|
||||
}
|
||||
|
@ -102,6 +107,7 @@ fn main() {
|
|||
rx.attach(None, move |message| {
|
||||
if !message.is_empty() {
|
||||
buffer.insert(&mut buffer.end_iter(), &format!("{}\n", message));
|
||||
serial_info.scroll_to_iter(&mut buffer.end_iter(), 0.0, true, 0.0, 0.0);
|
||||
}
|
||||
|
||||
glib::Continue(true)
|
||||
|
|
Loading…
Reference in a new issue