diff --git a/src/app/entries/mod.rs b/src/app/entries/mod.rs index 20826be..b5f854f 100644 --- a/src/app/entries/mod.rs +++ b/src/app/entries/mod.rs @@ -1,9 +1,10 @@ +use crate::app::style::rows::button::ButtonStyle; use crate::app::style::rows::icon::IconStyle; use crate::app::style::rows::RowStyles; use crate::app::Message; use crate::icons::{fallback_icon, Extension, IconPath}; use crate::THEME; -use iced::widget::{column, container, row, text, Container, Image, Row}; +use iced::widget::{column, container, row, text, Button, Container, Image, Row}; use iced::{Alignment, Length, Renderer}; use std::borrow::Cow; @@ -35,14 +36,19 @@ pub(crate) trait AsEntry<'a> { // See : https://github.com/iced-rs/iced/pull/1044 .align_items(Alignment::Start); - self.as_row(row, theme) + self.as_row(row, theme, idx) } - fn as_row<'b>(&self, row: Row<'b, Message>, theme: &'static RowStyles) -> Container<'b, Message> + fn as_row<'b>( + &self, + row: Row<'b, Message>, + theme: &'static RowStyles, + idx: usize, + ) -> Container<'b, Message> where 'b: 'a, { - let title_row: iced::widget::Container<'_, Message, Renderer> = + let title_row: Container<'_, Message, Renderer> = container(iced::widget::row(vec![text(self.get_display_name()) .size(theme.title.font_size) .into()])) @@ -73,7 +79,11 @@ pub(crate) trait AsEntry<'a> { _ => column, }; - Container::new(row.push(column)) + let button = Button::new(row.push(column)) + .style(iced::theme::Button::Custom(Box::new(&ButtonStyle))) + .on_press(Message::Click(idx)); + + Container::new(button) .style(iced::theme::Container::Custom(Box::new(theme))) .padding(theme.padding.to_iced_padding()) .width(theme.width) @@ -123,8 +133,8 @@ pub(crate) trait AsEntry<'a> { Extension::Svg => Container::new( icon.as_ref() .to_svg(&theme.color) - .height(iced_core::Length::Fixed(theme.icon_size as f32)) - .width(iced_core::Length::Fixed(theme.icon_size as f32)), + .height(Length::Fixed(theme.icon_size as f32)) + .width(Length::Fixed(theme.icon_size as f32)), ), Extension::Png => Container::new( Image::new(&icon.as_ref().path) diff --git a/src/app/mod.rs b/src/app/mod.rs index 3f6c1f6..81375ab 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -80,6 +80,7 @@ pub struct Onagre<'a> { pub enum Message { Loading, InputChanged(String), + Click(usize), KeyboardEvent(KeyCode), SubscriptionResponse(SubscriptionMessage), Unfocused, @@ -136,6 +137,14 @@ impl Application for Onagre<'_> { Command::none() } } + Message::Click(row_idx) => { + match self.state.get_active_mode() { + ActiveMode::History => self.state.selected = Selection::History(row_idx), + _ => self.state.selected = Selection::PopLauncher(row_idx), + } + + self.on_execute() + } } } diff --git a/src/app/style/rows/button.rs b/src/app/style/rows/button.rs new file mode 100644 index 0000000..74de716 --- /dev/null +++ b/src/app/style/rows/button.rs @@ -0,0 +1,38 @@ +use iced_core::{Color, Vector}; +use iced_style::button::{Appearance, StyleSheet}; + +// Button is just used as a wrapper to get access to the click event. +// For now all theming option is disabled, we might want to make +// on hovered theming options available in the config later. +pub struct ButtonStyle; + +impl StyleSheet for &ButtonStyle { + type Style = iced::Theme; + + fn active(&self, _: &Self::Style) -> Appearance { + no_style() + } + + fn hovered(&self, _: &Self::Style) -> Appearance { + no_style() + } + + fn pressed(&self, _: &Self::Style) -> Appearance { + no_style() + } + + fn disabled(&self, _: &Self::Style) -> Appearance { + no_style() + } +} + +fn no_style() -> Appearance { + Appearance { + shadow_offset: Vector { x: 0.0, y: 0.0 }, + background: None, + border_radius: 0.0.into(), + border_width: 0.0, + border_color: Color::TRANSPARENT, + text_color: Color::BLACK, + } +} diff --git a/src/app/style/rows/generic.rs b/src/app/style/rows/generic.rs index 31948b2..58a1125 100644 --- a/src/app/style/rows/generic.rs +++ b/src/app/style/rows/generic.rs @@ -34,6 +34,7 @@ impl Scale for GenericContainerStyle { self } } + impl Default for GenericContainerStyle { fn default() -> Self { GenericContainerStyle { diff --git a/src/app/style/rows/mod.rs b/src/app/style/rows/mod.rs index 0c50fe1..7f001b7 100644 --- a/src/app/style/rows/mod.rs +++ b/src/app/style/rows/mod.rs @@ -9,6 +9,7 @@ use iced_core::BorderRadius; use iced_style::container::{Appearance, StyleSheet}; use icon::IconStyle; +pub mod button; pub mod generic; pub mod icon;