diff options
Diffstat (limited to '')
| -rw-r--r-- | src/panes/code_view.rs | 87 |
1 files changed, 54 insertions, 33 deletions
diff --git a/src/panes/code_view.rs b/src/panes/code_view.rs index 551347c..5999b8f 100644 --- a/src/panes/code_view.rs +++ b/src/panes/code_view.rs @@ -1,69 +1,90 @@ use iced::advanced::text::highlighter::Format; -use iced::widget::{Space, button, pane_grid, row, text, text_editor}; -use iced::{Alignment, Background, Border, Font, Length, Theme}; +use iced::border::Radius; +use iced::widget::{button, pane_grid, row, text, text_editor}; +use iced::{Alignment, Border, Font, Length}; use iced_custom_highlighter::{Highlight, Highlighter, Scope, Settings}; +use material_theme::Theme; use super::style; use crate::icon; use crate::types::{DesignerPane, Message}; use crate::widget::tip; +// TODO: implement a highlight style for the material theme fn highlight_style(theme: &Theme, scope: &Scope) -> Format<Font> { + let theme = if theme.is_dark() { + iced::Theme::SolarizedDark + } else { + iced::Theme::SolarizedLight + }; + match scope { Scope::Custom { .. } | Scope::Other => Format { color: Some(theme.extended_palette().primary.strong.color), font: None, }, - _ => Highlight::default_style(theme, scope), + _ => Highlight::default_style(&theme, scope), } } pub fn view( editor_content: &text_editor::Content, is_focused: bool, -) -> pane_grid::Content<'_, Message> { - let title = row![ - text("Generated Code"), - Space::with_width(Length::Fill), - tip( - button(icon::copy()) - .on_press(Message::CopyCode) - .padding([2, 7]) - .style(button::text), - "Copy", - tip::Position::FollowCursor - ), - Space::with_width(20), - button("Switch to Designer view") - .on_press(Message::SwitchPage(DesignerPane::DesignerView)) - ] - .align_y(Alignment::Center); - let title_bar = pane_grid::TitleBar::new(title) +) -> pane_grid::Content<'_, Message, Theme> { + let title_bar = pane_grid::TitleBar::new(text("Generated Code").center()) + .controls(pane_grid::Controls::dynamic( + row![ + tip( + button(icon::copy()) + .on_press(Message::CopyCode) + .padding([2, 7]) + .style(material_theme::button::text), + "Copy", + tip::Position::FollowCursor + ), + button("Switch to Designer view") + .on_press(Message::SwitchPage(DesignerPane::DesignerView)) + ] + .spacing(20) + .align_y(Alignment::Center), + row![ + tip( + button(icon::copy()) + .on_press(Message::CopyCode) + .padding([2, 7]) + .style(material_theme::button::text), + "Copy", + tip::Position::FollowCursor + ), + button(icon::switch()) + .on_press(Message::SwitchPage(DesignerPane::DesignerView)) + ] + .spacing(20) + .align_y(Alignment::Center), + )) .padding(10) .style(style::title_bar); + pane_grid::Content::new( text_editor(editor_content) .on_action(Message::EditorAction) .font(Font::MONOSPACE) - .highlight_with::<Highlighter>( + .highlight_with::<Highlighter<Theme>>( Settings::new(vec![], highlight_style, "rs"), Highlight::to_format, ) .style(|theme, _| { - let palette = theme.extended_palette(); + let style = material_theme::text_editor::default( + theme, + text_editor::Status::Active, + ); + text_editor::Style { - background: Background::Color( - palette.background.base.color, - ), border: Border { - radius: 2.0.into(), - width: 1.0, - color: palette.background.strong.color, + radius: Radius::default(), + ..style.border }, - icon: palette.background.weak.text, - placeholder: palette.background.strong.color, - value: palette.background.base.text, - selection: palette.primary.weak.color, + ..style } }) .height(Length::Fill) |
