summaryrefslogtreecommitdiff
path: root/src/widgets/log.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/log.rs')
-rw-r--r--src/widgets/log.rs39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/widgets/log.rs b/src/widgets/log.rs
index 8bd240a..4966cc0 100644
--- a/src/widgets/log.rs
+++ b/src/widgets/log.rs
@@ -1,27 +1,44 @@
+//! Logging events in a scrolling list.
+//!
+//! Events are logged in an upwards scrolled box that forgets about the events
+//! that move off-screen. The logger may optionally add timestamps to events.
+//!
+//! To create a log widget, make a `LogBuilder`, optionally modify properties,
+//! and then use its `create` method to create a `Log` object.
+
use std::ptr;
use crate::bindings;
+use crate::core::Screen;
pub struct Log {
ptr: *mut bindings::Logwidget,
}
-pub struct LogBuilder<'a> {
+pub struct LogBuilder<'a, 'b> {
+ _screen: &'a Screen<'b>,
lefttop: (u32, u32),
size: (u32, u32),
title: Option<&'a str>,
timestamps: bool,
}
-impl<'a> LogBuilder<'a> {
- pub fn add_title<'s: 'a>(&'a mut self, title: &'s str)
- -> &'a mut LogBuilder<'a> {
+impl<'a, 'b> LogBuilder<'a, 'b> {
+ pub fn new(screen: &'a Screen<'b>, lefttop: (u32, u32), size: (u32, u32)) -> Self {
+ LogBuilder {
+ _screen: screen,
+ lefttop, size,
+ title: None,
+ timestamps: false,
+ }
+ }
+
+ pub fn add_title<'s: 'a>(&mut self, title: &'s str) -> &mut Self {
self.title = Some(title);
self
}
- pub fn set_timestamps(&'a mut self, timestamps: bool)
- -> &'a mut LogBuilder<'a> {
+ pub fn set_timestamps(&mut self, timestamps: bool) -> &mut Self {
self.timestamps = timestamps;
self
}
@@ -43,14 +60,8 @@ impl<'a> LogBuilder<'a> {
}
impl Log {
- pub fn new<'a>(lefttop: (u32, u32), size: (u32, u32)) -> LogBuilder<'a> {
- LogBuilder {
- lefttop, size,
- title: None,
- timestamps: false,
- }
- }
-
+ /// Called automatically; should only be needed if something else overwrote
+ /// the widget.
pub fn redraw(&self) {
unsafe { bindings::lgw_redraw(self.ptr); }
}