libcosmic updates

This commit is contained in:
Ashley Wulber 2024-10-16 20:36:46 -04:00 committed by Ashley Wulber
parent 9c62f19e4b
commit 0491c4baaa
91 changed files with 3550 additions and 2300 deletions

View file

@ -1,7 +1,7 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
use super::{Builder, Style};
use super::{Builder, ButtonClass};
use crate::widget::{
icon::{self, Handle},
tooltip,
@ -48,7 +48,7 @@ impl<'a, Message> Button<'a, Message> {
line_height: 20,
font_size: 14,
font_weight: Weight::Normal,
style: Style::Icon,
class: ButtonClass::Icon,
variant: icon,
}
}
@ -121,7 +121,7 @@ impl<'a, Message> Button<'a, Message> {
pub fn vertical(mut self, vertical: bool) -> Self {
self.variant.vertical = vertical;
self.style = Style::IconVertical;
self.class = ButtonClass::IconVertical;
self
}
}
@ -157,7 +157,7 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
crate::widget::column::with_children(content)
.padding(builder.padding)
.spacing(builder.spacing)
.align_items(Alignment::Center)
.align_x(Alignment::Center)
.apply(super::custom)
} else {
crate::widget::row::with_children(content)
@ -165,7 +165,7 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
.width(builder.width)
.height(builder.height)
.spacing(builder.spacing)
.align_items(Alignment::Center)
.align_y(Alignment::Center)
.apply(super::custom)
};
@ -174,18 +174,22 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
.id(builder.id)
.on_press_maybe(builder.on_press)
.selected(builder.variant.selected)
.style(builder.style);
.class(builder.class);
if builder.tooltip.is_empty() {
button.into()
} else {
tooltip(button, builder.tooltip, tooltip::Position::Top)
.size(builder.font_size)
.font(crate::font::Font {
weight: builder.font_weight,
..crate::font::default()
})
.into()
tooltip(
button,
crate::widget::text(builder.tooltip)
.size(builder.font_size)
.font(crate::font::Font {
weight: builder.font_weight,
..crate::font::default()
}),
tooltip::Position::Top,
)
.into()
}
}
}

View file

@ -42,7 +42,7 @@ impl<'a, Message> Button<'a, Message> {
line_height: 20,
font_size: 14,
font_weight: Weight::Normal,
style: Style::Image,
class: crate::theme::style::Button::Image,
variant,
}
}
@ -80,7 +80,7 @@ where
.selected(builder.variant.selected)
.id(builder.id)
.on_press_maybe(builder.on_press)
.style(builder.style)
.class(builder.class)
.into()
}
}

View file

@ -4,7 +4,7 @@
//! Hyperlink button widget
use super::Builder;
use super::Style;
use super::ButtonClass;
use crate::prelude::*;
use crate::widget::icon::{self, Handle};
use crate::widget::{button, row, tooltip};
@ -44,7 +44,7 @@ impl<'a, Message> Button<'a, Message> {
line_height: 20,
font_size: 14,
font_weight: Weight::Normal,
style: Style::Link,
class: ButtonClass::Link,
variant: link,
}
}
@ -81,23 +81,27 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
.width(builder.width)
.height(builder.height)
.spacing(builder.spacing)
.align_items(Alignment::Center)
.align_y(Alignment::Center)
.apply(button::custom)
.padding(0)
.id(builder.id)
.on_press_maybe(builder.on_press.take())
.style(builder.style);
.class(builder.class);
if builder.tooltip.is_empty() {
button.into()
} else {
tooltip(button, builder.tooltip, tooltip::Position::Top)
.size(builder.font_size)
.font(crate::font::Font {
weight: builder.font_weight,
..crate::font::default()
})
.into()
tooltip(
button,
crate::widget::text(builder.tooltip)
.size(builder.font_size)
.font(crate::font::Font {
weight: builder.font_weight,
..crate::font::default()
}),
tooltip::Position::Top,
)
.into()
}
}
}

View file

@ -3,7 +3,7 @@
//! Button widgets for COSMIC applications.
pub use crate::theme::Button as Style;
pub use crate::theme::Button as ButtonClass;
pub mod link;
use derive_setters::Setters;
@ -26,7 +26,7 @@ pub use image::Button as ImageButton;
mod style;
#[doc(inline)]
pub use style::{Appearance, StyleSheet};
pub use style::{Catalog, Style};
mod text;
#[doc(inline)]
@ -105,7 +105,7 @@ pub struct Builder<'a, Message, Variant> {
font_weight: Weight,
/// The preferred style of the button.
style: Style,
class: ButtonClass,
#[setters(skip)]
variant: Variant,

