diff --git a/src/app.rs b/src/app.rs index 5add935..613b0f2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4,6 +4,7 @@ use crate::{app::tile::ExtSender, clipboard::ClipBoardContentType}; pub mod apps; pub mod menubar; +pub mod pages; pub mod tile; use iced::window::{self, Id, Settings}; diff --git a/src/app/apps.rs b/src/app/apps.rs index a6232c8..d55c2d0 100644 --- a/src/app/apps.rs +++ b/src/app/apps.rs @@ -6,7 +6,7 @@ use std::path::Path; use iced::{ Alignment, Length::Fill, - widget::{Button, Row, Text, container, image::Viewer}, + widget::{Button, Row, Text, container, image::Viewer, text::Wrapping}, }; use crate::{ @@ -53,7 +53,7 @@ impl App { /// A vec of all the emojis as App structs pub fn emoji_apps() -> Vec { emojis::iter() - .filter(|x| x.unicode_version() < emojis::UnicodeVersion::new(13, 0)) + .filter(|x| x.unicode_version() < emojis::UnicodeVersion::new(17, 13)) .map(|x| App { icons: None, name: x.to_string(), @@ -154,6 +154,7 @@ impl App { Text::new(self.name) .font(theme.font()) .size(16) + .wrapping(Wrapping::WordOrGlyph) .color(theme.text_color(1.0)), ) .push( diff --git a/src/app/pages.rs b/src/app/pages.rs new file mode 100644 index 0000000..929c35e --- /dev/null +++ b/src/app/pages.rs @@ -0,0 +1,5 @@ +pub mod clipboard; +pub mod common; +pub mod emoji; +pub mod prelude; +pub mod settings; diff --git a/src/app/pages/clipboard.rs b/src/app/pages/clipboard.rs new file mode 100644 index 0000000..7eab31f --- /dev/null +++ b/src/app/pages/clipboard.rs @@ -0,0 +1,53 @@ +use iced::widget::{ + Scrollable, + scrollable::{Direction, Scrollbar}, +}; + +use crate::{app::pages::prelude::*, clipboard::ClipBoardContentType}; + +pub fn clipboard_view( + clipboard_content: Vec, + focussed_id: u32, + theme: Theme, + focus_id: u32, +) -> Element<'static, Message> { + let theme_clone = theme.clone(); + let theme_clone_2 = theme.clone(); + Row::from_vec(vec![ + container( + Column::from_iter( + clipboard_content + .iter() + .enumerate() + .map(|(i, content)| content.to_app().render(theme.clone(), i as u32, focus_id)), + ) + .width(WINDOW_WIDTH / 3.), + ) + .height(7 * 55) + .style(move |_| result_row_container_style(&theme_clone_2, false)) + .into(), + container(Scrollable::with_direction( + Text::new( + clipboard_content + .get(focussed_id as usize) + .map(|x| x.to_app().name_lc) + .unwrap_or("".to_string()), + ) + .height(Length::Fill) + .width(Length::Fill) + .align_x(Alignment::Start) + .font(theme.font()) + .size(16), + Direction::Both { + vertical: Scrollbar::new().scroller_width(0.).width(0.), + horizontal: Scrollbar::new().scroller_width(0.).width(0.), + }, + )) + .padding(10) + .style(move |_| result_row_container_style(&theme_clone, false)) + .width((WINDOW_WIDTH / 3.) * 2.) + .height(7 * 55) + .into(), + ]) + .into() +} diff --git a/src/app/pages/common.rs b/src/app/pages/common.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/app/pages/common.rs @@ -0,0 +1 @@ + diff --git a/src/app/pages/emoji.rs b/src/app/pages/emoji.rs new file mode 100644 index 0000000..978167f --- /dev/null +++ b/src/app/pages/emoji.rs @@ -0,0 +1,86 @@ +use iced::{Border, Length::Fill, border::Radius, widget::tooltip}; + +use crate::{app::pages::prelude::*, clipboard::ClipBoardContentType, commands::Function}; + +pub fn emoji_page( + tile_theme: Theme, + emojis: Vec, + focussed_id: u32, +) -> Element<'static, Message> { + let emoji_vec = emojis + .chunks(6) + .map(|x| x.to_vec()) + .collect::>>(); + + let mut column = Vec::new(); + + let mut id_num = 0; + + for emoji_row in emoji_vec { + let mut emoji_row_element = Row::new().spacing(10); + for emoji in emoji_row { + let theme_clone = tile_theme.clone(); + let element_column = Column::new().push( + Text::new(emoji.name.clone()) + .font(tile_theme.font()) + .size(30) + .width(Length::Fill) + .height(Fill) + .align_y(Alignment::Center) + .align_x(Alignment::Center), + ); + let value = tile_theme.clone(); + let value_two = tile_theme.clone(); + emoji_row_element = emoji_row_element.push(tooltip( + container( + Button::new(element_column) + .width(70) + .height(70) + .on_press(Message::RunFunction(Function::CopyToClipboard( + ClipBoardContentType::Text(emoji.name), + ))) + .style(move |_, _| emoji_button_style(&value)), + ) + .width(70) + .height(70) + .id(format!("result-{}", id_num)) + .style(move |_| emoji_button_container_style(&theme_clone, focussed_id == id_num)), + container( + Text::new(emoji.desc) + .font(tile_theme.font()) + .size(20) + .color(tile_theme.text_color(0.7)), + ) + .style(move |_| container::Style { + background: Some(Background::Color(value_two.bg_color())), + ..Default::default() + }), + tooltip::Position::Top, + )); + + id_num += 1; + } + + column.push(container(emoji_row_element).center_y(70).into()); + } + + let tile_theme_clone = tile_theme.clone(); + + container(Column::from_vec(column).spacing(10)) + .padding(5) + .style(move |_| { + result_row_container_style(&tile_theme_clone, false) + .background({ + let mut clr = tile_theme_clone.bg_color(); + clr.a = 1.; + Background::Color(tint(clr, 0.02)) + }) + .border(Border { + color: tile_theme.bg_color(), + width: 1., + radius: Radius::new(0), + }) + }) + .center_x(WINDOW_WIDTH) + .into() +} diff --git a/src/app/pages/prelude.rs b/src/app/pages/prelude.rs new file mode 100644 index 0000000..a9484b6 --- /dev/null +++ b/src/app/pages/prelude.rs @@ -0,0 +1,10 @@ +pub use iced::{ + Alignment, Background, Element, Length, + widget::{Button, Column, Row, Text, container}, +}; + +pub use crate::{ + app::{Message, WINDOW_WIDTH, apps::App}, + config::Theme, + styles::{emoji_button_container_style, emoji_button_style, result_row_container_style, tint}, +}; diff --git a/src/app/pages/settings.rs b/src/app/pages/settings.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/app/pages/settings.rs @@ -0,0 +1 @@ + diff --git a/src/app/tile.rs b/src/app/tile.rs index cae008f..fc31d80 100644 --- a/src/app/tile.rs +++ b/src/app/tile.rs @@ -143,6 +143,12 @@ impl Tile { keyboard::Key::Named(Named::ArrowUp) => { return Some(Message::ChangeFocus(ArrowKey::Up)); } + keyboard::Key::Named(Named::ArrowLeft) => { + return Some(Message::ChangeFocus(ArrowKey::Left)); + } + keyboard::Key::Named(Named::ArrowRight) => { + return Some(Message::ChangeFocus(ArrowKey::Right)); + } keyboard::Key::Named(Named::ArrowDown) => { return Some(Message::ChangeFocus(ArrowKey::Down)); } diff --git a/src/app/tile/elm.rs b/src/app/tile/elm.rs index 4dfc5ca..df952f4 100644 --- a/src/app/tile/elm.rs +++ b/src/app/tile/elm.rs @@ -15,6 +15,8 @@ use rayon::{ slice::ParallelSliceMut, }; +use crate::app::pages::clipboard::clipboard_view; +use crate::app::pages::emoji::emoji_page; use crate::app::tile::AppIndex; use crate::styles::{contents_style, rustcast_text_input_style}; use crate::{ @@ -100,8 +102,8 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> { let scrollbar_direction = if tile.config.theme.show_scroll_bar { Direction::Vertical( Scrollbar::new() - .width(2) - .scroller_width(2) + .width(10) + .scroller_width(10) .anchor(Anchor::Start), ) } else { @@ -109,21 +111,29 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> { }; let results = if tile.page == Page::ClipboardHistory { - Column::from_iter( - tile.clipboard_content - .iter() - .enumerate() - .map(|(i, content)| { - content - .to_app() - .render(tile.config.theme.clone(), i as u32, tile.focus_id) - }), + clipboard_view( + tile.clipboard_content.clone(), + tile.focus_id, + tile.config.theme.clone(), + tile.focus_id, + ) + } else if tile.results.is_empty() { + space().into() + } else if tile.page == Page::EmojiSearch { + emoji_page( + tile.config.theme.clone(), + tile.emoji_apps + .search_prefix(&tile.query_lc) + .map(|x| x.to_owned()) + .collect(), + tile.focus_id, ) } else { Column::from_iter(tile.results.iter().enumerate().map(|(i, app)| { app.clone() .render(tile.config.theme.clone(), i as u32, tile.focus_id) })) + .into() }; let scrollable = Scrollable::with_direction(results, scrollbar_direction).id("results"); @@ -139,7 +149,7 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> { ..Default::default() }); - container(contents.clip(true)) + container(contents.clip(false)) .style(|_| contents_style(&tile.config.theme)) .into() } else { diff --git a/src/app/tile/update.rs b/src/app/tile/update.rs index 292765b..4e48e17 100644 --- a/src/app/tile/update.rs +++ b/src/app/tile/update.rs @@ -65,6 +65,10 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task { } Message::EscKeyPressed(id) => { + if tile.page == Page::EmojiSearch && !tile.query_lc.is_empty() { + return Task::none(); + } + if tile.query_lc.is_empty() { Task::batch([ Task::done(Message::HideWindow(id)), @@ -87,183 +91,6 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task { } } - Message::SearchQueryChanged(input, id) => { - tile.focus_id = 0; - #[cfg(target_os = "macos")] - if tile.config.haptic_feedback { - perform_haptic(HapticPattern::Alignment); - } - - tile.query_lc = input.trim().to_lowercase(); - tile.query = input; - let prev_size = tile.results.len(); - if tile.query_lc.is_empty() && tile.page != Page::ClipboardHistory { - tile.results = vec![]; - return window::resize( - id, - iced::Size { - width: WINDOW_WIDTH, - height: DEFAULT_WINDOW_HEIGHT, - }, - ); - } else if tile.query_lc == "randomvar" { - let rand_num = rand::random_range(0..100); - tile.results = vec![App { - open_command: AppCommand::Function(Function::RandomVar(rand_num)), - desc: "Easter egg".to_string(), - icons: None, - name: rand_num.to_string(), - name_lc: String::new(), - }]; - return window::resize( - id, - iced::Size { - width: WINDOW_WIDTH, - height: 55. + DEFAULT_WINDOW_HEIGHT, - }, - ); - } else if tile.query_lc == "67" { - tile.results = vec![App { - open_command: AppCommand::Function(Function::RandomVar(67)), - desc: "Easter egg".to_string(), - icons: None, - name: 67.to_string(), - name_lc: String::new(), - }]; - return window::resize( - id, - iced::Size { - width: WINDOW_WIDTH, - height: 55. + DEFAULT_WINDOW_HEIGHT, - }, - ); - } else if tile.query_lc.ends_with("?") { - tile.results = vec![App { - open_command: AppCommand::Function(Function::GoogleSearch(tile.query.clone())), - icons: None, - desc: "Web Search".to_string(), - name: format!("Search for: {}", tile.query), - name_lc: String::new(), - }]; - return window::resize( - id, - iced::Size::new(WINDOW_WIDTH, 55. + DEFAULT_WINDOW_HEIGHT), - ); - } else if tile.query_lc == "cbhist" { - tile.page = Page::ClipboardHistory - } else if tile.query_lc == "main" { - tile.page = Page::Main - } - - tile.handle_search_query_changed(); - - if tile.results.is_empty() - && let Some(res) = Expr::from_str(&tile.query).ok() - { - tile.results.push(App { - open_command: AppCommand::Function(Function::Calculate(res.clone())), - desc: RUSTCAST_DESC_NAME.to_string(), - icons: None, - name: res.eval().map(|x| x.to_string()).unwrap_or("".to_string()), - name_lc: "".to_string(), - }); - } else if tile.results.is_empty() - && let Some(conversions) = unit_conversion::convert_query(&tile.query) - { - tile.results = conversions - .into_iter() - .map(|conversion| { - let source = format!( - "{} {}", - unit_conversion::format_number(conversion.source_value), - conversion.source_unit.name - ); - let target = format!( - "{} {}", - unit_conversion::format_number(conversion.target_value), - conversion.target_unit.name - ); - App { - open_command: AppCommand::Function(Function::CopyToClipboard( - ClipBoardContentType::Text(target.clone()), - )), - desc: source, - icons: None, - name: target, - name_lc: String::new(), - } - }) - .collect(); - } else if tile.results.is_empty() && is_valid_url(&tile.query) { - tile.results.push(App { - open_command: AppCommand::Function(Function::OpenWebsite(tile.query.clone())), - desc: "Web Browsing".to_string(), - icons: None, - name: "Open Website: ".to_string() + &tile.query, - name_lc: "".to_string(), - }); - } else if tile.query_lc.split(' ').count() > 1 { - tile.results.push(App { - open_command: AppCommand::Function(Function::GoogleSearch(tile.query.clone())), - icons: None, - desc: "Web Search".to_string(), - name: format!("Search for: {}", tile.query), - name_lc: String::new(), - }); - } else if tile.results.is_empty() && tile.query_lc == "lemon" { - tile.results.push(App { - open_command: AppCommand::Display, - desc: "Easter Egg".to_string(), - icons: Some(Handle::from_path(Path::new( - "/Applications/Rustcast.app/Contents/Resources/lemon.png", - ))), - name: "Lemon".to_string(), - name_lc: "".to_string(), - }); - } - let new_length = tile.results.len(); - - let max_elem = min(5, new_length); - - if tile.results - == vec![App { - open_command: AppCommand::Message(Message::SwitchToPage( - Page::ClipboardHistory, - )), - desc: RUSTCAST_DESC_NAME.to_string(), - icons: None, - name: "Clipboard History".to_string(), - name_lc: "clipboard".to_string(), - }] - { - tile.page = Page::ClipboardHistory - } - - if prev_size != new_length && tile.page != Page::ClipboardHistory { - Task::batch([ - window::resize( - id, - iced::Size { - width: WINDOW_WIDTH, - height: ((max_elem * 70) + DEFAULT_WINDOW_HEIGHT as usize) as f32, - }, - ), - Task::done(Message::ChangeFocus(ArrowKey::Left)), - ]) - } else if tile.page == Page::ClipboardHistory { - let element_count = min(tile.clipboard_content.len(), 5); - window::resize( - id, - iced::Size { - width: WINDOW_WIDTH, - height: ((element_count * 70) + DEFAULT_WINDOW_HEIGHT as usize) as f32, - }, - ) - } else { - Task::none() - } - } - Message::ClearSearchQuery => { tile.query_lc = String::new(); tile.query = String::new(); @@ -271,24 +98,55 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task { } Message::ChangeFocus(key) => { - let u32_len = tile.results.len() as u32; - if u32_len > 0 { - match key { - ArrowKey::Down => tile.focus_id = (tile.focus_id + 1) % u32_len, - ArrowKey::Up => tile.focus_id = (tile.focus_id + u32_len - 1) % u32_len, - _ => {} + let len = match tile.page { + Page::ClipboardHistory => tile.clipboard_content.len() as u32, + Page::EmojiSearch => tile.emoji_apps.search_prefix(&tile.query_lc).count() as u32, // or tile.results.len() + _ => tile.results.len() as u32, + }; + + let old_focus_id = tile.focus_id.clone(); + + if len == 0 { + return Task::none(); + } + + let change_by = match tile.page { + Page::EmojiSearch => 6, + _ => 1, + }; + + let task = match (key, &tile.page) { + (ArrowKey::Down, _) => { + tile.focus_id = (tile.focus_id + change_by) % len; + Task::none() } + (ArrowKey::Up, _) => { + tile.focus_id = (tile.focus_id + len - change_by) % len; + Task::none() + } + (ArrowKey::Left, Page::EmojiSearch) => { + tile.focus_id = (tile.focus_id + len - 1) % len; + operation::focus("results") + } + (ArrowKey::Right, Page::EmojiSearch) => { + tile.focus_id = (tile.focus_id + 1) % len; + operation::focus("results") + } + _ => Task::none(), + }; + + let direction = if tile.focus_id < old_focus_id { -1 } else { 1 }; + Task::batch([ + task, operation::scroll_to( "results", AbsoluteOffset { x: None, - y: Some(tile.focus_id as f32 * 55.), + y: Some((tile.focus_id as f32 * 5.) * direction as f32), }, - ) - } else { - Task::none() - } + ), + ]) } Message::OpenFocused => match tile.results.get(tile.focus_id as usize) { @@ -438,9 +296,180 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task { } } - Message::ClipboardHistory(clip_content) => { - tile.clipboard_content.insert(0, clip_content); + Message::ClipboardHistory(content) => { + tile.clipboard_content.insert(0, content); Task::none() } + + Message::SearchQueryChanged(input, id) => { + tile.focus_id = 0; + #[cfg(target_os = "macos")] + if tile.config.haptic_feedback { + perform_haptic(HapticPattern::Alignment); + } + + tile.query_lc = input.trim().to_lowercase(); + tile.query = input; + let prev_size = tile.results.len(); + if tile.query_lc.is_empty() && tile.page != Page::ClipboardHistory { + tile.results = vec![]; + return window::resize( + id, + iced::Size { + width: WINDOW_WIDTH, + height: DEFAULT_WINDOW_HEIGHT, + }, + ); + } else if tile.query_lc == "randomvar" { + let rand_num = rand::random_range(0..100); + tile.results = vec![App { + open_command: AppCommand::Function(Function::RandomVar(rand_num)), + desc: "Easter egg".to_string(), + icons: None, + name: rand_num.to_string(), + name_lc: String::new(), + }]; + return window::resize( + id, + iced::Size { + width: WINDOW_WIDTH, + height: 55. + DEFAULT_WINDOW_HEIGHT, + }, + ); + } else if tile.query_lc == "67" { + tile.results = vec![App { + open_command: AppCommand::Function(Function::RandomVar(67)), + desc: "Easter egg".to_string(), + icons: None, + name: 67.to_string(), + name_lc: String::new(), + }]; + return window::resize( + id, + iced::Size { + width: WINDOW_WIDTH, + height: 55. + DEFAULT_WINDOW_HEIGHT, + }, + ); + } else if tile.query_lc.ends_with("?") { + tile.results = vec![App { + open_command: AppCommand::Function(Function::GoogleSearch(tile.query.clone())), + icons: None, + desc: "Web Search".to_string(), + name: format!("Search for: {}", tile.query), + name_lc: String::new(), + }]; + return window::resize( + id, + iced::Size::new(WINDOW_WIDTH, 55. + DEFAULT_WINDOW_HEIGHT), + ); + } else if tile.query_lc == "cbhist" { + tile.page = Page::ClipboardHistory + } else if tile.query_lc == "main" { + tile.page = Page::Main + } + tile.handle_search_query_changed(); + + if tile.results.is_empty() + && let Some(res) = Expr::from_str(&tile.query).ok() + { + tile.results.push(App { + open_command: AppCommand::Function(Function::Calculate(res.clone())), + desc: RUSTCAST_DESC_NAME.to_string(), + icons: None, + name: res.eval().map(|x| x.to_string()).unwrap_or("".to_string()), + name_lc: "".to_string(), + }); + } else if tile.results.is_empty() + && let Some(conversions) = unit_conversion::convert_query(&tile.query) + { + tile.results = conversions + .into_iter() + .map(|conversion| { + let source = format!( + "{} {}", + unit_conversion::format_number(conversion.source_value), + conversion.source_unit.name + ); + let target = format!( + "{} {}", + unit_conversion::format_number(conversion.target_value), + conversion.target_unit.name + ); + App { + open_command: AppCommand::Function(Function::CopyToClipboard( + ClipBoardContentType::Text(target.clone()), + )), + desc: source, + icons: None, + name: target, + name_lc: String::new(), + } + }) + .collect(); + } else if tile.results.is_empty() && is_valid_url(&tile.query) { + tile.results.push(App { + open_command: AppCommand::Function(Function::OpenWebsite(tile.query.clone())), + desc: "Web Browsing".to_string(), + icons: None, + name: "Open Website: ".to_string() + &tile.query, + name_lc: "".to_string(), + }); + } else if tile.query_lc.split(' ').count() > 1 { + tile.results.push(App { + open_command: AppCommand::Function(Function::GoogleSearch(tile.query.clone())), + icons: None, + desc: "Web Search".to_string(), + name: format!("Search for: {}", tile.query), + name_lc: String::new(), + }); + } else if tile.results.is_empty() && tile.query_lc == "lemon" { + tile.results.push(App { + open_command: AppCommand::Display, + desc: "Easter Egg".to_string(), + icons: Some(Handle::from_path(Path::new( + "/Applications/Rustcast.app/Contents/Resources/lemon.png", + ))), + name: "Lemon".to_string(), + name_lc: "".to_string(), + }); + } + if !tile.query_lc.is_empty() && tile.page == Page::EmojiSearch { + tile.results = tile + .emoji_apps + .search_prefix("") + .map(|x| x.to_owned()) + .collect(); + } + + let new_length = tile.results.len(); + let max_elem = min(5, new_length); + + if prev_size != new_length && tile.page != Page::ClipboardHistory { + Task::batch([ + window::resize( + id, + iced::Size { + width: WINDOW_WIDTH, + height: ((max_elem * 55) + DEFAULT_WINDOW_HEIGHT as usize) as f32, + }, + ), + Task::done(Message::ChangeFocus(ArrowKey::Left)), + ]) + } else if tile.page == Page::ClipboardHistory { + Task::batch([ + window::resize( + id, + iced::Size { + width: WINDOW_WIDTH, + height: ((7 * 55) + DEFAULT_WINDOW_HEIGHT as usize) as f32, + }, + ), + Task::done(Message::ChangeFocus(ArrowKey::Left)), + ]) + } else { + Task::none() + } + } } } diff --git a/src/clipboard.rs b/src/clipboard.rs index 07d6d87..979432e 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -11,14 +11,19 @@ pub enum ClipBoardContentType { } impl ClipBoardContentType { - /// Returns the iced element for rendering the clipboard item + /// Returns the iced element for rendering the clipboard item, and the entire content since the + /// display name is only the first line pub fn to_app(&self) -> App { - let name = match self { + let mut name = match self { ClipBoardContentType::Image(_) => "".to_string(), ClipBoardContentType::Text(a) => a.to_owned(), }; let self_clone = self.clone(); + let name_lc = name.clone(); + + // only get the first line from the contents + name = name.lines().next().unwrap_or("").to_string(); App { open_command: crate::app::apps::AppCommand::Function(Function::CopyToClipboard( @@ -26,7 +31,7 @@ impl ClipBoardContentType { )), desc: "Clipboard Item".to_string(), icons: None, - name_lc: name.to_lowercase(), + name_lc, name, } } diff --git a/src/styles.rs b/src/styles.rs index b7e2dc5..af7a2f4 100644 --- a/src/styles.rs +++ b/src/styles.rs @@ -87,3 +87,35 @@ pub fn result_row_container_style(tile: &ConfigTheme, focused: bool) -> containe ..Default::default() } } + +pub fn emoji_button_container_style(tile_theme: &ConfigTheme, focused: bool) -> container::Style { + let base = tile_theme.bg_color(); + let row_bg = if focused { + with_alpha(tint(base, 0.10), 1.0) + } else { + with_alpha(tint(base, 0.04), 1.0) + }; + container::Style { + background: Some(Background::Color(row_bg)), + text_color: Some(tile_theme.text_color(1.)), + border: Border { + color: tile_theme.text_color(0.8), + width: 0., + radius: Radius::new(10), + }, + ..Default::default() + } +} + +pub fn emoji_button_style(tile_theme: &ConfigTheme) -> button::Style { + button::Style { + background: Some(Background::Color(tint(tile_theme.bg_color(), 0.02))), + text_color: tile_theme.text_color(1.), + border: Border { + color: tile_theme.text_color(0.8), + width: 0.1, + radius: Radius::new(10), + }, + ..Default::default() + } +} diff --git a/src/unit_conversion.rs b/src/unit_conversion.rs index 5fa3379..3bc6f7f 100644 --- a/src/unit_conversion.rs +++ b/src/unit_conversion.rs @@ -333,10 +333,10 @@ fn parse_number_prefix(s: &str) -> Option<(&str, &str)> { } let mut chars = s.char_indices().peekable(); - if let Some((_, c)) = chars.peek() { - if *c == '+' || *c == '-' { - chars.next(); - } + if let Some((_, c)) = chars.peek() + && (*c == '+' || *c == '-') + { + chars.next(); } let mut end = 0; @@ -370,7 +370,7 @@ fn find_unit(token: &str) -> Option<&'static UnitDef> { UNITS .iter() - .find(|unit| unit.name == token || unit.aliases.iter().any(|alias| *alias == token)) + .find(|unit| unit.name == token || unit.aliases.contains(&token)) } fn to_base(value: f64, unit: &UnitDef) -> f64 {