Fix applet window styling (#652)
* fix(applet windows): fix styling * update libcosmic Updates context drawers to use the new API.
This commit is contained in:
parent
b4b5e78abe
commit
1f19fe7015
11 changed files with 174 additions and 168 deletions
162
src/app.rs
162
src/app.rs
|
|
@ -13,7 +13,7 @@ use cosmic::iced::{
|
|||
Limits,
|
||||
};
|
||||
use cosmic::{
|
||||
app::{self, message, Core, Task},
|
||||
app::{self, context_drawer, message, Core, Task},
|
||||
cosmic_config, cosmic_theme, executor,
|
||||
iced::{
|
||||
clipboard::dnd::DndAction,
|
||||
|
|
@ -21,7 +21,6 @@ use cosmic::{
|
|||
futures::{self, SinkExt},
|
||||
keyboard::{Event as KeyEvent, Key, Modifiers},
|
||||
stream,
|
||||
widget::scrollable,
|
||||
window::{self, Event as WindowEvent, Id as WindowId},
|
||||
Alignment, Event, Length, Size, Subscription,
|
||||
},
|
||||
|
|
@ -372,18 +371,6 @@ pub enum ContextPage {
|
|||
Settings,
|
||||
}
|
||||
|
||||
impl ContextPage {
|
||||
pub fn title(&self) -> String {
|
||||
match self {
|
||||
Self::About => String::new(),
|
||||
Self::EditHistory => fl!("edit-history"),
|
||||
Self::NetworkDrive => fl!("add-network-drive"),
|
||||
Self::Preview(..) => String::default(),
|
||||
Self::Settings => fl!("settings"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
|
||||
pub enum ArchiveType {
|
||||
Tgz,
|
||||
|
|
@ -1135,16 +1122,6 @@ impl App {
|
|||
let cosmic_theme::Spacing {
|
||||
space_xxs, space_m, ..
|
||||
} = theme::active().cosmic().spacing;
|
||||
let mut text_input =
|
||||
widget::text_input(fl!("enter-server-address"), &self.network_drive_input);
|
||||
let button = if self.network_drive_connecting.is_some() {
|
||||
widget::button::standard(fl!("connecting"))
|
||||
} else {
|
||||
text_input = text_input
|
||||
.on_input(Message::NetworkDriveInput)
|
||||
.on_submit(Message::NetworkDriveSubmit);
|
||||
widget::button::standard(fl!("connect")).on_press(Message::NetworkDriveSubmit)
|
||||
};
|
||||
let mut table = widget::column::with_capacity(8);
|
||||
for (i, line) in fl!("network-drive-schemes").lines().enumerate() {
|
||||
let mut row = widget::row::with_capacity(2);
|
||||
|
|
@ -1165,17 +1142,15 @@ impl App {
|
|||
}
|
||||
}
|
||||
widget::column::with_children(vec![
|
||||
text_input.into(),
|
||||
widget::text(fl!("network-drive-description")).into(),
|
||||
table.into(),
|
||||
widget::row::with_children(vec![widget::horizontal_space().into(), button.into()])
|
||||
.into(),
|
||||
])
|
||||
.spacing(space_m)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn desktop_view_options(&self) -> Element<Message> {
|
||||
let cosmic_theme::Spacing { space_l, .. } = theme::active().cosmic().spacing;
|
||||
let config = self.config.desktop;
|
||||
|
||||
let mut children = Vec::new();
|
||||
|
|
@ -1238,7 +1213,9 @@ impl App {
|
|||
children.push(section.into());
|
||||
*/
|
||||
|
||||
widget::column::with_children(children).into()
|
||||
widget::column::with_children(children)
|
||||
.padding([0, space_l, space_l, space_l])
|
||||
.into()
|
||||
}
|
||||
|
||||
fn edit_history(&self) -> Element<Message> {
|
||||
|
|
@ -1333,19 +1310,20 @@ impl App {
|
|||
kind: &'a PreviewKind,
|
||||
context_drawer: bool,
|
||||
) -> Element<'a, Message> {
|
||||
let cosmic_theme::Spacing { space_l, .. } = theme::active().cosmic().spacing;
|
||||
|
||||
let mut children = Vec::with_capacity(1);
|
||||
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
|
||||
match kind {
|
||||
PreviewKind::Custom(PreviewItem(item)) => {
|
||||
children.push(item.preview_view(IconSizes::default(), context_drawer));
|
||||
children.push(item.preview_view(IconSizes::default()));
|
||||
}
|
||||
PreviewKind::Location(location) => {
|
||||
if let Some(tab) = self.tab_model.data::<Tab>(entity) {
|
||||
if let Some(items) = tab.items_opt() {
|
||||
for item in items.iter() {
|
||||
if item.location_opt.as_ref() == Some(location) {
|
||||
children
|
||||
.push(item.preview_view(tab.config.icon_sizes, context_drawer));
|
||||
children.push(item.preview_view(tab.config.icon_sizes));
|
||||
// Only show one property view to avoid issues like hangs when generating
|
||||
// preview images on thousands of files
|
||||
break;
|
||||
|
|
@ -1359,8 +1337,7 @@ impl App {
|
|||
if let Some(items) = tab.items_opt() {
|
||||
for item in items.iter() {
|
||||
if item.selected {
|
||||
children
|
||||
.push(item.preview_view(tab.config.icon_sizes, context_drawer));
|
||||
children.push(item.preview_view(tab.config.icon_sizes));
|
||||
// Only show one property view to avoid issues like hangs when generating
|
||||
// preview images on thousands of files
|
||||
break;
|
||||
|
|
@ -1368,15 +1345,20 @@ impl App {
|
|||
}
|
||||
if children.is_empty() {
|
||||
if let Some(item) = &tab.parent_item_opt {
|
||||
children
|
||||
.push(item.preview_view(tab.config.icon_sizes, context_drawer));
|
||||
children.push(item.preview_view(tab.config.icon_sizes));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
widget::column::with_children(children).into()
|
||||
widget::column::with_children(children)
|
||||
.padding(if context_drawer {
|
||||
[0, 0, 0, 0]
|
||||
} else {
|
||||
[0, space_l, space_l, space_l]
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
||||
fn settings(&self) -> Element<Message> {
|
||||
|
|
@ -2745,7 +2727,6 @@ impl Application for App {
|
|||
tab::Command::AddNetworkDrive => {
|
||||
self.context_page = ContextPage::NetworkDrive;
|
||||
self.set_show_context(true);
|
||||
self.set_context_title(self.context_page.title());
|
||||
}
|
||||
tab::Command::AddToSidebar(path) => {
|
||||
let mut favorites = self.config.favorites.clone();
|
||||
|
|
@ -2813,7 +2794,6 @@ impl Application for App {
|
|||
tab::Command::Preview(kind) => {
|
||||
self.context_page = ContextPage::Preview(Some(entity), kind);
|
||||
self.set_show_context(true);
|
||||
self.set_context_title(self.context_page.title());
|
||||
}
|
||||
tab::Command::WindowDrag => {
|
||||
if let Some(window_id) = &self.window_id_opt {
|
||||
|
|
@ -2868,7 +2848,6 @@ impl Application for App {
|
|||
self.set_show_context(true);
|
||||
}
|
||||
self.context_page = context_page;
|
||||
self.set_context_title(self.context_page.title());
|
||||
}
|
||||
Message::Undo(_id) => {
|
||||
// TODO: undo
|
||||
|
|
@ -3204,7 +3183,6 @@ impl Application for App {
|
|||
PreviewKind::Custom(PreviewItem(item)),
|
||||
);
|
||||
self.set_show_context(true);
|
||||
self.set_context_title(self.context_page.title());
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!("failed to get item from path {:?}: {}", path, err);
|
||||
|
|
@ -3323,17 +3301,69 @@ impl Application for App {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn context_drawer(&self) -> Option<Element<Message>> {
|
||||
fn context_drawer(&self) -> Option<context_drawer::ContextDrawer<Message>> {
|
||||
if !self.core.window.show_context {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(match &self.context_page {
|
||||
ContextPage::About => self.about(),
|
||||
ContextPage::EditHistory => self.edit_history(),
|
||||
ContextPage::NetworkDrive => self.network_drive(),
|
||||
ContextPage::Preview(entity_opt, kind) => self.preview(entity_opt, kind, true),
|
||||
ContextPage::Settings => self.settings(),
|
||||
ContextPage::About => context_drawer::context_drawer(
|
||||
self.about(),
|
||||
Message::ToggleContextPage(ContextPage::About),
|
||||
),
|
||||
ContextPage::EditHistory => context_drawer::context_drawer(
|
||||
self.edit_history(),
|
||||
Message::ToggleContextPage(ContextPage::EditHistory),
|
||||
)
|
||||
.title(fl!("edit-history")),
|
||||
ContextPage::NetworkDrive => {
|
||||
let mut text_input =
|
||||
widget::text_input(fl!("enter-server-address"), &self.network_drive_input);
|
||||
let button = if self.network_drive_connecting.is_some() {
|
||||
widget::button::standard(fl!("connecting"))
|
||||
} else {
|
||||
text_input = text_input
|
||||
.on_input(Message::NetworkDriveInput)
|
||||
.on_submit(Message::NetworkDriveSubmit);
|
||||
widget::button::standard(fl!("connect")).on_press(Message::NetworkDriveSubmit)
|
||||
};
|
||||
context_drawer::context_drawer(
|
||||
self.network_drive(),
|
||||
Message::ToggleContextPage(ContextPage::NetworkDrive),
|
||||
)
|
||||
.title(fl!("add-network-drive"))
|
||||
.header(text_input)
|
||||
.footer(widget::row::with_children(vec![
|
||||
widget::horizontal_space().into(),
|
||||
button.into(),
|
||||
]))
|
||||
}
|
||||
ContextPage::Preview(entity_opt, kind) => {
|
||||
let mut actions = Vec::with_capacity(3);
|
||||
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
|
||||
if let Some(tab) = self.tab_model.data::<Tab>(entity) {
|
||||
if let Some(items) = tab.items_opt() {
|
||||
for item in items.iter() {
|
||||
if item.selected {
|
||||
actions.extend(item.preview_header())
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
context_drawer::context_drawer(
|
||||
self.preview(entity_opt, kind, true),
|
||||
Message::ToggleContextPage(ContextPage::Preview(
|
||||
entity_opt.clone(),
|
||||
kind.clone(),
|
||||
)),
|
||||
)
|
||||
.header_actions(actions)
|
||||
}
|
||||
ContextPage::Settings => context_drawer::context_drawer(
|
||||
self.settings(),
|
||||
Message::ToggleContextPage(ContextPage::Settings),
|
||||
)
|
||||
.title(fl!("settings")),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -3885,10 +3915,7 @@ impl Application for App {
|
|||
}
|
||||
|
||||
let cosmic_theme::Spacing {
|
||||
space_xxs,
|
||||
space_xs,
|
||||
space_s,
|
||||
..
|
||||
space_xs, space_s, ..
|
||||
} = theme::active().cosmic().spacing;
|
||||
|
||||
let mut title = String::new();
|
||||
|
|
@ -3993,7 +4020,7 @@ impl Application for App {
|
|||
.align_y(Alignment::Center)
|
||||
.into(),
|
||||
]))
|
||||
.padding([space_xxs, space_xs])
|
||||
.padding([8, space_xs])
|
||||
.layer(cosmic_theme::Layer::Primary);
|
||||
|
||||
Some(container.into())
|
||||
|
|
@ -4146,34 +4173,11 @@ impl Application for App {
|
|||
}
|
||||
};
|
||||
|
||||
//TODO: these are hacks to have a sane scroll bar
|
||||
let cosmic_theme::Spacing { space_l, .. } = theme::active().cosmic().spacing;
|
||||
let scrollbar_width = 8;
|
||||
let scrollbar_margin = 8;
|
||||
widget::container(
|
||||
widget::scrollable(widget::row::with_children(vec![
|
||||
content,
|
||||
widget::Space::with_width(Length::Fixed(
|
||||
(scrollbar_width + scrollbar_margin).into(),
|
||||
))
|
||||
.into(),
|
||||
]))
|
||||
.direction(scrollable::Direction::Vertical(
|
||||
scrollable::Scrollbar::new()
|
||||
.width(scrollbar_width)
|
||||
.scroller_width(scrollbar_width),
|
||||
)),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.padding([
|
||||
0,
|
||||
space_l - (scrollbar_width + scrollbar_margin),
|
||||
space_l,
|
||||
space_l,
|
||||
])
|
||||
.class(theme::Container::WindowBackground)
|
||||
.into()
|
||||
widget::container(widget::scrollable(content))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.class(theme::Container::WindowBackground)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Self::Message> {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use cosmic::{
|
||||
app::{self, cosmic::Cosmic, message, Core, Task},
|
||||
app::{self, context_drawer, cosmic::Cosmic, message, Core, Task},
|
||||
cosmic_config, cosmic_theme, executor,
|
||||
iced::{
|
||||
event,
|
||||
|
|
@ -461,7 +461,7 @@ impl App {
|
|||
|
||||
widget::layer_container(col)
|
||||
.layer(cosmic_theme::Layer::Primary)
|
||||
.padding([space_xxs, space_xs])
|
||||
.padding([8, space_xs])
|
||||
.into()
|
||||
}
|
||||
|
||||
|
|
@ -469,13 +469,13 @@ impl App {
|
|||
let mut children = Vec::with_capacity(1);
|
||||
match kind {
|
||||
PreviewKind::Custom(PreviewItem(item)) => {
|
||||
children.push(item.preview_view(IconSizes::default(), true));
|
||||
children.push(item.preview_view(IconSizes::default()));
|
||||
}
|
||||
PreviewKind::Location(location) => {
|
||||
if let Some(items) = self.tab.items_opt() {
|
||||
for item in items.iter() {
|
||||
if item.location_opt.as_ref() == Some(location) {
|
||||
children.push(item.preview_view(self.tab.config.icon_sizes, true));
|
||||
children.push(item.preview_view(self.tab.config.icon_sizes));
|
||||
// Only show one property view to avoid issues like hangs when generating
|
||||
// preview images on thousands of files
|
||||
break;
|
||||
|
|
@ -487,7 +487,7 @@ impl App {
|
|||
if let Some(items) = self.tab.items_opt() {
|
||||
for item in items.iter() {
|
||||
if item.selected {
|
||||
children.push(item.preview_view(self.tab.config.icon_sizes, true));
|
||||
children.push(item.preview_view(self.tab.config.icon_sizes));
|
||||
// Only show one property view to avoid issues like hangs when generating
|
||||
// preview images on thousands of files
|
||||
break;
|
||||
|
|
@ -495,7 +495,7 @@ impl App {
|
|||
}
|
||||
if children.is_empty() {
|
||||
if let Some(item) = &self.tab.parent_item_opt {
|
||||
children.push(item.preview_view(self.tab.config.icon_sizes, true));
|
||||
children.push(item.preview_view(self.tab.config.icon_sizes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -794,13 +794,33 @@ impl Application for App {
|
|||
(app, commands)
|
||||
}
|
||||
|
||||
fn context_drawer(&self) -> Option<Element<Message>> {
|
||||
fn context_drawer(&self) -> Option<context_drawer::ContextDrawer<Message>> {
|
||||
if !self.core.window.show_context {
|
||||
return None;
|
||||
}
|
||||
|
||||
match &self.context_page {
|
||||
ContextPage::Preview(_, kind) => Some(self.preview(kind).map(Message::from)),
|
||||
ContextPage::Preview(_, kind) => {
|
||||
let mut actions = Vec::with_capacity(3);
|
||||
if let Some(items) = self.tab.items_opt() {
|
||||
for item in items.iter() {
|
||||
if item.selected {
|
||||
actions.extend(
|
||||
item.preview_header().into_iter().map(|element| {
|
||||
element.map(move |message| Message::from(message))
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
Some(
|
||||
context_drawer::context_drawer(
|
||||
self.preview(kind).map(Message::from),
|
||||
Message::Preview,
|
||||
)
|
||||
.header_actions(actions),
|
||||
)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -1401,7 +1421,6 @@ impl Application for App {
|
|||
tab::Command::Preview(kind) => {
|
||||
self.context_page = ContextPage::Preview(None, kind);
|
||||
self.set_show_context(true);
|
||||
self.set_context_title(self.context_page.title());
|
||||
}
|
||||
tab::Command::WindowDrag => {
|
||||
commands.push(window::drag(self.flags.window_id));
|
||||
|
|
|
|||
53
src/tab.rs
53
src/tab.rs
|
|
@ -1374,42 +1374,39 @@ impl Item {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn preview_view<'a>(
|
||||
&'a self,
|
||||
sizes: IconSizes,
|
||||
nav_row: bool,
|
||||
) -> Element<'a, app::Message> {
|
||||
pub fn preview_header(&self) -> Vec<Element<app::Message>> {
|
||||
let mut row = Vec::with_capacity(3);
|
||||
row.push(
|
||||
widget::button::icon(widget::icon::from_name("go-previous-symbolic"))
|
||||
.on_press(app::Message::TabMessage(None, Message::ItemLeft))
|
||||
.into(),
|
||||
);
|
||||
row.push(
|
||||
widget::button::icon(widget::icon::from_name("go-next-symbolic"))
|
||||
.on_press(app::Message::TabMessage(None, Message::ItemRight))
|
||||
.into(),
|
||||
);
|
||||
if self.can_gallery() {
|
||||
if let Some(_path) = self.path_opt() {
|
||||
row.push(
|
||||
widget::button::icon(widget::icon::from_name("view-fullscreen-symbolic"))
|
||||
.on_press(app::Message::TabMessage(None, Message::Gallery(true)))
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
row
|
||||
}
|
||||
|
||||
pub fn preview_view<'a>(&'a self, sizes: IconSizes) -> Element<'a, app::Message> {
|
||||
let cosmic_theme::Spacing {
|
||||
space_xxxs,
|
||||
space_xxs,
|
||||
space_m,
|
||||
..
|
||||
} = theme::active().cosmic().spacing;
|
||||
|
||||
let mut column = widget::column().spacing(space_m);
|
||||
|
||||
if nav_row {
|
||||
let mut row = widget::row::with_capacity(3).spacing(space_xxs);
|
||||
row = row.push(
|
||||
widget::button::icon(widget::icon::from_name("go-previous-symbolic"))
|
||||
.on_press(app::Message::TabMessage(None, Message::ItemLeft)),
|
||||
);
|
||||
row = row.push(
|
||||
widget::button::icon(widget::icon::from_name("go-next-symbolic"))
|
||||
.on_press(app::Message::TabMessage(None, Message::ItemRight)),
|
||||
);
|
||||
|
||||
if self.can_gallery() {
|
||||
if let Some(_path) = self.path_opt() {
|
||||
row = row.push(
|
||||
widget::button::icon(widget::icon::from_name("view-fullscreen-symbolic"))
|
||||
.on_press(app::Message::TabMessage(None, Message::Gallery(true))),
|
||||
);
|
||||
}
|
||||
}
|
||||
column = column.push(row);
|
||||
}
|
||||
|
||||
column = column.push(widget::row::with_children(vec![
|
||||
widget::horizontal_space().into(),
|
||||
self.preview(sizes),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue