feat: Tooltips and Better Surface Management
This commit is contained in:
parent
c7edd37b03
commit
337b80d4ca
90 changed files with 3651 additions and 977 deletions
|
|
@ -29,7 +29,7 @@ pub fn icon<'a, Message>(handle: impl Into<Handle>) -> Button<'a, Message> {
|
|||
})
|
||||
}
|
||||
|
||||
impl<'a, Message> Button<'a, Message> {
|
||||
impl<Message> Button<'_, Message> {
|
||||
pub fn new(icon: Icon) -> Self {
|
||||
let guard = crate::theme::THEME.lock().unwrap();
|
||||
let theme = guard.cosmic();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::{Builder, Style};
|
||||
use super::Builder;
|
||||
use crate::{
|
||||
widget::{self, image::Handle},
|
||||
Element,
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ pub struct Builder<'a, Message, Variant> {
|
|||
variant: Variant,
|
||||
}
|
||||
|
||||
impl<'a, Message, Variant> Builder<'a, Message, Variant> {
|
||||
impl<Message, Variant> Builder<'_, Message, Variant> {
|
||||
/// Set the value of [`on_press`] as either `Some` or `None`.
|
||||
pub fn on_press_maybe(mut self, on_press: Option<Message>) -> Self {
|
||||
self.on_press = on_press;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::{Builder, ButtonClass, Style};
|
||||
use super::{Builder, ButtonClass};
|
||||
use crate::widget::{icon, row, tooltip};
|
||||
use crate::{ext::CollectionWidget, Element};
|
||||
use apply::Apply;
|
||||
|
|
@ -42,6 +42,12 @@ pub struct Text {
|
|||
pub(super) trailing_icon: Option<icon::Handle>,
|
||||
}
|
||||
|
||||
impl Default for Text {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Text {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
|
|
@ -51,7 +57,7 @@ impl Text {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, Message> Button<'a, Message> {
|
||||
impl<Message> Button<'_, Message> {
|
||||
pub fn new(text: Text) -> Self {
|
||||
let guard = crate::theme::THEME.lock().unwrap();
|
||||
let theme = guard.cosmic();
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ pub struct Button<'a, Message> {
|
|||
selected: bool,
|
||||
style: crate::theme::Button,
|
||||
variant: Variant<Message>,
|
||||
force_enabled: bool,
|
||||
}
|
||||
|
||||
impl<'a, Message> Button<'a, Message> {
|
||||
|
|
@ -77,6 +78,7 @@ impl<'a, Message> Button<'a, Message> {
|
|||
selected: false,
|
||||
style: crate::theme::Button::default(),
|
||||
variant: Variant::Normal,
|
||||
force_enabled: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,6 +92,7 @@ impl<'a, Message> Button<'a, Message> {
|
|||
name: None,
|
||||
#[cfg(feature = "a11y")]
|
||||
description: None,
|
||||
force_enabled: false,
|
||||
#[cfg(feature = "a11y")]
|
||||
label: None,
|
||||
content: content.into(),
|
||||
|
|
@ -163,6 +166,12 @@ impl<'a, Message> Button<'a, Message> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the the [`Button`] to enabled whether or not it has handlers for on press.
|
||||
pub fn force_enabled(mut self, enabled: bool) -> Self {
|
||||
self.force_enabled = enabled;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the widget to a selected state.
|
||||
///
|
||||
/// Displays a selection indicator on image buttons.
|
||||
|
|
@ -348,7 +357,8 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
|||
|
||||
let mut headerbar_alpha = None;
|
||||
|
||||
let is_enabled = self.on_press.is_some() || self.on_press_down.is_some();
|
||||
let is_enabled =
|
||||
self.on_press.is_some() || self.on_press_down.is_some() || self.force_enabled;
|
||||
let is_mouse_over = cursor.position().is_some_and(|p| bounds.contains(p));
|
||||
|
||||
let state = tree.state.downcast_ref::<State>();
|
||||
|
|
@ -583,12 +593,7 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
|||
}
|
||||
match self.description.as_ref() {
|
||||
Some(iced_accessibility::Description::Id(id)) => {
|
||||
node.set_described_by(
|
||||
id.iter()
|
||||
.cloned()
|
||||
.map(|id| NodeId::from(id))
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
node.set_described_by(id.iter().cloned().map(NodeId::from).collect::<Vec<_>>());
|
||||
}
|
||||
Some(iced_accessibility::Description::Text(text)) => {
|
||||
node.set_description(text.clone());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue