style.rs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. use iced::widget::button::Status;
  2. use iced::widget::container::Style;
  3. use iced::{theme, Border, Color, Font, Theme, overlay};
  4. use iced::widget::pick_list;
  5. pub const ICON_BYTES: &[u8] = include_bytes!("fonts/icons.ttf");
  6. pub const ICON_FONT: Font = Font::with_name("icons");
  7. pub enum Icon {
  8. Locked,
  9. Unlocked,
  10. ResizeFull,
  11. ResizeSmall,
  12. Close,
  13. Layout,
  14. Cog,
  15. Link,
  16. BinanceLogo,
  17. BybitLogo,
  18. }
  19. impl From<Icon> for char {
  20. fn from(icon: Icon) -> Self {
  21. match icon {
  22. Icon::Unlocked => '\u{E800}',
  23. Icon::Locked => '\u{E801}',
  24. Icon::ResizeFull => '\u{E802}',
  25. Icon::ResizeSmall => '\u{E803}',
  26. Icon::Close => '\u{E804}',
  27. Icon::Layout => '\u{E805}',
  28. Icon::Cog => '\u{E806}',
  29. Icon::Link => '\u{E807}',
  30. Icon::BybitLogo => '\u{E808}',
  31. Icon::BinanceLogo => '\u{E809}',
  32. }
  33. }
  34. }
  35. pub fn tooltip(theme: &Theme) -> Style {
  36. let palette = theme.extended_palette();
  37. Style {
  38. background: Some(palette.background.weak.color.into()),
  39. border: Border {
  40. width: 1.0,
  41. color: palette.primary.weak.color,
  42. radius: 4.0.into(),
  43. },
  44. ..Default::default()
  45. }
  46. }
  47. pub fn title_bar_active(theme: &Theme) -> Style {
  48. let palette = theme.extended_palette();
  49. Style {
  50. text_color: Some(palette.background.base.text),
  51. background: Some(Color::BLACK.into()),
  52. ..Default::default()
  53. }
  54. }
  55. pub fn title_bar_focused(theme: &Theme) -> Style {
  56. let palette = theme.extended_palette();
  57. Style {
  58. text_color: Some(palette.background.weak.text),
  59. background: Some(Color::TRANSPARENT.into()),
  60. ..Default::default()
  61. }
  62. }
  63. pub fn pane_active(theme: &Theme) -> Style {
  64. let palette = theme.extended_palette();
  65. Style {
  66. text_color: Some(palette.background.base.text),
  67. background: Some(Color::BLACK.into()),
  68. ..Default::default()
  69. }
  70. }
  71. pub fn pane_focused(theme: &Theme) -> Style {
  72. let palette = theme.extended_palette();
  73. Style {
  74. text_color: Some(palette.background.weak.text),
  75. background: Some(Color::BLACK.into()),
  76. border: Border {
  77. width: 1.0,
  78. color: palette.background.weak.color,
  79. radius: 4.0.into(),
  80. },
  81. ..Default::default()
  82. }
  83. }
  84. pub fn chart_modal(theme: &Theme) -> Style {
  85. let palette = theme.extended_palette();
  86. Style {
  87. text_color: Some(palette.background.base.text),
  88. background: Some(palette.background.base.color.into()),
  89. border: Border {
  90. width: 1.0,
  91. color: palette.background.weak.color,
  92. radius: 4.0.into(),
  93. },
  94. ..Default::default()
  95. }
  96. }
  97. pub fn button_primary(theme: &Theme, status: Status) -> iced::widget::button::Style {
  98. let palette = theme.extended_palette();
  99. match status {
  100. Status::Active => iced::widget::button::Style {
  101. background: Some(Color::BLACK.into()),
  102. text_color: palette.background.base.text,
  103. border: Border {
  104. radius: 3.0.into(),
  105. ..Default::default()
  106. },
  107. ..Default::default()
  108. },
  109. Status::Pressed => iced::widget::button::Style {
  110. background: Some(Color::BLACK.into()),
  111. text_color: palette.background.base.text,
  112. border: Border {
  113. color: palette.primary.weak.color,
  114. width: 2.0,
  115. radius: 6.0.into(),
  116. ..Default::default()
  117. },
  118. ..Default::default()
  119. },
  120. Status::Hovered => iced::widget::button::Style {
  121. background: Some(Color::BLACK.into()),
  122. text_color: palette.background.weak.text,
  123. border: Border {
  124. color: palette.primary.strong.color,
  125. width: 1.0,
  126. radius: 3.0.into(),
  127. ..Default::default()
  128. },
  129. ..Default::default()
  130. },
  131. Status::Disabled => iced::widget::button::Style {
  132. background: Some(Color::BLACK.into()),
  133. text_color: palette.background.base.text,
  134. border: Border {
  135. radius: 3.0.into(),
  136. ..Default::default()
  137. },
  138. ..Default::default()
  139. }
  140. }
  141. }
  142. pub fn picklist_primary(theme: &Theme, status: pick_list::Status) -> pick_list::Style {
  143. let palette = theme.extended_palette();
  144. match status {
  145. pick_list::Status::Active => pick_list::Style {
  146. text_color: palette.background.base.text,
  147. placeholder_color: palette.background.base.text,
  148. handle_color: palette.background.base.text,
  149. background: palette.background.base.color.into(),
  150. border: Border {
  151. radius: 3.0.into(),
  152. width: 1.0,
  153. color: palette.background.weak.color,
  154. ..Default::default()
  155. },
  156. },
  157. pick_list::Status::Opened => pick_list::Style {
  158. text_color: palette.background.base.text,
  159. placeholder_color: palette.background.base.text,
  160. handle_color: palette.background.base.text,
  161. background: palette.background.base.color.into(),
  162. border: Border {
  163. radius: 3.0.into(),
  164. width: 1.0,
  165. color: palette.primary.base.color,
  166. ..Default::default()
  167. },
  168. },
  169. pick_list::Status::Hovered => pick_list::Style {
  170. text_color: palette.background.weak.text,
  171. placeholder_color: palette.background.weak.text,
  172. handle_color: palette.background.weak.text,
  173. background: palette.background.base.color.into(),
  174. border: Border {
  175. radius: 3.0.into(),
  176. width: 1.0,
  177. color: palette.primary.strong.color,
  178. ..Default::default()
  179. },
  180. },
  181. }
  182. }
  183. pub fn picklist_menu_primary(theme: &Theme) -> overlay::menu::Style {
  184. let palette = theme.extended_palette();
  185. overlay::menu::Style {
  186. text_color: palette.background.base.text,
  187. background: palette.background.base.color.into(),
  188. border: Border {
  189. radius: 3.0.into(),
  190. width: 1.0,
  191. color: palette.background.base.color,
  192. ..Default::default()
  193. },
  194. selected_text_color: palette.background.weak.text,
  195. selected_background: palette.secondary.weak.color.into(),
  196. }
  197. }
  198. pub fn sell_side_red(color_alpha: f32) -> Style {
  199. Style {
  200. text_color: Color::from_rgba(192.0 / 255.0, 80.0 / 255.0, 77.0 / 255.0, 1.0).into(),
  201. border: Border {
  202. width: 1.0,
  203. color: Color::from_rgba(192.0 / 255.0, 80.0 / 255.0, 77.0 / 255.0, color_alpha),
  204. ..Border::default()
  205. },
  206. ..Default::default()
  207. }
  208. }
  209. pub fn buy_side_green(color_alpha: f32) -> Style {
  210. Style {
  211. text_color: Color::from_rgba(81.0 / 255.0, 205.0 / 255.0, 160.0 / 255.0, 1.0).into(),
  212. border: Border {
  213. width: 1.0,
  214. color: Color::from_rgba(81.0 / 255.0, 205.0 / 255.0, 160.0 / 255.0, color_alpha),
  215. ..Border::default()
  216. },
  217. ..Default::default()
  218. }
  219. }