Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl ContextMenu #139

Merged
merged 13 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,23 @@
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'context_menu'",
"cargo": {
"args": [
"build",
"--bin=context_menu",
"--package=context_menu"
],
"filter": {
"name": "context_menu",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
]
}
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ split = []
menu = []
quad = []
spinner = []
context_menu = []

default = [
"badge",
Expand All @@ -52,6 +53,7 @@ default = [
"split",
"menu",
"quad",
"context_menu"
]

[dependencies]
Expand Down Expand Up @@ -101,7 +103,8 @@ members = [
"examples/split",
"examples/split_scroller",
"examples/menu",
"examples/spinner"
"examples/spinner",
"examples/context_menu"
]

[workspace.dependencies.iced]
Expand Down
13 changes: 13 additions & 0 deletions examples/context_menu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "context_menu"
version = "0.1.0"
authors = ["wiiznokes <[email protected]>"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
iced_aw = { workspace = true, features = [
"context_menu",
] }
iced.workspace = true
81 changes: 81 additions & 0 deletions examples/context_menu/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use iced::{
widget::{column, Button, Container, Row, Text},
Alignment, Element, Sandbox, Settings,
};

use iced_aw::ContextMenu;

fn main() -> iced::Result {
ContextMenuExample::run(Settings::default())
}

#[derive(Clone, Debug)]
pub enum Message {
ButtonClicked,
Choice1,
Choice2,
Choice3,
Choice4,
}

#[derive(Default)]
struct ContextMenuExample {
last_message: Option<Message>,
}

impl Sandbox for ContextMenuExample {
type Message = Message;

fn new() -> Self {
Self::default()
}

fn title(&self) -> String {
String::from("ContextMenu example")
}

fn update(&mut self, message: Self::Message) {
self.last_message = Some(message);
}

fn view(&self) -> Element<'_, Self::Message> {
let underlay = Container::new(
Row::new()
.spacing(10)
.align_items(Alignment::Center)
.push(Button::new(Text::new("right click me!")).on_press(Message::ButtonClicked))
.push(Text::new(format!(
"Last message: {}",
match self.last_message.as_ref() {
Some(message) => match message {
Message::ButtonClicked => "button clicked",
Message::Choice1 => "choice 1",
Message::Choice2 => "choice 2",
Message::Choice3 => "choice 3",
Message::Choice4 => "choice 4",
},
None => "None",
}
))),
);

ContextMenu::new(underlay, || {
column(vec![
iced::widget::button("Choice 1")
.on_press(Message::Choice1)
.into(),
iced::widget::button("Choice 2")
.on_press(Message::Choice2)
.into(),
iced::widget::button("Choice 3")
.on_press(Message::Choice3)
.into(),
iced::widget::button("Choice 4")
.on_press(Message::Choice4)
.into(),
])
.into()
})
.into()
}
}
2 changes: 1 addition & 1 deletion examples/floating_element/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use iced::{
Element, Length, Sandbox, Settings, Theme,
};

use iced_aw::floating_element::{Anchor};
use iced_aw::floating_element::Anchor;
use iced_aw::{helpers::floating_element, Icon, ICON_FONT};

fn main() -> iced::Result {
Expand Down
3 changes: 2 additions & 1 deletion examples/grid/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ impl Sandbox for GridExample {
let mut grid = grid!(
Text::new("Column 1").style(theme::Text::Color(Color::from_rgb8(255, 0, 0))),
Text::new("Column 2").style(theme::Text::Color(Color::from_rgb8(255, 0, 0))),
).strategy(iced_aw::Strategy::Columns(2));
)
.strategy(iced_aw::Strategy::Columns(2));

// Add elements to the grid
for i in 0..self.element_index {
Expand Down
2 changes: 1 addition & 1 deletion examples/number_input/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use iced::{
widget::{Container, Row, Text},
window, Alignment, Element, Length, Sandbox, Settings,
};
use iced_aw::{number_input, style::NumberInputStyles};
use iced_aw::{number_input, style::NumberInputStyles};

#[derive(Default)]
pub struct NumberInputDemo {
Expand Down
2 changes: 1 addition & 1 deletion examples/tab_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Sandbox for TabBarExample {
Message::TabSelected(index) => {
println!("Tab selected: {}", index);
self.active_tab = index
},
}
Message::TabClosed(index) => {
self.tabs.remove(index);
println!("active tab before: {}", self.active_tab);
Expand Down
24 changes: 20 additions & 4 deletions examples/tabs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,26 @@ impl Sandbox for TabBarExample {
.unwrap_or_default();

Tabs::new(Message::TabSelected)
.push(TabId::Login, self.login_tab.tab_label(), self.login_tab.view())
.push(TabId::Ferris, self.ferris_tab.tab_label(), self.ferris_tab.view())
.push(TabId::Counter, self.counter_tab.tab_label(), self.counter_tab.view())
.push(TabId::Settings, self.settings_tab.tab_label(), self.settings_tab.view())
.push(
TabId::Login,
self.login_tab.tab_label(),
self.login_tab.view(),
)
.push(
TabId::Ferris,
self.ferris_tab.tab_label(),
self.ferris_tab.view(),
)
.push(
TabId::Counter,
self.counter_tab.tab_label(),
self.counter_tab.view(),
)
.push(
TabId::Settings,
self.settings_tab.tab_label(),
self.settings_tab.view(),
)
.set_active_tab(&self.active_tab)
.tab_bar_style(theme)
.icon_font(ICON_FONT)
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ mod platform {
#[doc(no_inline)]
#[cfg(feature = "spinner")]
pub use {crate::native::spinner, crate::style::SpinnerStyle, spinner::Spinner};

#[doc(no_inline)]
#[cfg(feature = "context_menu")]
pub use {
crate::native::context_menu, crate::style::ContextMenuStyle, context_menu::ContextMenu,
};
}

#[doc(no_inline)]
Expand Down
Loading