chore(doc): add documentation for a handful of widgets
This commit is contained in:
parent
0d4c3db162
commit
f4936344f0
15 changed files with 113 additions and 10 deletions
|
|
@ -13,12 +13,14 @@ use std::borrow::Cow;
|
|||
|
||||
pub type Button<'a, Message> = Builder<'a, Message, Icon>;
|
||||
|
||||
/// The icon variant of a button.
|
||||
pub struct Icon {
|
||||
handle: Handle,
|
||||
vertical: bool,
|
||||
selected: bool,
|
||||
}
|
||||
|
||||
/// A button constructed from an icon handle, using icon button styling.
|
||||
pub fn icon<'a, Message>(handle: impl Into<Handle>) -> Button<'a, Message> {
|
||||
Button::new(Icon {
|
||||
handle: handle.into(),
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use std::borrow::Cow;
|
|||
|
||||
pub type Button<'a, Message> = Builder<'a, Message, Image<'a, Handle, Message>>;
|
||||
|
||||
/// A button constructed from an image handle, using image button styling.
|
||||
pub fn image<'a, Message>(handle: impl Into<Handle> + 'a) -> Button<'a, Message> {
|
||||
Button::new(Image {
|
||||
image: widget::image(handle).border_radius([9.0; 4]),
|
||||
|
|
@ -19,6 +20,7 @@ pub fn image<'a, Message>(handle: impl Into<Handle> + 'a) -> Button<'a, Message>
|
|||
})
|
||||
}
|
||||
|
||||
/// The image variant of a button.
|
||||
pub struct Image<'a, Handle, Message> {
|
||||
image: widget::Image<'a, Handle>,
|
||||
selected: bool,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
//! Hyperlink button widget
|
||||
|
||||
use super::Builder;
|
||||
use super::Style;
|
||||
use crate::prelude::*;
|
||||
|
|
@ -17,6 +19,7 @@ pub struct Hyperlink {
|
|||
trailing_icon: bool,
|
||||
}
|
||||
|
||||
/// A hyperlink button.
|
||||
pub fn link<'a, Message>(label: impl Into<Cow<'a, str>> + 'static) -> Button<'a, Message> {
|
||||
Button::new(
|
||||
label,
|
||||
|
|
|
|||
|
|
@ -1,29 +1,41 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
//! Button widgets for COSMIC applications.
|
||||
|
||||
pub use crate::theme::Button as Style;
|
||||
|
||||
pub mod link;
|
||||
use derive_setters::Setters;
|
||||
#[doc(inline)]
|
||||
pub use link::link;
|
||||
#[doc(inline)]
|
||||
pub use link::Button as LinkButton;
|
||||
|
||||
mod icon;
|
||||
#[doc(inline)]
|
||||
pub use icon::icon;
|
||||
#[doc(inline)]
|
||||
pub use icon::Button as IconButton;
|
||||
|
||||
mod image;
|
||||
#[doc(inline)]
|
||||
pub use image::image;
|
||||
#[doc(inline)]
|
||||
pub use image::Button as ImageButton;
|
||||
|
||||
mod style;
|
||||
#[doc(inline)]
|
||||
pub use style::{Appearance, StyleSheet};
|
||||
|
||||
mod text;
|
||||
#[doc(inline)]
|
||||
pub use text::Button as TextButton;
|
||||
#[doc(inline)]
|
||||
pub use text::{destructive, standard, suggested, text};
|
||||
|
||||
mod widget;
|
||||
#[doc(inline)]
|
||||
pub use widget::{draw, focus, layout, mouse_interaction, Button};
|
||||
|
||||
use iced_core::font::Weight;
|
||||
|
|
@ -31,10 +43,12 @@ use iced_core::widget::Id;
|
|||
use iced_core::{Length, Padding};
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// A button with the default style, which may contain any widget as its content.
|
||||
pub fn button<'a, Message>(content: impl Into<crate::Element<'a, Message>>) -> Button<'a, Message> {
|
||||
Button::new(content)
|
||||
}
|
||||
|
||||
/// An image button which may contain any widget as its content.
|
||||
pub fn custom_image_button<'a, Message>(
|
||||
content: impl Into<crate::Element<'a, Message>>,
|
||||
on_remove: Option<Message>,
|
||||
|
|
@ -42,6 +56,7 @@ pub fn custom_image_button<'a, Message>(
|
|||
Button::new_image(content, on_remove)
|
||||
}
|
||||
|
||||
/// A builder for constructing a custom [`Button`].
|
||||
#[must_use]
|
||||
#[derive(Setters)]
|
||||
pub struct Builder<'a, Message, Variant> {
|
||||
|
|
|
|||
|
|
@ -10,26 +10,31 @@ use std::borrow::Cow;
|
|||
|
||||
pub type Button<'a, Message> = Builder<'a, Message, Text>;
|
||||
|
||||
/// A text button with the destructive style
|
||||
pub fn destructive<'a, Message>(label: impl Into<Cow<'a, str>>) -> Button<'a, Message> {
|
||||
Button::new(Text::new())
|
||||
.label(label)
|
||||
.style(Style::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)
|
||||
}
|
||||
|
||||
/// A text button with the standard style
|
||||
pub fn standard<'a, Message>(label: impl Into<Cow<'a, str>>) -> Button<'a, Message> {
|
||||
Button::new(Text::new()).label(label)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
||||
/// The text variant of a button.
|
||||
pub struct Text {
|
||||
pub(super) leading_icon: Option<icon::Handle>,
|
||||
pub(super) trailing_icon: Option<icon::Handle>,
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ pub struct Button<'a, Message> {
|
|||
|
||||
impl<'a, Message> Button<'a, Message> {
|
||||
/// Creates a new [`Button`] with the given content.
|
||||
pub fn new(content: impl Into<crate::Element<'a, Message>>) -> Self {
|
||||
pub(super) fn new(content: impl Into<crate::Element<'a, Message>>) -> Self {
|
||||
Self {
|
||||
id: Id::unique(),
|
||||
#[cfg(feature = "a11y")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue