Merge pull request #945 from derezzedex/menu

feat: add menus
This commit is contained in:
Héctor Ramón 2021-07-20 21:44:33 +07:00 committed by GitHub
commit 8e29709b69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 749 additions and 75 deletions

View file

@ -61,8 +61,8 @@ mod debug;
mod debug;
pub use iced_core::{
Align, Background, Color, Font, HorizontalAlignment, Length, Padding,
Point, Rectangle, Size, Vector, VerticalAlignment,
menu, Align, Background, Color, Font, HorizontalAlignment, Length, Menu,
Padding, Point, Rectangle, Size, Vector, VerticalAlignment,
};
pub use iced_futures::{executor, futures, Command};

View file

@ -11,7 +11,7 @@ pub trait Program: Sized {
type Renderer: Renderer;
/// The type of __messages__ your [`Program`] will produce.
type Message: std::fmt::Debug + Send;
type Message: std::fmt::Debug + Clone + Send;
/// The type of [`Clipboard`] your [`Program`] will use.
type Clipboard: Clipboard;

View file

@ -362,7 +362,7 @@ where
Event::Keyboard(keyboard::Event::CharacterReceived(c))
if self.state.is_focused
&& self.state.is_pasting.is_none()
&& !self.state.keyboard_modifiers.is_command_pressed()
&& !self.state.keyboard_modifiers.command()
&& !c.is_control() =>
{
let mut editor =
@ -450,7 +450,7 @@ where
if platform::is_jump_modifier_pressed(modifiers)
&& !self.is_secure
{
if modifiers.shift {
if modifiers.shift() {
self.state
.cursor
.select_left_by_words(&self.value);
@ -459,7 +459,7 @@ where
.cursor
.move_left_by_words(&self.value);
}
} else if modifiers.shift {
} else if modifiers.shift() {
self.state.cursor.select_left(&self.value)
} else {
self.state.cursor.move_left(&self.value);
@ -469,7 +469,7 @@ where
if platform::is_jump_modifier_pressed(modifiers)
&& !self.is_secure
{
if modifiers.shift {
if modifiers.shift() {
self.state
.cursor
.select_right_by_words(&self.value);
@ -478,14 +478,14 @@ where
.cursor
.move_right_by_words(&self.value);
}
} else if modifiers.shift {
} else if modifiers.shift() {
self.state.cursor.select_right(&self.value)
} else {
self.state.cursor.move_right(&self.value);
}
}
keyboard::KeyCode::Home => {
if modifiers.shift {
if modifiers.shift() {
self.state.cursor.select_range(
self.state.cursor.start(&self.value),
0,
@ -495,7 +495,7 @@ where
}
}
keyboard::KeyCode::End => {
if modifiers.shift {
if modifiers.shift() {
self.state.cursor.select_range(
self.state.cursor.start(&self.value),
self.value.len(),
@ -505,10 +505,7 @@ where
}
}
keyboard::KeyCode::C
if self
.state
.keyboard_modifiers
.is_command_pressed() =>
if self.state.keyboard_modifiers.command() =>
{
match self.state.cursor.selection(&self.value) {
Some((start, end)) => {
@ -520,10 +517,7 @@ where
}
}
keyboard::KeyCode::X
if self
.state
.keyboard_modifiers
.is_command_pressed() =>
if self.state.keyboard_modifiers.command() =>
{
match self.state.cursor.selection(&self.value) {
Some((start, end)) => {
@ -545,7 +539,7 @@ where
messages.push(message);
}
keyboard::KeyCode::V => {
if self.state.keyboard_modifiers.is_command_pressed() {
if self.state.keyboard_modifiers.command() {
let content = match self.state.is_pasting.take() {
Some(content) => content,
None => {
@ -576,10 +570,7 @@ where
}
}
keyboard::KeyCode::A
if self
.state
.keyboard_modifiers
.is_command_pressed() =>
if self.state.keyboard_modifiers.command() =>
{
self.state.cursor.select_all(&self.value);
}
@ -858,9 +849,9 @@ mod platform {
pub fn is_jump_modifier_pressed(modifiers: keyboard::Modifiers) -> bool {
if cfg!(target_os = "macos") {
modifiers.alt
modifiers.alt()
} else {
modifiers.control
modifiers.control()
}
}
}