Skip to content

Commit

Permalink
Use keybind directly in editor example
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jan 29, 2025
1 parent 5f3ae6b commit 337d209
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions examples/editor/src/main.rs
Original file line number Diff line number Diff line change
@@ -146,18 +146,25 @@ impl Editor {

fn view(&self) -> Element<Message> {
let controls = row![
action(new_icon(), "New file", 'n', Some(Message::NewFile)),
action(
open_icon(),
"Open file",
keybind(
'n',
action(new_icon(), "New file", Some(Message::NewFile))
),
keybind(
'o',
(!self.is_loading).then_some(Message::OpenFile)
action(
open_icon(),
"Open file",
(!self.is_loading).then_some(Message::OpenFile)
)
),
action(
save_icon(),
"Save file",
keybind(
's',
self.is_dirty.then_some(Message::SaveFile),
action(
save_icon(),
"Save file",
self.is_dirty.then_some(Message::SaveFile),
)
),
horizontal_space(),
toggler(self.word_wrap)
@@ -284,14 +291,13 @@ async fn save_file(
fn action<'a, Message: Clone + 'a>(
content: impl Into<Element<'a, Message>>,
label: &'a str,
hotkey: impl Into<Hotkey>,
on_press: Option<Message>,
) -> Element<'a, Message> {
let action = button(center_x(content).width(30));

if let Some(on_press) = on_press {
tooltip(
keybind(hotkey, action.on_press(on_press)),
action.on_press(on_press),
label,
tooltip::Position::FollowCursor,
)

0 comments on commit 337d209

Please sign in to comment.