Skip to content
Draft
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
19 changes: 10 additions & 9 deletions examples/application/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ env_logger = "0.11"
[dependencies.libcosmic]
path = "../../"
features = [
"debug",
"winit",
"tokio",
"xdg-portal",
"a11y",
"single-instance",
"surface-message",
"multi-window",
"wgpu",
"debug",
"winit",
"tokio",
"xdg-portal",
"a11y",
"single-instance",
"surface-message",
"multi-window",
"wgpu",
"wayland",
]
40 changes: 39 additions & 1 deletion examples/application/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use cosmic::iced::{Alignment, Length, Size};
use cosmic::prelude::*;
use cosmic::widget::menu::{self, KeyBind};
use cosmic::widget::nav_bar;
use cosmic::widget::text_editor::{self, Content};
use cosmic::{executor, iced, widget, Core};
use std::collections::HashMap;
use std::sync::LazyLock;
Expand Down Expand Up @@ -84,6 +85,7 @@ pub enum Message {
Hi2,
Hi3,
Tick,
EditorAction(text_editor::Action),
}

/// The [`App`] stores application-specific state.
Expand All @@ -95,6 +97,7 @@ pub struct App {
hidden: bool,
keybinds: HashMap<KeyBind, Action>,
progress: f32,
editor_content: text_editor::Content,
}

/// Implement [`cosmic::Application`] to integrate with COSMIC.
Expand Down Expand Up @@ -137,6 +140,9 @@ impl cosmic::Application for App {
hidden: true,
keybinds: HashMap::new(),
progress: 0.0,
editor_content: text_editor::Content::with_text(
"This is a text editor.\nTry right-clicking for a context menu.\n\nمتن فارسی در ادیتور",
),
};

