From bc2066220f656765cc820baeb687d8594fbc8826 Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 23 Sep 2024 23:57:45 +0200 Subject: feat: make code view scrollable, add autogen comment to code --- iced_builder/src/codegen/mod.rs | 3 ++- iced_builder/src/main.rs | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'iced_builder/src') diff --git a/iced_builder/src/codegen/mod.rs b/iced_builder/src/codegen/mod.rs index 88c0c61..20a2e65 100644 --- a/iced_builder/src/codegen/mod.rs +++ b/iced_builder/src/codegen/mod.rs @@ -92,7 +92,8 @@ impl RenderedElement { let mut app_code = format!("use iced::{{widget::{{{imports}}},Sandbox,Settings,Element}};"); app_code = format!( - r#"{app_code} + r#"// Automatically generated by iced Builder + {app_code} fn main() -> iced::Result {{ App::run(Settings::default()) diff --git a/iced_builder/src/main.rs b/iced_builder/src/main.rs index e966614..2633e6c 100644 --- a/iced_builder/src/main.rs +++ b/iced_builder/src/main.rs @@ -37,6 +37,7 @@ struct App { enum Message { ToggleTheme, CopyCode, + EditorAction(text_editor::Action), Drop(types::ElementName, iced::Point, iced::Rectangle), HandleZones( types::ElementName, @@ -107,6 +108,11 @@ impl Application for App { match message { Message::ToggleTheme => self.dark_theme = !self.dark_theme, Message::CopyCode => return clipboard::write(self.editor_content.text()), + Message::EditorAction(action) => { + if let text_editor::Action::Scroll { lines: _ } = action { + self.editor_content.perform(action); + } + } Message::Resized(pane_grid::ResizeEvent { split, ratio }) => { self.pane_state.resize(split, ratio); } @@ -190,6 +196,7 @@ impl Application for App { .style(style::title_bar); pane_grid::Content::new( text_editor(&self.editor_content) + .on_action(Message::EditorAction) .highlight::( highlighter::Settings { theme: highlighter::Theme::Base16Mocha, -- cgit v1.2.3