summaryrefslogtreecommitdiffstats
path: root/examples/editor
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-04 21:25:59 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-04 21:26:47 +0200
commitf98328f4f1ee58b6288e4f19d7475e7eeb9a7ba7 (patch)
tree8fb3e8b470bff711e0ca2f1bf120ab6c66ba9a9d /examples/editor
parent8d826cc662554b337282e7c982383f5db428d7aa (diff)
downloadiced-f98328f4f1ee58b6288e4f19d7475e7eeb9a7ba7.tar.gz
iced-f98328f4f1ee58b6288e4f19d7475e7eeb9a7ba7.tar.bz2
iced-f98328f4f1ee58b6288e4f19d7475e7eeb9a7ba7.zip
Add `text::Wrapping` support
Co-authored-by: Neeraj Jaiswal <neerajj85@gmail.com>
Diffstat (limited to 'examples/editor')
-rw-r--r--examples/editor/src/main.rs20
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()