Skip to content

Commit

Permalink
command palatte has results
Browse files Browse the repository at this point in the history
  • Loading branch information
LegitCamper committed Sep 21, 2024
1 parent 9c1964a commit 57b4030
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 44 deletions.
46 changes: 41 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ ultralight = ["ul-next"]
[dependencies]
env_home = "0.1.0"
iced = { version = "0.13", features = ["advanced", "image", "tokio", "lazy"] }
iced_aw = { version = "0.10", features = ["tab_bar", "icons"] }
iced_aw = { version = "0.10", features = [
"tab_bar",
"icons",
"selection_list",
] }
iced_on_focus_widget = "0.1.1"
rand = "0.8.5"
reqwest = "0.12.5"
serde = "1.0.207"
serde_json = "1.0.124"
smol_str = "0.2.2"
strum = { version = "0.26.3", features = ["derive"] }
strum_macros = "0.26.4"
tempfile = "3.12.0"
ul-next = { version = "0.4", optional = true }
url = "2.5.2"
2 changes: 1 addition & 1 deletion examples/keyboard_driven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Browser {
Message::Update => self.widgets.force_update().map(Message::BrowserWidget),
Message::Event(event) => self
.widgets
.update(widgets::Message::Event(event))
.update(widgets::Message::Event(Some(event)))
.map(Message::BrowserWidget),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/browser_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ where

match event {
Event::Keyboard(event) => {
shell.publish(Message::SendKeyboardEvent(event));
shell.publish(Message::SendKeyboardEvent(Some(event)));
}
Event::Mouse(event) => {
if let Some(point) = cursor.position_in(layout.bounds()) {
shell.publish(Message::SendMouseEvent(point, event));
shell.publish(Message::SendMouseEvent(point, Some(event)));
}
}
_ => (),
Expand Down
34 changes: 31 additions & 3 deletions src/widgets/command_window.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
use iced::widget::{center, column, container, mouse_area, opaque, stack, text_input};
use iced::{border, Color, Element, Theme};
use iced::{border, Color, Element, Font, Length, Theme};
use iced_aw::SelectionList;
use strum::IntoEnumIterator;

use super::Message;

pub struct CommandWindowState {
pub query: String,
actions: Vec<String>,
pub selected_action: String,
pub selected_index: usize,
}

impl CommandWindowState {
pub fn new() -> Self {
Self {
query: String::new(),
actions: Message::iter().map(|e| e.clone().to_string()).collect(),
selected_action: String::new(),
selected_index: 0,
}
}
}

pub fn command_window<'a>(
base: impl Into<Element<'a, Message>>,
query: &str,
state: &'a CommandWindowState,
) -> Element<'a, Message> {
let window = container(column![
text_input("Command Menu", query).on_input(Message::QueryChanged),
text_input("Command Menu", &state.query).on_input(Message::QueryChanged),
SelectionList::new(&state.actions, Message::CommandSelectionChanged)
.width(Length::Fill)
.height(Length::Fill)
.style(|theme: &Theme, _| iced_aw::style::selection_list::Style {
text_color: theme.palette().text.into(),
background: theme.palette().background.into(),
..Default::default()
}),
])
.padding(10)
.center(600)
Expand Down
Loading

0 comments on commit 57b4030

Please sign in to comment.