Simplify editor example a bit
This commit is contained in:
parent
0024fc0eb1
commit
d0df7c689d
1 changed files with 6 additions and 7 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
use iced::highlighter;
|
use iced::highlighter;
|
||||||
use iced::keyboard;
|
use iced::keyboard;
|
||||||
use iced::widget::{
|
use iced::widget::{
|
||||||
self, button, center_x, column, container, operation::focus, pick_list,
|
button, center_x, column, container, operation, pick_list, row, space,
|
||||||
row, space, text, text_editor, toggler, tooltip,
|
text, text_editor, toggler, tooltip,
|
||||||
};
|
};
|
||||||
use iced::{Center, Element, Fill, Font, Task, Theme};
|
use iced::{Center, Element, Fill, Font, Task, Theme};
|
||||||
|
|
||||||
|
|
@ -20,7 +20,6 @@ pub fn main() -> iced::Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Editor {
|
struct Editor {
|
||||||
editor_id: widget::Id,
|
|
||||||
file: Option<PathBuf>,
|
file: Option<PathBuf>,
|
||||||
content: text_editor::Content,
|
content: text_editor::Content,
|
||||||
theme: highlighter::Theme,
|
theme: highlighter::Theme,
|
||||||
|
|
@ -43,10 +42,8 @@ enum Message {
|
||||||
|
|
||||||
impl Editor {
|
impl Editor {
|
||||||
fn new() -> (Self, Task<Message>) {
|
fn new() -> (Self, Task<Message>) {
|
||||||
let id = widget::Id::unique();
|
|
||||||
(
|
(
|
||||||
Self {
|
Self {
|
||||||
editor_id: id.clone(),
|
|
||||||
file: None,
|
file: None,
|
||||||
content: text_editor::Content::new(),
|
content: text_editor::Content::new(),
|
||||||
theme: highlighter::Theme::SolarizedDark,
|
theme: highlighter::Theme::SolarizedDark,
|
||||||
|
|
@ -62,7 +59,7 @@ impl Editor {
|
||||||
)),
|
)),
|
||||||
Message::FileOpened,
|
Message::FileOpened,
|
||||||
),
|
),
|
||||||
focus(id),
|
operation::focus(EDITOR),
|
||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -199,7 +196,7 @@ impl Editor {
|
||||||
column![
|
column![
|
||||||
controls,
|
controls,
|
||||||
text_editor(&self.content)
|
text_editor(&self.content)
|
||||||
.id(self.editor_id.clone())
|
.id(EDITOR)
|
||||||
.height(Fill)
|
.height(Fill)
|
||||||
.on_action(Message::ActionPerformed)
|
.on_action(Message::ActionPerformed)
|
||||||
.wrapping(if self.word_wrap {
|
.wrapping(if self.word_wrap {
|
||||||
|
|
@ -335,3 +332,5 @@ fn icon<'a, Message>(codepoint: char) -> Element<'a, Message> {
|
||||||
.shaping(text::Shaping::Basic)
|
.shaping(text::Shaping::Basic)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EDITOR: &str = "editor";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue