From 989dd984685fc00b9a85a27c0e3db164fb0c3544 Mon Sep 17 00:00:00 2001 From: jess Date: Tue, 7 Apr 2026 17:56:24 -0700 Subject: [PATCH] add cursor position status bar (Ln/Col) below text editor --- viewport/src/editor.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/viewport/src/editor.rs b/viewport/src/editor.rs index 37f7410..2b0a765 100644 --- a/viewport/src/editor.rs +++ b/viewport/src/editor.rs @@ -1,7 +1,8 @@ use iced_wgpu::core::text::Wrapping; 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}; #[derive(Debug, Clone)] @@ -31,7 +32,11 @@ impl EditorState { } 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) .font(Font::MONOSPACE) .size(self.font_size) @@ -44,7 +49,26 @@ impl EditorState { placeholder: Color::from_rgb(0.4, 0.4, 0.4), value: Color::WHITE, 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() } }