diff options
| author | 2024-09-04 21:42:11 +0200 | |
|---|---|---|
| committer | 2024-09-04 21:42:11 +0200 | |
| commit | 6009420b57933ccf799f1b7eac8debab950cdd5e (patch) | |
| tree | e6218826131a702e51adf3041a45871140bae0be /examples/editor | |
| parent | 8d826cc662554b337282e7c982383f5db428d7aa (diff) | |
| parent | 3a70462a7232cc2b3a7cc3fe8d07f0c29cc578cc (diff) | |
| download | iced-6009420b57933ccf799f1b7eac8debab950cdd5e.tar.gz iced-6009420b57933ccf799f1b7eac8debab950cdd5e.tar.bz2 iced-6009420b57933ccf799f1b7eac8debab950cdd5e.zip  | |
Merge pull request #2279 from nrjais/wrapping
Add `text::Wrapping` support
Diffstat (limited to 'examples/editor')
| -rw-r--r-- | examples/editor/src/main.rs | 20 | 
1 files changed, 19 insertions, 1 deletions
diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs index aa07b328..5f12aec5 100644 --- a/examples/editor/src/main.rs +++ b/examples/editor/src/main.rs @@ -2,7 +2,7 @@ use iced::highlighter;  use iced::keyboard;  use iced::widget::{      self, button, column, container, horizontal_space, pick_list, row, text, -    text_editor, tooltip, +    text_editor, toggler, tooltip,  };  use iced::{Center, Element, Fill, Font, Subscription, Task, Theme}; @@ -24,6 +24,7 @@ struct Editor {      file: Option<PathBuf>,      content: text_editor::Content,      theme: highlighter::Theme, +    word_wrap: bool,      is_loading: bool,      is_dirty: bool,  } @@ -32,6 +33,7 @@ struct Editor {  enum Message {      ActionPerformed(text_editor::Action),      ThemeSelected(highlighter::Theme), +    WordWrapToggled(bool),      NewFile,      OpenFile,      FileOpened(Result<(PathBuf, Arc<String>), Error>), @@ -46,6 +48,7 @@ impl Editor {                  file: None,                  content: text_editor::Content::new(),                  theme: highlighter::Theme::SolarizedDark, +                word_wrap: true,                  is_loading: true,                  is_dirty: false,              }, @@ -76,6 +79,11 @@ impl Editor {                  Task::none()              } +            Message::WordWrapToggled(word_wrap) => { +                self.word_wrap = word_wrap; + +                Task::none() +            }              Message::NewFile => {                  if !self.is_loading {                      self.file = None; @@ -152,6 +160,11 @@ impl Editor {                  self.is_dirty.then_some(Message::SaveFile)              ),              horizontal_space(), +            toggler( +                Some("Word Wrap"), +                self.word_wrap, +                Message::WordWrapToggled +            ),              pick_list(                  highlighter::Theme::ALL,                  Some(self.theme), @@ -189,6 +202,11 @@ impl Editor {              text_editor(&self.content)                  .height(Fill)                  .on_action(Message::ActionPerformed) +                .wrapping(if self.word_wrap { +                    text::Wrapping::Word +                } else { +                    text::Wrapping::None +                })                  .highlight(                      self.file                          .as_deref()  | 