View file

@ -9,7 +9,7 @@ use crate::theme::THEME;
/// The appearance of a button.
#[must_use]
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
pub struct Style {
/// The amount of offset to apply to the shadow of the button.
pub shadow_offset: Vector,
@ -41,7 +41,7 @@ pub struct Appearance {
pub text_color: Option<Color>,
}
impl Appearance {
impl Style {
// TODO: `Radius` is not `const fn` compatible.
pub fn new() -> Self {
let rad_0 = THEME.lock().unwrap().cosmic().corner_radii.radius_0;
@ -60,33 +60,34 @@ impl Appearance {
}
}
impl std::default::Default for Appearance {
impl std::default::Default for Style {
fn default() -> Self {
Self::new()
}
}
// TODO update to match other styles
/// A set of rules that dictate the style of a button.
pub trait StyleSheet {
pub trait Catalog {
/// The supported style of the [`StyleSheet`].
type Style: Default;
type Class: Default;
/// Produces the active [`Appearance`] of a button.
fn active(&self, focused: bool, selected: bool, style: &Self::Style) -> Appearance;
fn active(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
/// Produces the disabled [`Appearance`] of a button.
fn disabled(&self, style: &Self::Style) -> Appearance;
fn disabled(&self, style: &Self::Class) -> Style;
/// [`Appearance`] when the button is the target of a DND operation.
fn drop_target(&self, style: &Self::Style) -> Appearance {
fn drop_target(&self, style: &Self::Class) -> Style {
self.hovered(false, false, style)
}
/// Produces the hovered [`Appearance`] of a button.
fn hovered(&self, focused: bool, selected: bool, style: &Self::Style) -> Appearance;
fn hovered(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
/// Produces the pressed [`Appearance`] of a button.
fn pressed(&self, focused: bool, selected: bool, style: &Self::Style) -> Appearance;
fn pressed(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
/// Background color of the selection indicator
fn selection_background(&self) -> Background;

View file

@ -1,7 +1,7 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
use super::{Builder, Style};
use super::{Builder, ButtonClass, Style};
use crate::widget::{icon, row, tooltip};
use crate::{ext::CollectionWidget, Element};
use apply::Apply;
@ -14,14 +14,14 @@ pub type Button<'a, Message> = Builder<'a, Message, Text>;
pub fn destructive<'a, Message>(label: impl Into<Cow<'a, str>>) -> Button<'a, Message> {
Button::new(Text::new())
.label(label)
.style(Style::Destructive)
.class(ButtonClass::Destructive)
}
/// A text button with the suggested style
pub fn suggested<'a, Message>(label: impl Into<Cow<'a, str>>) -> Button<'a, Message> {
Button::new(Text::new())
.label(label)
.style(Style::Suggested)
.class(ButtonClass::Suggested)
}
/// A text button with the standard style
@ -31,7 +31,9 @@ pub fn standard<'a, Message>(label: impl Into<Cow<'a, str>>) -> Button<'a, Messa
/// A text button with the text style
pub fn text<'a, Message>(label: impl Into<Cow<'a, str>>) -> Button<'a, Message> {
Button::new(Text::new()).label(label).style(Style::Text)
Button::new(Text::new())
.label(label)
.class(ButtonClass::Text)
}
/// The text variant of a button.
@ -66,7 +68,7 @@ impl<'a, Message> Button<'a, Message> {
line_height: 20,
font_size: 14,
font_weight: Weight::Normal,
style: Style::Standard,
class: ButtonClass::Standard,
variant: text,
}
}
@ -125,23 +127,27 @@ impl<'a, Message: Clone + 'static> From<Button<'a, Message>> for Element<'a, Mes
.width(builder.width)
.height(builder.height)
.spacing(builder.spacing)
.align_items(Alignment::Center)
.align_y(Alignment::Center)
.apply(super::custom)
.padding(0)
.id(builder.id)
.on_press_maybe(builder.on_press.take())
.style(builder.style);
.class(builder.class);
if builder.tooltip.is_empty() {
button.into()
} else {
tooltip(button, builder.tooltip, tooltip::Position::Top)
.size(builder.font_size)
.font(crate::font::Font {
weight: builder.font_weight,
..crate::font::default()
})
.into()
tooltip(
button,
crate::widget::text(builder.tooltip)
.size(builder.font_size)
.font(crate::font::Font {
weight: builder.font_weight,
..crate::font::default()
}),
tooltip::Position::Top,
)
.into()
}
}
}

