Configuration fields in game rules screen are editable

This commit is contained in:
2022-10-02 16:21:08 +02:00
parent 075b9e33e4
commit a62ced4d3c
4 changed files with 98 additions and 14 deletions

View File

@ -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);
}