| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705 |
- use iced::theme::{Custom, Palette};
- use iced::widget::button::Status;
- use iced::widget::container::{self, Style};
- use iced::widget::pane_grid::{Highlight, Line};
- use iced::widget::scrollable::{Rail, Scroller};
- use iced::widget::{text, Text};
- use iced::{widget, Border, Color, Font, Renderer, Shadow, Theme};
- pub const ICON_BYTES: &[u8] = include_bytes!("fonts/icons.ttf");
- pub const ICON_FONT: Font = Font::with_name("icons");
- pub enum Icon {
- Locked,
- Unlocked,
- ResizeFull,
- ResizeSmall,
- Close,
- Layout,
- Cog,
- Link,
- BinanceLogo,
- BybitLogo,
- Search,
- Sort,
- SortDesc,
- SortAsc,
- Star,
- StarFilled,
- Return,
- Popout,
- ChartOutline,
- }
- impl From<Icon> for char {
- fn from(icon: Icon) -> Self {
- match icon {
- Icon::Locked => '\u{E800}',
- Icon::Unlocked => '\u{E801}',
- Icon::Search => '\u{E802}',
- Icon::ResizeFull => '\u{E803}',
- Icon::ResizeSmall => '\u{E804}',
- Icon::Close => '\u{E805}',
- Icon::Layout => '\u{E806}',
- Icon::Link => '\u{E807}',
- Icon::BybitLogo => '\u{E808}',
- Icon::BinanceLogo => '\u{E809}',
- Icon::Cog => '\u{E810}',
- Icon::Sort => '\u{F0DC}',
- Icon::SortDesc => '\u{F0DD}',
- Icon::SortAsc => '\u{F0DE}',
- Icon::Star => '\u{E80A}',
- Icon::StarFilled => '\u{E80B}',
- Icon::Return => '\u{E80C}',
- Icon::Popout => '\u{E80D}',
- Icon::ChartOutline => '\u{E80E}',
- }
- }
- }
- pub fn get_icon_text<'a>(icon: Icon, size: u16) -> Text<'a, Theme, Renderer> {
- text(char::from(icon).to_string())
- .font(ICON_FONT)
- .size(size)
- }
- pub fn custom_theme() -> Custom {
- Custom::new(
- "Flowsurface".to_string(),
- Palette {
- background: Color::from_rgb8(24, 22, 22),
- text: Color::from_rgb8(197, 201, 197),
- primary: Color::from_rgb8(200, 200, 200),
- success: Color::from_rgb8(81, 205, 160),
- danger: Color::from_rgb8(192, 80, 77),
- warning: Color::from_rgb8(238, 216, 139),
- },
- )
- }
- #[cfg(target_os = "macos")]
- pub fn branding_text(theme: &Theme) -> iced::widget::text::Style {
- let palette = theme.extended_palette();
- iced::widget::text::Style {
- color: Some(
- palette
- .secondary
- .weak
- .color
- .scale_alpha(if palette.is_dark { 0.1 } else { 0.8 })
- ),
- }
- }
- // Tooltips
- pub fn tooltip(theme: &Theme) -> Style {
- let palette = theme.extended_palette();
- Style {
- background: Some(palette.background.weak.color.into()),
- border: Border {
- width: 1.0,
- color: palette.secondary.weak.color,
- radius: 4.0.into(),
- },
- ..Default::default()
- }
- }
- // Buttons
- pub fn button_transparent(
- theme: &Theme,
- status: Status,
- is_active: bool,
- ) -> iced::widget::button::Style {
- let palette = theme.extended_palette();
- let color_alpha = if palette.is_dark { 0.2 } else { 0.6 };
- match status {
- Status::Active => iced::widget::button::Style {
- background: if is_active {
- Some(palette.secondary.weak.color.scale_alpha(color_alpha).into())
- } else {
- None
- },
- text_color: palette.background.base.text,
- border: Border {
- radius: 3.0.into(),
- ..Default::default()
- },
- ..Default::default()
- },
- Status::Pressed => iced::widget::button::Style {
- text_color: palette.background.base.text,
- background: Some(
- palette
- .background
- .strong
- .color
- .scale_alpha(color_alpha)
- .into(),
- ),
- border: Border {
- radius: 3.0.into(),
- ..Default::default()
- },
- ..Default::default()
- },
- Status::Hovered => iced::widget::button::Style {
- background: if palette.is_dark {
- Some(palette.background.weak.color.into())
- } else {
- Some(palette.background.strong.color.into())
- },
- text_color: palette.background.base.text,
- border: Border {
- radius: 3.0.into(),
- ..Default::default()
- },
- ..Default::default()
- },
- Status::Disabled => iced::widget::button::Style {
- background: if is_active {
- None
- } else {
- Some(palette.secondary.weak.color.scale_alpha(color_alpha).into())
- },
- text_color: palette.background.base.text,
- border: Border {
- radius: 3.0.into(),
- ..Default::default()
- },
- ..Default::default()
- },
- }
- }
- pub fn button_modifier(
- theme: &Theme,
- status: Status,
- disabled: bool,
- ) -> iced::widget::button::Style {
- let palette = theme.extended_palette();
- let color_alpha = if palette.is_dark { 0.2 } else { 0.6 };
- match status {
- Status::Active => iced::widget::button::Style {
- background: if disabled {
- if palette.is_dark {
- Some(
- palette
- .background
- .weak
- .color
- .scale_alpha(color_alpha)
- .into(),
- )
- } else {
- Some(
- palette
- .background
- .base
- .color
- .scale_alpha(color_alpha)
- .into(),
- )
- }
- } else {
- Some(
- palette
- .background
- .strong
- .color
- .scale_alpha(color_alpha)
- .into(),
- )
- },
- text_color: palette.background.base.text,
- border: Border {
- radius: 3.0.into(),
- ..Default::default()
- },
- ..Default::default()
- },
- Status::Pressed => iced::widget::button::Style {
- text_color: palette.background.base.text,
- background: Some(
- palette
- .background
- .strong
- .color
- .scale_alpha(color_alpha)
- .into(),
- ),
- border: Border {
- radius: 3.0.into(),
- ..Default::default()
- },
- ..Default::default()
- },
- Status::Hovered => iced::widget::button::Style {
- background: if palette.is_dark {
- Some(palette.background.weak.color.into())
- } else {
- Some(palette.background.strong.color.into())
- },
- text_color: palette.background.base.text,
- border: Border {
- radius: 3.0.into(),
- ..Default::default()
- },
- ..Default::default()
- },
- Status::Disabled => iced::widget::button::Style {
- background: if disabled {
- None
- } else {
- Some(palette.secondary.weak.color.scale_alpha(color_alpha).into())
- },
- text_color: palette.background.base.text,
- border: Border {
- radius: 3.0.into(),
- ..Default::default()
- },
- ..Default::default()
- },
- }
- }
- // Panes
- pub fn pane_grid(theme: &Theme) -> widget::pane_grid::Style {
- let palette = theme.extended_palette();
- widget::pane_grid::Style {
- hovered_region: Highlight {
- background: palette.background.strong.color.into(),
- border: Border {
- width: 1.0,
- color: palette.primary.base.color,
- radius: 4.0.into(),
- },
- },
- picked_split: Line {
- color: palette.primary.strong.color,
- width: 4.0,
- },
- hovered_split: Line {
- color: palette.primary.weak.color,
- width: 4.0,
- },
- }
- }
- pub fn title_bar(theme: &Theme) -> Style {
- let palette = theme.extended_palette();
- Style {
- background: {
- if palette.is_dark {
- Some(palette.background.weak.color.scale_alpha(0.1).into())
- } else {
- Some(palette.background.strong.color.scale_alpha(0.1).into())
- }
- },
- ..Default::default()
- }
- }
- pub fn pane_primary(theme: &Theme, is_focused: bool) -> Style {
- let palette = theme.extended_palette();
- Style {
- text_color: Some(palette.background.base.text),
- background: Some(
- palette
- .background
- .weak
- .color
- .scale_alpha(if palette.is_dark { 0.1 } else { 0.6 })
- .into(),
- ),
- border: {
- if is_focused {
- Border {
- width: 1.0,
- color: {
- if palette.is_dark {
- palette.background.strong.color.scale_alpha(0.4)
- } else {
- palette.background.strong.color.scale_alpha(0.8)
- }
- },
- radius: 4.0.into(),
- }
- } else {
- Border {
- width: 1.0,
- color: {
- if palette.is_dark {
- palette.background.weak.color.scale_alpha(0.2)
- } else {
- palette.background.strong.color.scale_alpha(0.2)
- }
- },
- radius: 2.0.into(),
- }
- }
- },
- ..Default::default()
- }
- }
- // Modals
- pub fn chart_modal(theme: &Theme) -> Style {
- let palette = theme.extended_palette();
- Style {
- text_color: Some(palette.background.base.text),
- background: Some(
- Color {
- a: 0.99,
- ..palette.background.base.color
- }
- .into(),
- ),
- border: Border {
- width: 1.0,
- color: palette.secondary.weak.color,
- radius: 6.0.into(),
- },
- shadow: Shadow {
- offset: iced::Vector { x: 0.0, y: 0.0 },
- blur_radius: 12.0,
- color: Color::BLACK.scale_alpha(
- if palette.is_dark {
- 0.4
- } else {
- 0.2
- }
- ),
- },
- ..Default::default()
- }
- }
- pub fn dashboard_modal(theme: &Theme) -> Style {
- let palette = theme.extended_palette();
- Style {
- background: Some(
- Color {
- a: 0.99,
- ..palette.background.base.color
- }
- .into(),
- ),
- border: Border {
- width: 1.0,
- color: palette.secondary.weak.color,
- radius: 6.0.into(),
- },
- shadow: Shadow {
- offset: iced::Vector { x: 0.0, y: 0.0 },
- blur_radius: 20.0,
- color: Color::BLACK.scale_alpha(
- if palette.is_dark {
- 0.4
- } else {
- 0.2
- }
- ),
- },
- ..Default::default()
- }
- }
- pub fn modal_container(theme: &Theme) -> Style {
- let palette = theme.extended_palette();
- let color = if palette.is_dark {
- palette.background.weak.color.scale_alpha(0.6)
- } else {
- palette.background.strong.color.scale_alpha(0.6)
- };
- Style {
- text_color: Some(palette.background.base.text),
- background: Some(color.into()),
- border: Border {
- width: 1.0,
- color,
- radius: 6.0.into(),
- },
- shadow: Shadow {
- offset: iced::Vector { x: 0.0, y: 0.0 },
- blur_radius: 2.0,
- color: Color::BLACK.scale_alpha(
- if palette.is_dark {
- 0.8
- } else {
- 0.2
- }
- ),
- },
- }
- }
- pub fn sorter_container(theme: &Theme) -> Style {
- let palette = theme.extended_palette();
- let color = if palette.is_dark {
- palette.background.weak.color.scale_alpha(0.4)
- } else {
- palette.background.strong.color.scale_alpha(0.4)
- };
- Style {
- text_color: Some(palette.background.base.text),
- background: Some(color.into()),
- border: Border {
- width: 1.0,
- color,
- radius: 3.0.into(),
- },
- shadow: Shadow {
- offset: iced::Vector { x: 0.0, y: 0.0 },
- blur_radius: 2.0,
- color: Color::BLACK.scale_alpha(
- if palette.is_dark {
- 0.8
- } else {
- 0.2
- }
- ),
- },
- }
- }
- // Time&Sales Table
- pub fn ts_table_container(theme: &Theme, is_sell: bool, color_alpha: f32) -> Style {
- let palette = theme.extended_palette();
- let color = if is_sell {
- palette.danger.base.color
- } else {
- palette.success.base.color
- };
- Style {
- text_color: color.into(),
- border: Border {
- width: 1.0,
- color: color.scale_alpha(color_alpha),
- ..Border::default()
- },
- ..Default::default()
- }
- }
- // Tickers Table
- pub fn search_input(
- theme: &Theme,
- status: widget::text_input::Status,
- ) -> widget::text_input::Style {
- let palette = theme.extended_palette();
- match status {
- widget::text_input::Status::Active => widget::text_input::Style {
- background: palette.background.weak.color.into(),
- border: Border {
- radius: 3.0.into(),
- width: 1.0,
- color: palette.secondary.base.color,
- },
- icon: palette.background.strong.text,
- placeholder: palette.background.base.text,
- value: palette.background.weak.text,
- selection: palette.background.strong.color,
- },
- widget::text_input::Status::Hovered => widget::text_input::Style {
- background: palette.background.weak.color.into(),
- border: Border {
- radius: 3.0.into(),
- width: 1.0,
- color: palette.secondary.strong.color,
- },
- icon: palette.background.strong.text,
- placeholder: palette.background.base.text,
- value: palette.background.weak.text,
- selection: palette.background.strong.color,
- },
- widget::text_input::Status::Focused { .. } => widget::text_input::Style {
- background: palette.background.weak.color.into(),
- border: Border {
- radius: 3.0.into(),
- width: 2.0,
- color: palette.secondary.strong.color,
- },
- icon: palette.background.strong.text,
- placeholder: palette.background.base.text,
- value: palette.background.weak.text,
- selection: palette.background.strong.color,
- },
- widget::text_input::Status::Disabled => widget::text_input::Style {
- background: palette.background.weak.color.into(),
- border: Border {
- radius: 3.0.into(),
- width: 1.0,
- color: palette.secondary.weak.color,
- },
- icon: palette.background.weak.text,
- placeholder: palette.background.weak.text,
- value: palette.background.weak.text,
- selection: palette.background.weak.text,
- },
- }
- }
- pub fn ticker_card(theme: &Theme, _color_alpha: f32) -> Style {
- let palette = theme.extended_palette();
- let color_alpha = if palette.is_dark { 0.2 } else { 0.8 };
- Style {
- background: Some(
- palette
- .background
- .weak
- .color
- .scale_alpha(color_alpha)
- .into(),
- ),
- border: Border {
- radius: 4.0.into(),
- width: 1.0,
- ..Border::default()
- },
- ..Default::default()
- }
- }
- pub fn ticker_card_bar(theme: &Theme, color_alpha: f32) -> Style {
- let palette = theme.extended_palette();
- Style {
- background: {
- if color_alpha > 0.0 {
- Some(palette.success.strong.color.scale_alpha(color_alpha).into())
- } else {
- Some(palette.danger.strong.color.scale_alpha(-color_alpha).into())
- }
- },
- border: Border {
- radius: 4.0.into(),
- width: 1.0,
- color: if color_alpha > 0.0 {
- palette.success.strong.color.scale_alpha(color_alpha)
- } else {
- palette.danger.strong.color.scale_alpha(-color_alpha)
- },
- },
- ..Default::default()
- }
- }
- pub fn ticker_card_button(theme: &Theme, status: Status) -> iced::widget::button::Style {
- let palette = theme.extended_palette();
- match status {
- Status::Hovered => iced::widget::button::Style {
- text_color: palette.background.base.text,
- background: Some(palette.background.weak.color.scale_alpha(0.1).into()),
- border: Border {
- radius: 4.0.into(),
- width: 1.0,
- color: {
- if palette.is_dark {
- palette.background.strong.color.scale_alpha(0.4)
- } else {
- palette.background.strong.color.scale_alpha(0.8)
- }
- },
- },
- ..Default::default()
- },
- _ => iced::widget::button::Style {
- text_color: palette.background.base.text,
- ..Default::default()
- },
- }
- }
- // Scrollable
- pub fn scroll_bar(theme: &Theme, status: widget::scrollable::Status) -> widget::scrollable::Style {
- let palette = theme.extended_palette();
- let light_factor = if palette.is_dark { 1.0 } else { 4.0 };
- let (rail_bg, scroller_bg) = match status {
- widget::scrollable::Status::Dragged { .. }
- | widget::scrollable::Status::Hovered { .. } => {
- (
- palette.background.weak.color.scale_alpha(0.2 * light_factor),
- palette.secondary.weak.color.scale_alpha(0.8 * light_factor),
- )
- },
- _ => (
- palette.background.weak.color.scale_alpha(0.1 * light_factor),
- palette.secondary.weak.color.scale_alpha(0.4 * light_factor),
- ),
- };
- let rail = Rail {
- background: Some(iced::Background::Color(rail_bg)),
- border: Border {
- radius: 4.0.into(),
- width: 1.0,
- color: Color::TRANSPARENT,
- },
- scroller: Scroller {
- color: scroller_bg,
- border: Border {
- radius: 4.0.into(),
- width: 0.0,
- color: Color::TRANSPARENT,
- },
- },
- };
- widget::scrollable::Style {
- container: container::Style {
- text_color: None,
- background: None,
- border: Border {
- radius: 4.0.into(),
- width: 1.0,
- color: Color::TRANSPARENT,
- },
- shadow: Shadow::default(),
- },
- vertical_rail: rail,
- horizontal_rail: rail,
- gap: None,
- }
- }
- // custom widgets
- pub fn split_ruler(theme: &Theme) -> iced::widget::rule::Style {
- let palette = theme.extended_palette();
- iced::widget::rule::Style {
- color: {
- if palette.is_dark {
- palette.background.weak.color.scale_alpha(0.2)
- } else {
- palette.background.strong.color.scale_alpha(0.2)
- }
- },
- width: 1,
- radius: iced::border::Radius::default(),
- fill_mode: iced::widget::rule::FillMode::Full,
- }
- }
|