let command = app.update_title();
Expand Down Expand Up @@ -185,6 +191,9 @@ impl cosmic::Application for App {
Message::Tick => {
self.progress = (self.progress + 0.01) % 1.0;
}
Message::EditorAction(action) => {
self.editor_content.perform(action);
}
}
Task::none()
}
Expand All @@ -201,8 +210,37 @@ impl cosmic::Application for App {
.map_or("No page selected", String::as_str);

let centered = widget::container(
widget::column::with_capacity(14)
widget::column::with_capacity(20)
.push(widget::text::body(page_content))
.push(widget::text::title4("Selectable Title").selectable())
.push(
widget::text::body(
"This text is selectable. Try clicking and dragging to select, \
double-click to select a word, or triple-click to select all. \
Press Ctrl+C to copy, or right-click for a context menu.",
)
.selectable(),
)
.push(
widget::text::caption("Selectable caption text. No right-click context menu.")
.selectable()
.context_menu(false),
)
.push(
widget::text::body("متن فارسی برای تست انتخاب متن از راست به چپ").selectable(),
)
.push(
widget::text::body(
"Mixed text: Hello سلام World دنیا! Some English and فارسی together.",
)
.selectable(),
)
.push(
text_editor::text_editor(&self.editor_content)
.placeholder("Text editor...")
.on_action(Message::EditorAction)
.height(Length::Fixed(120.0)),
)
.push(
widget::text_input::text_input("", &self.input_1)
.on_input(Message::Input1)
Expand Down
2 changes: 1 addition & 1 deletion examples/text-input/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ tracing-log = "0.2.0"

[dependencies.libcosmic]
path = "../../"
features = ["debug", "winit", "wgpu", "tokio", "xdg-portal"]
features = ["debug", "winit", "wgpu", "tokio", "xdg-portal", "wayland"]
17 changes: 13 additions & 4 deletions src/app/cosmic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ where
}
}) {
let settings = settings();

self.get_popup(settings, Box::new(move |_| view()))
} else {
iced_winit::commands::popup::get_popup(settings())
Expand Down Expand Up @@ -375,7 +374,7 @@ where
&mut self,
message: crate::Action<T::Message>,
) -> iced::Task<crate::Action<T::Message>> {
let message = match message {
let mut task = match message {
crate::Action::App(message) => self.app.update(message),
crate::Action::Cosmic(message) => self.cosmic_update(message),
crate::Action::None => iced::Task::none(),
Expand All @@ -395,7 +394,7 @@ where
#[cfg(all(target_env = "gnu", not(target_os = "windows")))]
crate::malloc::trim(0);

message
task
}

#[cfg(not(feature = "multi-window"))]
Expand Down Expand Up @@ -572,9 +571,14 @@ where
#[cfg(feature = "multi-window")]
pub fn view(&self, id: window::Id) -> Element<'_, crate::Action<T::Message>> {
#[cfg(all(feature = "wayland", target_os = "linux"))]
if let Some((_, _, v)) = self.surface_views.get(&id) {
if let Some((_parent, _surface_id, v)) = self.surface_views.get(&id) {
return v(&self.app);
}
#[cfg(feature = "wayland")]
if let Some(element) = crate::widget::text_context_menu::popup_view_for_id::<T::Message>(id)
{
return element;
}
if self
.app
.core()
Expand All @@ -584,6 +588,8 @@ where
return self.app.view_window(id).map(crate::Action::App);
}

crate::widget::text_context_menu::set_current_window_id(id);

let view = if self.app.core().window.use_template {
self.app.view_main()
} else {
Expand All @@ -598,6 +604,9 @@ where

#[cfg(not(feature = "multi-window"))]
pub fn view(&self) -> Element<crate::Action<T::Message>> {
if let Some(id) = self.app.core().main_window_id() {
crate::widget::text_context_menu::set_current_window_id(id);
}
let view = self.app.view_main();

#[cfg(all(target_env = "gnu", not(target_os = "windows")))]
Expand Down
4 changes: 2 additions & 2 deletions src/applet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Context {
)
}

pub fn applet_tooltip<'a, Message: 'static>(
pub fn applet_tooltip<'a, Message: Clone + 'static>(
&self,
content: impl Into<Element<'a, Message>>,
tooltip: impl Into<Cow<'static, str>>,
Expand Down Expand Up @@ -501,7 +501,7 @@ impl Context {
}
}

pub fn text<'a>(&self, msg: impl Into<Cow<'a, str>>) -> crate::widget::Text<'a, crate::Theme> {
pub fn text<'a>(&self, msg: impl Into<Cow<'a, str>>) -> crate::widget::Text<'a> {
let msg = msg.into();
let t = match self.size {
Size::Hardcoded(_) => crate::widget::text,
Expand Down
7 changes: 4 additions & 3 deletions src/theme/style/iced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,18 +1338,19 @@ impl iced_widget::text::Catalog for Theme {
}

fn style(&self, class: &Self::Class<'_>) -> iced_widget::text::Style {
let selected_fill = self.cosmic().accent.base.into();
match class {
Text::Accent => iced_widget::text::Style {
color: Some(self.cosmic().accent_text_color().into()),
..Default::default()
selected_fill,
},
Text::Default => iced_widget::text::Style {
color: None,
..Default::default()
selected_fill,
},
Text::Color(c) => iced_widget::text::Style {
color: Some(*c),
..Default::default()
selected_fill,
},
Text::Custom(f) => f(self),
}
Expand Down
2 changes: 1 addition & 1 deletion src/widget/menu/menu_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub(super) struct MenuSlice {
#[derive(Debug, Clone)]
/// Menu bounds in overlay space
pub struct MenuBounds {
child_positions: Vec<f32>,
pub(crate) child_positions: Vec<f32>,
child_sizes: Vec<Size>,
children_bounds: Rectangle,
pub parent_bounds: Rectangle,
Expand Down
2 changes: 1 addition & 1 deletion src/widget/menu/menu_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub fn menu_root<'a, Message, Renderer: renderer::Renderer>(
) -> Button<'a, Message>
where
Element<'a, Message, crate::Theme, Renderer>: From<widget::Button<'a, Message>>,
Message: std::clone::Clone + 'a,
Message: std::clone::Clone + 'static,
{
widget::button::custom(widget::text(label))
.padding([4, 12])
Expand Down
7 changes: 6 additions & 1 deletion src/widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ pub use iced::widget::{Slider, VerticalSlider, slider, vertical_slider};
#[doc(inline)]
pub use iced::widget::{Svg, svg};

pub mod text_editor;
#[doc(inline)]
pub use iced::widget::{TextEditor, text_editor};
pub use text_editor::TextEditor;

#[doc(inline)]
pub use iced_core::widget::{Id, Operation, Widget};
Expand Down Expand Up @@ -295,6 +296,10 @@ pub mod text;
#[doc(inline)]
pub use text::{Text, text};

pub mod text_context_menu;
#[doc(inline)]
pub use text_context_menu::HasSelectableText;

pub mod text_input;
#[doc(inline)]
pub use text_input::{
Expand Down
8 changes: 4 additions & 4 deletions src/widget/settings/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use taffy::AlignContent;
/// A settings item aligned in a row
#[must_use]
#[allow(clippy::module_name_repetitions)]
pub fn item<'a, Message: 'static>(
pub fn item<'a, Message: Clone + 'static>(
title: impl Into<Cow<'a, str>> + 'a,
widget: impl Into<Element<'a, Message>> + 'a,
) -> Row<'a, Message, Theme> {
#[inline(never)]
fn inner<'a, Message: 'static>(
fn inner<'a, Message: Clone + 'static>(
title: Cow<'a, str>,
widget: Element<'a, Message>,
) -> Row<'a, Message, Theme> {
Expand All @@ -45,12 +45,12 @@ pub fn item_row<Message>(children: Vec<Element<Message>>) -> Row<Message, Theme>

/// A settings item aligned in a flex row
#[allow(clippy::module_name_repetitions)]
pub fn flex_item<'a, Message: 'static>(
pub fn flex_item<'a, Message: Clone + 'static>(
title: impl Into<Cow<'a, str>> + 'a,
widget: impl Into<Element<'a, Message>> + 'a,
) -> FlexRow<'a, Message> {
#[inline(never)]
fn inner<'a, Message: 'static>(
fn inner<'a, Message: Clone + 'static>(
title: Cow<'a, str>,
widget: Element<'a, Message>,
) -> FlexRow<'a, Message> {
Expand Down
Loading
Loading