chore: update iced/libcosmic
This commit is contained in:
parent
0d0b89d538
commit
7de52054ff
12 changed files with 502 additions and 549 deletions
|
|
@ -5,11 +5,7 @@ use cosmic::{
|
|||
alignment, event,
|
||||
layout::{Layout, Limits, Node},
|
||||
mouse, overlay, renderer,
|
||||
widget::{
|
||||
operation::{Operation, OperationOutputWrapper},
|
||||
tree::Tree,
|
||||
Id, Widget,
|
||||
},
|
||||
widget::{operation::Operation, tree::Tree, Id, Widget},
|
||||
Border, Clipboard, Color, Length, Rectangle, Shell, Size,
|
||||
},
|
||||
iced_widget::scrollable::AbsoluteOffset,
|
||||
|
|
@ -54,19 +50,19 @@ pub(super) enum TabRuleTheme {
|
|||
impl From<TabRuleTheme> for theme::Rule {
|
||||
fn from(theme: TabRuleTheme) -> Self {
|
||||
match theme {
|
||||
TabRuleTheme::ActiveActivated => Self::custom(|theme| widget::rule::Appearance {
|
||||
TabRuleTheme::ActiveActivated => Self::custom(|theme| widget::rule::Style {
|
||||
color: theme.cosmic().accent_color().into(),
|
||||
width: 4,
|
||||
radius: 0.0.into(),
|
||||
fill_mode: FillMode::Full,
|
||||
}),
|
||||
TabRuleTheme::ActiveDeactivated => Self::custom(|theme| widget::rule::Appearance {
|
||||
TabRuleTheme::ActiveDeactivated => Self::custom(|theme| widget::rule::Style {
|
||||
color: theme.cosmic().palette.neutral_5.into(),
|
||||
width: 4,
|
||||
radius: 0.0.into(),
|
||||
fill_mode: FillMode::Full,
|
||||
}),
|
||||
TabRuleTheme::Default => Self::custom(|theme| widget::rule::Appearance {
|
||||
TabRuleTheme::Default => Self::custom(|theme| widget::rule::Style {
|
||||
color: theme.cosmic().palette.neutral_5.into(),
|
||||
width: 4,
|
||||
radius: 8.0.into(),
|
||||
|
|
@ -96,11 +92,11 @@ impl TabBackgroundTheme {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<TabBackgroundTheme> for theme::Container {
|
||||
impl From<TabBackgroundTheme> for theme::Container<'_> {
|
||||
fn from(background_theme: TabBackgroundTheme) -> Self {
|
||||
match background_theme {
|
||||
TabBackgroundTheme::ActiveActivated => {
|
||||
Self::custom(move |theme| widget::container::Appearance {
|
||||
Self::custom(move |theme| widget::container::Style {
|
||||
icon_color: Some(Color::from(theme.cosmic().accent_text_color())),
|
||||
text_color: Some(Color::from(theme.cosmic().accent_text_color())),
|
||||
background: Some(background_theme.background_color(theme).into()),
|
||||
|
|
@ -113,7 +109,7 @@ impl From<TabBackgroundTheme> for theme::Container {
|
|||
})
|
||||
}
|
||||
TabBackgroundTheme::ActiveDeactivated => {
|
||||
Self::custom(move |theme| widget::container::Appearance {
|
||||
Self::custom(move |theme| widget::container::Style {
|
||||
icon_color: None,
|
||||
text_color: None,
|
||||
background: Some(background_theme.background_color(theme).into()),
|
||||
|
|
@ -215,20 +211,19 @@ impl<Message: TabMessage + 'static> Tab<Message> {
|
|||
.icon()
|
||||
.apply(widget::button)
|
||||
.padding(0)
|
||||
.style(theme::iced::Button::Text);
|
||||
.class(theme::iced::Button::Text);
|
||||
if let Some(close_message) = self.close_message {
|
||||
close_button = close_button.on_press(close_message);
|
||||
}
|
||||
|
||||
let items = vec![
|
||||
widget::vertical_rule(4).style(self.rule_theme).into(),
|
||||
widget::vertical_rule(4).class(self.rule_theme).into(),
|
||||
self.app_icon
|
||||
.clone()
|
||||
.apply(widget::container)
|
||||
.height(Length::Fill)
|
||||
.width(Length::Shrink)
|
||||
.padding([2, 4])
|
||||
.center_y()
|
||||
.center_y(Length::Fill)
|
||||
.into(),
|
||||
tab_text(self.title, self.active)
|
||||
.font(self.font)
|
||||
|
|
@ -238,10 +233,9 @@ impl<Message: TabMessage + 'static> Tab<Message> {
|
|||
.into(),
|
||||
close_button
|
||||
.apply(widget::container)
|
||||
.height(Length::Fill)
|
||||
.width(Length::Shrink)
|
||||
.padding([2, 4])
|
||||
.center_y()
|
||||
.center_y(Length::Fill)
|
||||
.align_x(alignment::Horizontal::Right)
|
||||
.into(),
|
||||
];
|
||||
|
|
@ -269,7 +263,7 @@ pub(super) struct TabInternal<'a, Message: TabMessage> {
|
|||
id: Id,
|
||||
idx: usize,
|
||||
active: bool,
|
||||
background: theme::Container,
|
||||
background: theme::Container<'a>,
|
||||
elements: Vec<cosmic::Element<'a, Message>>,
|
||||
press_message: Option<Message>,
|
||||
right_click_message: Option<Message>,
|
||||
|
|
@ -347,7 +341,7 @@ where
|
|||
tree: &mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &cosmic::Renderer,
|
||||
operation: &mut dyn Operation<OperationOutputWrapper<Message>>,
|
||||
operation: &mut dyn Operation<()>,
|
||||
) {
|
||||
operation.container(None, layout.bounds(), &mut |operation| {
|
||||
self.elements
|
||||
|
|
@ -454,8 +448,8 @@ where
|
|||
cursor: mouse::Cursor,
|
||||
viewport: &Rectangle,
|
||||
) {
|
||||
use cosmic::widget::container::StyleSheet;
|
||||
let style = theme.appearance(&self.background);
|
||||
use cosmic::widget::container::Catalog;
|
||||
let style = theme.style(&self.background);
|
||||
|
||||
draw_background(renderer, &style, layout.bounds());
|
||||
|
||||
|
|
@ -486,7 +480,8 @@ where
|
|||
tree: &'b mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &cosmic::Renderer,
|
||||
translation: cosmic::iced::Vector,
|
||||
) -> Option<overlay::Element<'b, Message, cosmic::Theme, cosmic::Renderer>> {
|
||||
overlay::from_children(&mut self.elements, tree, layout, renderer)
|
||||
overlay::from_children(&mut self.elements, tree, layout, renderer, translation)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ impl TabText {
|
|||
vertical_alignment: alignment::Vertical::Center,
|
||||
shaping: Shaping::Advanced,
|
||||
line_height: LineHeight::default(),
|
||||
wrap: cosmic::iced::advanced::text::Wrap::None,
|
||||
wrapping: cosmic::iced::advanced::text::Wrapping::None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use cosmic::{
|
|||
widget::{
|
||||
operation::{
|
||||
scrollable::{AbsoluteOffset, RelativeOffset},
|
||||
Operation, OperationOutputWrapper, Scrollable,
|
||||
Operation, Scrollable,
|
||||
},
|
||||
tree::{self, Tree},
|
||||
Widget,
|
||||
|
|
@ -16,10 +16,9 @@ use cosmic::{
|
|||
Background, Border, Clipboard, Color, Length, Point, Rectangle, Renderer, Shell, Size,
|
||||
Vector,
|
||||
},
|
||||
iced_style::container::StyleSheet as ContainerStyleSheet,
|
||||
iced_widget::container::draw_background,
|
||||
theme,
|
||||
widget::icon::from_name,
|
||||
widget::{container::Catalog, icon::from_name},
|
||||
Apply,
|
||||
};
|
||||
use keyframe::{
|
||||
|
|
@ -45,6 +44,7 @@ struct ScrollAnimationState {
|
|||
start_time: Instant,
|
||||
start: Offset,
|
||||
end: Offset,
|
||||
extra: Offset,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -75,9 +75,24 @@ impl Scrollable for State {
|
|||
start_time: Instant::now(),
|
||||
start: self.offset_x,
|
||||
end: new_offset,
|
||||
extra: Offset::Absolute(0.),
|
||||
});
|
||||
self.offset_x = new_offset;
|
||||
}
|
||||
|
||||
fn scroll_by(
|
||||
&mut self,
|
||||
offset: AbsoluteOffset,
|
||||
_bounds: Rectangle,
|
||||
_content_bounds: Rectangle,
|
||||
) {
|
||||
self.scroll_animation = Some(ScrollAnimationState {
|
||||
start_time: Instant::now(),
|
||||
start: self.offset_x,
|
||||
end: self.offset_x,
|
||||
extra: Offset::Absolute(offset.x.max(0.0)),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
|
|
@ -145,7 +160,7 @@ where
|
|||
Element::new(tab.internal(i))
|
||||
});
|
||||
|
||||
let tabs_rule = widget::vertical_rule(4).style(if tabs.len() - 1 == active {
|
||||
let tabs_rule = widget::vertical_rule(4).class(if tabs.len() - 1 == active {
|
||||
if activated {
|
||||
TabRuleTheme::ActiveActivated
|
||||
} else {
|
||||
|
|
@ -166,7 +181,7 @@ where
|
|||
.prefer_svg(true)
|
||||
.icon()
|
||||
.apply(widget::button)
|
||||
.style(theme::iced::Button::Text)
|
||||
.class(theme::iced::Button::Text)
|
||||
.on_press(Message::scroll_back());
|
||||
|
||||
let next_button = from_name("go-next-symbolic")
|
||||
|
|
@ -174,17 +189,17 @@ where
|
|||
.prefer_svg(true)
|
||||
.icon()
|
||||
.apply(widget::button)
|
||||
.style(theme::iced::Button::Text)
|
||||
.class(theme::iced::Button::Text)
|
||||
.on_press(Message::scroll_further());
|
||||
|
||||
let mut elements = Vec::with_capacity(tabs.len() + 5);
|
||||
|
||||
elements.push(widget::vertical_rule(4).style(rule_style).into());
|
||||
elements.push(widget::vertical_rule(4).class(rule_style).into());
|
||||
elements.push(prev_button.into());
|
||||
elements.extend(tabs);
|
||||
elements.push(tabs_rule.into());
|
||||
elements.push(next_button.into());
|
||||
elements.push(widget::vertical_rule(4).style(rule_style).into());
|
||||
elements.push(widget::vertical_rule(4).class(rule_style).into());
|
||||
|
||||
Tabs {
|
||||
elements,
|
||||
|
|
@ -239,6 +254,7 @@ impl State {
|
|||
|
||||
Vector::new(
|
||||
animation.start.absolute(bounds.width, content_bounds.width)
|
||||
+ animation.extra.absolute(bounds.width, content_bounds.width) * percentage
|
||||
+ (animation.end.absolute(bounds.width, content_bounds.width)
|
||||
- animation.start.absolute(bounds.width, content_bounds.width))
|
||||
* percentage,
|
||||
|
|
@ -490,9 +506,9 @@ where
|
|||
height: b.bounds().height,
|
||||
});
|
||||
|
||||
let background_style = ContainerStyleSheet::appearance(
|
||||
let background_style = Catalog::style(
|
||||
theme,
|
||||
&theme::Container::custom(|theme| widget::container::Appearance {
|
||||
&theme::Container::custom(|theme| widget::container::Style {
|
||||
icon_color: None,
|
||||
text_color: None,
|
||||
background: Some(Background::Color(super::tab::primary_container_color(
|
||||
|
|
@ -666,10 +682,12 @@ where
|
|||
tree: &mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &cosmic::Renderer,
|
||||
operation: &mut dyn Operation<OperationOutputWrapper<Message>>,
|
||||
operation: &mut dyn Operation<()>,
|
||||
) {
|
||||
let state = tree.state.downcast_mut::<State>();
|
||||
let bounds = layout.bounds();
|
||||
let content_layout = layout.children().next().unwrap();
|
||||
let content_bounds = content_layout.bounds();
|
||||
|
||||
state.cleanup_old_animations();
|
||||
|
||||
|
|
@ -677,6 +695,7 @@ where
|
|||
state,
|
||||
self.id.as_ref(),
|
||||
bounds,
|
||||
content_bounds,
|
||||
Vector { x: 0.0, y: 0.0 }, /* seemingly unused */
|
||||
);
|
||||
|
||||
|
|
@ -819,6 +838,7 @@ where
|
|||
start_time: Instant::now(),
|
||||
start: Offset::Absolute(offset.x),
|
||||
end: Offset::Absolute(new_offset.x),
|
||||
extra: Offset::Absolute(0.),
|
||||
});
|
||||
state.offset_x = Offset::Absolute(new_offset.x);
|
||||
}
|
||||
|
|
@ -993,7 +1013,8 @@ where
|
|||
tree: &'b mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &cosmic::Renderer,
|
||||
translation: cosmic::iced::Vector,
|
||||
) -> Option<overlay::Element<'b, Message, cosmic::Theme, cosmic::Renderer>> {
|
||||
overlay::from_children(&mut self.elements, tree, layout, renderer)
|
||||
overlay::from_children(&mut self.elements, tree, layout, renderer, translation)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue