summaryrefslogtreecommitdiff
path: root/src/widgets/prompt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/prompt.rs')
-rw-r--r--src/widgets/prompt.rs35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/widgets/prompt.rs b/src/widgets/prompt.rs
index 0690840..31c8630 100644
--- a/src/widgets/prompt.rs
+++ b/src/widgets/prompt.rs
@@ -1,21 +1,36 @@
+//! A box for getting a line of text input.
+//!
+//! To create a prompt widget, make a `PromptBuilder`, optionally modify
+//! properties, and then use its `create` method to create a `Prompt` object.
+
use std::ptr;
use crate::bindings;
+use crate::core::Screen;
use crate::util;
pub struct Prompt {
ptr: *mut bindings::Promptwidget,
}
-pub struct PromptBuilder<'a> {
+pub struct PromptBuilder<'a, 'b> {
+ _screen: &'a Screen<'b>,
lefttop: (u32, u32),
width: u32,
title: Option<&'a str>,
}
-impl<'a> PromptBuilder<'a> {
- pub fn add_title<'s: 'a>(&'a mut self, title: &'s str)
- -> &'a mut PromptBuilder<'a> {
+impl<'a, 'b> PromptBuilder<'a, 'b> {
+ pub fn new(screen: &'a Screen<'b>, lefttop: (u32, u32), width: u32) -> Self {
+ PromptBuilder {
+ _screen: screen,
+ lefttop, width,
+ title: None,
+ }
+ }
+
+ pub fn add_title<'s: 'a>(&mut self, title: &'s str)
+ -> &mut Self {
self.title = Some(title);
self
}
@@ -36,17 +51,15 @@ impl<'a> PromptBuilder<'a> {
}
impl Prompt {
- pub fn new<'a>(lefttop: (u32, u32), width: u32) -> PromptBuilder<'a> {
- PromptBuilder {
- lefttop, width,
- title: None,
- }
- }
-
+ /// Called automatically; should only be needed if something else overwrote
+ /// the widget.
pub fn redraw(&self) {
unsafe { bindings::prw_redraw(self.ptr); }
}
+ /// Input string if <enter>, None otherwise.
+ ///
+ /// The key should be a return value from `Keyboard::get_key()`.
pub fn handle_key(&mut self, key: i32) -> Option<String> {
let ptr = unsafe { bindings::prw_handlekey(self.ptr, key) };
if ptr.is_null() {