diff options
| author | pml68 <contact@pml68.dev> | 2025-02-27 00:01:38 +0100 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-02-27 00:01:38 +0100 |
| commit | 1889f2fddddcce21790828c46a396e12c416919a (patch) | |
| tree | 9b1438127127a54896f9496fb4f2cd6f731507c3 /README.md | |
| parent | feat: switch to personal `iced` fork (should be temporary) (diff) | |
| download | iced_custom_highlighter-1889f2fddddcce21790828c46a396e12c416919a.tar.gz | |
docs: add README
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..d09cfcc --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# iced_custom_highlighter + +A custom syntax highlighter for iced. + +It uses the colors from your app's Theme, based on a styling method (like `default_style`) + +# Example + +```rust +use iced::widget::{Column, pick_list, text_editor}; +use iced::{Element, Theme}; +use iced_custom_highlighter::{Highlight, Highlighter, Settings}; + +#[derive(Default)] +struct State { + content: text_editor::Content, + theme: Theme, +} + +#[derive(Debug, Clone)] +enum Message { + Edit(text_editor::Action), + ChangeTheme(Theme), +} + +fn view(state: &State) -> Element<'_, Message> { +Column::new() + .push( + text_editor(&state.content) + .placeholder("Type something here...") + .rehighlight_on_redraw(true) + .highlight_with::<Highlighter>( + Settings::new(vec![], Highlight::default_style, "rs"), + Highlight::to_format, + ) + .on_action(Message::Edit), + ) + .push(pick_list( + Theme::ALL, + Some(state.theme), + Message::ChangeTheme, + )) + .into() +} + +fn update(state: &mut State, message: Message) { + match message { + Message::Edit(action) => { + state.content.perform(action); + } + + Message::ChangeTheme(theme) => { + state.theme = theme; + } + } +} +``` |
