from_iced_theme

Function from_iced_theme 

Source
pub fn from_iced_theme(theme: &Theme) -> Style
Expand description

Creates a theme style automatically from any Iced theme.

This is the default styling function that adapts to all native Iced themes including:

  • Basic themes: Light, Dark
  • Popular themes: Dracula, Nord, Solarized, Gruvbox
  • Catppuccin variants: Latte, Frappé, Macchiato, Mocha
  • Tokyo Night variants: Tokyo Night, Storm, Light
  • Kanagawa variants: Wave, Dragon, Lotus
  • And more: Moonfly, Nightfly, Oxocarbon, Ferra

The function automatically detects if the theme is dark or light and adjusts colors accordingly for optimal contrast and readability in code editing.

§Color Mapping

  • background: Uses the theme’s base background color
  • text_color: Uses the theme’s base text color
  • gutter_background: Slightly darker/lighter than background
  • gutter_border: Border between gutter and editor
  • line_number_color: Dimmed text color for subtle line numbers
  • scrollbar_background: Matches editor background
  • scroller_color: Uses secondary color for visibility
  • current_line_highlight: Subtle highlight using primary color

§Example

use iced_code_editor::theme;

let tokyo_night = iced::Theme::TokyoNightStorm;
let style = theme::from_iced_theme(&tokyo_night);

// Or use with any theme variant
let dracula = iced::Theme::Dracula;
let style = theme::from_iced_theme(&dracula);