Configuration fields in game rules screen are editable
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use tui::buffer::Buffer;
|
||||
use tui::layout::Rect;
|
||||
use tui::style::{Color, Style};
|
||||
use tui::text::*;
|
||||
use tui::widgets::{Block, Borders, Paragraph, Widget};
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub enum InputMode {
|
||||
Normal,
|
||||
Editing,
|
||||
@ -30,16 +33,26 @@ impl TextEditorWidget {
|
||||
|
||||
impl Widget for TextEditorWidget {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let input = Paragraph::new(self.value.as_ref())
|
||||
.style(match &self.input_mode {
|
||||
let span = Span::styled(
|
||||
self.value.to_string(),
|
||||
match &self.input_mode {
|
||||
InputMode::Normal => Style::default(),
|
||||
InputMode::Editing => Style::default().fg(Color::Yellow),
|
||||
})
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(self.label.as_ref()),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
let mut spans = vec![span];
|
||||
|
||||
if self.input_mode == InputMode::Editing {
|
||||
spans.push(Span::styled(" ", Style::default().bg(Color::Yellow)))
|
||||
}
|
||||
|
||||
let text = Text::from(Spans::from(spans));
|
||||
let input = Paragraph::new(text).block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(self.label.as_ref()),
|
||||
);
|
||||
|
||||
input.render(area, buf);
|
||||
}
|
||||
|
Reference in New Issue
Block a user