View file

@ -7,7 +7,7 @@
//! A [`Button`] has some local [`State`].
use iced_runtime::core::widget::Id;
use iced_runtime::{keyboard, Command};
use iced_runtime::{keyboard, task, Action, Task};
use iced_core::event::{self, Event};
use iced_core::renderer::{self, Quad, Renderer};
@ -20,11 +20,11 @@ use iced_core::{overlay, Shadow};
use iced_core::{
Background, Clipboard, Color, Layout, Length, Padding, Point, Rectangle, Shell, Vector, Widget,
};
use iced_renderer::core::widget::{operation, OperationOutputWrapper};
use iced_renderer::core::widget::operation;
use crate::theme::THEME;
pub use super::style::{Appearance, StyleSheet};
pub use super::style::{Catalog, Style};
/// Internally defines different button widget variants.
enum Variant<Message> {
@ -173,7 +173,7 @@ impl<'a, Message> Button<'a, Message> {
}
/// Sets the style variant of this [`Button`].
pub fn style(mut self, style: crate::theme::Button) -> Self {
pub fn class(mut self, style: crate::theme::Button) -> Self {
self.style = style;
self
}
@ -257,7 +257,7 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
tree: &mut Tree,
layout: Layout<'_>,
renderer: &crate::Renderer,
operation: &mut dyn Operation<OperationOutputWrapper<Message>>,
operation: &mut dyn Operation<()>,
) {
operation.container(None, layout.bounds(), &mut |operation| {
self.content.as_widget().operate(
@ -470,10 +470,11 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
selection_background,
);
iced_core::svg::Renderer::draw(
let svg_handle = svg::Svg::new(crate::widget::common::object_select().clone())
.color(icon_color);
iced_core::svg::Renderer::draw_svg(
renderer,
crate::widget::common::object_select().clone(),
Some(icon_color),
svg_handle,
Rectangle {
width: 16.0,
height: 16.0,
@ -498,11 +499,10 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
},
selection_background,
);
iced_core::svg::Renderer::draw(
let svg_handle = svg::Svg::new(close_icon.clone()).color(icon_color);
iced_core::svg::Renderer::draw_svg(
renderer,
close_icon.clone(),
Some(icon_color),
svg_handle,
Rectangle {
width: 16.0,
height: 16.0,
@ -533,11 +533,16 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
tree: &'b mut Tree,
layout: Layout<'_>,
renderer: &crate::Renderer,
mut translation: Vector,
) -> Option<overlay::Element<'b, Message, crate::Theme, crate::Renderer>> {
let mut position = layout.bounds().position();
translation.x += position.x;
translation.y += position.y;
self.content.as_widget_mut().overlay(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
translation,
)
}
@ -748,11 +753,11 @@ pub fn update<'a, Message: Clone>(
pub fn draw<Renderer: iced_core::Renderer, Theme>(
renderer: &mut Renderer,
bounds: Rectangle,
styling: &super::style::Appearance,
draw_contents: impl FnOnce(&mut Renderer, &Appearance),
styling: &super::style::Style,
draw_contents: impl FnOnce(&mut Renderer, &Style),
is_image: bool,
) where
Theme: super::style::StyleSheet,
Theme: super::style::Catalog,
{
let doubled_border_width = styling.border_width * 2.0;
let doubled_outline_width = styling.outline_width * 2.0;
@ -909,9 +914,9 @@ pub fn mouse_interaction(
}
}
/// Produces a [`Command`] that focuses the [`Button`] with the given [`Id`].
pub fn focus<Message: 'static>(id: Id) -> Command<Message> {
Command::widget(operation::focusable::focus(id))
/// Produces a [`Task`] that focuses the [`Button`] with the given [`Id`].
pub fn focus<Message: 'static>(id: Id) -> Task<Message> {
task::effect(Action::Widget(Box::new(operation::focusable::focus(id))))
}
impl operation::Focusable for State {