add cursor position status bar (Ln/Col) below text editor

This commit is contained in:
jess 2026-04-07 17:56:24 -07:00
parent 4efab49959
commit 989dd98468
1 changed files with 27 additions and 3 deletions

View File

@ -1,7 +1,8 @@
use iced_wgpu::core::text::Wrapping; use iced_wgpu::core::text::Wrapping;
use iced_wgpu::core::{ use iced_wgpu::core::{
Background, Border, Color, Element, Font, Length, Padding, Theme, Background, Border, Color, Element, Font, Length, Padding, Shadow, Theme,
}; };
use iced_widget::container;
use iced_widget::text_editor::{self, Style}; use iced_widget::text_editor::{self, Style};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -31,7 +32,11 @@ impl EditorState {
} }
pub fn view(&self) -> Element<'_, Message, Theme, iced_wgpu::Renderer> { pub fn view(&self) -> Element<'_, Message, Theme, iced_wgpu::Renderer> {
iced_widget::text_editor(&self.content) let cursor = self.content.cursor();
let line = cursor.position.line + 1;
let col = cursor.position.column + 1;
let editor = iced_widget::text_editor(&self.content)
.on_action(Message::EditorAction) .on_action(Message::EditorAction)
.font(Font::MONOSPACE) .font(Font::MONOSPACE)
.size(self.font_size) .size(self.font_size)
@ -44,7 +49,26 @@ impl EditorState {
placeholder: Color::from_rgb(0.4, 0.4, 0.4), placeholder: Color::from_rgb(0.4, 0.4, 0.4),
value: Color::WHITE, value: Color::WHITE,
selection: Color::from_rgba(0.3, 0.5, 0.8, 0.4), selection: Color::from_rgba(0.3, 0.5, 0.8, 0.4),
}) });
let status_bar = iced_widget::container(
iced_widget::text(format!("Ln {}, Col {}", line, col))
.font(Font::MONOSPACE)
.size(11.0)
.color(Color::from_rgb(0.55, 0.55, 0.55)),
)
.width(Length::Fill)
.padding(Padding { top: 3.0, right: 10.0, bottom: 3.0, left: 10.0 })
.style(|_theme: &Theme| container::Style {
background: Some(Background::Color(Color::from_rgb(0.12, 0.12, 0.14))),
border: Border::default(),
text_color: None,
shadow: Shadow::default(),
snap: false,
});
iced_widget::column([editor.into(), status_bar.into()])
.height(Length::Fill)
.into() .into()
} }
} }