chore: fix styles
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
ed5a5db7c5
commit
7cead58ed3
@ -59,7 +59,7 @@ impl<'a> App<'a> {
|
||||
self.command = Some(CommandBarState::default());
|
||||
self.mode = Mode::Command
|
||||
}
|
||||
Msg::SubmitCommand => {
|
||||
Msg::SubmitCommand { command } => {
|
||||
tracing::info!("submitting command");
|
||||
|
||||
self.command = None;
|
||||
|
@ -22,16 +22,16 @@ impl Default for CommandBarState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CommandBar {}
|
||||
|
||||
impl CommandBarState {
|
||||
pub fn update(&mut self, msg: &Msg) -> anyhow::Result<impl IntoCommand> {
|
||||
if let Msg::Edit(e) = msg {
|
||||
self.contents.update(e)?;
|
||||
|
||||
if let EditMsg::InsertNewLine = e {
|
||||
return Ok(Msg::SubmitCommand.into_command());
|
||||
return Ok(Msg::SubmitCommand {
|
||||
command: self.contents.string(),
|
||||
}
|
||||
.into_command());
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,9 @@ impl CommandBarState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CommandBar {}
|
||||
|
||||
impl StatefulWidget for CommandBar {
|
||||
type State = CommandBarState;
|
||||
|
||||
|
@ -145,11 +145,16 @@ impl Default for InputBuffer {
|
||||
|
||||
pub struct InputField<'a> {
|
||||
title: &'a str,
|
||||
|
||||
focused: bool,
|
||||
}
|
||||
|
||||
impl<'a> InputField<'a> {
|
||||
pub fn new(title: &'a str) -> Self {
|
||||
Self { title }
|
||||
Self {
|
||||
title,
|
||||
focused: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +162,11 @@ impl<'a> StatefulWidget for InputField<'a> {
|
||||
type State = InputBuffer;
|
||||
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
||||
let block = Block::bordered().title(self.title);
|
||||
let mut block = Block::bordered().title(self.title);
|
||||
|
||||
if !self.focused {
|
||||
block = block.dark_gray();
|
||||
}
|
||||
|
||||
match &state.state {
|
||||
BufferState::Focused { content, position } => {
|
||||
@ -165,7 +174,7 @@ impl<'a> StatefulWidget for InputField<'a> {
|
||||
.block(block)
|
||||
.render(area, buf);
|
||||
|
||||
buf.get_mut(area.x + 1 + *position as u16, area.y + 1)
|
||||
buf.get_mut(clamp_x(&area, area.x + 1 + *position as u16), area.y + 1)
|
||||
.set_style(Style::new().bg(Color::Magenta).fg(Color::Black));
|
||||
}
|
||||
BufferState::Static { content, .. } => {
|
||||
@ -177,6 +186,14 @@ impl<'a> StatefulWidget for InputField<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn clamp_x(area: &Rect, x: u16) -> u16 {
|
||||
if x >= area.width {
|
||||
area.width - 1
|
||||
} else {
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
enum CreateItemFocused {
|
||||
Title,
|
||||
Description,
|
||||
@ -239,9 +256,16 @@ impl StatefulWidget for &mut CreateItem {
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
||||
let chunks =
|
||||
Layout::vertical(vec![Constraint::Length(3), Constraint::Length(3)]).split(area);
|
||||
let mut title_input = InputField::new("title");
|
||||
let mut description_input = InputField::new("description");
|
||||
|
||||
InputField::new("title").render(chunks[0], buf, &mut state.title);
|
||||
InputField::new("description").render(chunks[1], buf, &mut state.description);
|
||||
match state.focused {
|
||||
CreateItemFocused::Title => title_input.focused = true,
|
||||
CreateItemFocused::Description => description_input.focused = true,
|
||||
}
|
||||
|
||||
title_input.render(chunks[0], buf, &mut state.title);
|
||||
description_input.render(chunks[1], buf, &mut state.description);
|
||||
|
||||
// let title = Paragraph::new("something"); //.block(block);
|
||||
|
||||
|
@ -12,7 +12,7 @@ pub enum Msg {
|
||||
EnterViewMode,
|
||||
EnterCommandMode,
|
||||
|
||||
SubmitCommand,
|
||||
SubmitCommand { command: String },
|
||||
|
||||
Edit(EditMsg),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user