feat(widget): progress bars

This commit is contained in:
Ashley Wulber 2026-04-07 11:02:58 -04:00 committed by GitHub
parent 724351727a
commit b963fbfea9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 935 additions and 8 deletions

View file

@ -82,6 +82,7 @@ pub enum Message {
Hi,
Hi2,
Hi3,
Tick,
}
/// The [`App`] stores application-specific state.
@ -92,6 +93,7 @@ pub struct App {
input_2: String,
hidden: bool,
keybinds: HashMap<KeyBind, Action>,
progress: f32,
}
/// Implement [`cosmic::Application`] to integrate with COSMIC.
@ -133,6 +135,7 @@ impl cosmic::Application for App {
input_2: String::new(),
hidden: true,
keybinds: HashMap::new(),
progress: 0.0,
};
let command = app.update_title();
@ -178,10 +181,17 @@ impl cosmic::Application for App {
Message::Hi3 => {
dbg!("hi 3");
}
Message::Tick => {
self.progress = (self.progress + 0.01) % 1.0;
}
}
Task::none()
}
fn subscription(&self) -> iced::Subscription<Self::Message> {
iced::time::every(std::time::Duration::from_millis(64)).map(|_| Message::Tick)
}
/// Creates a view after each update.
fn view(&self) -> Element<'_, Self::Message> {
let page_content = self
@ -212,6 +222,46 @@ impl cosmic::Application for App {
.on_input(Message::Input2)
.on_clear(Message::Ignore),
)
.push(widget::progress_bar::circular::Circular::new().size(50.0))
.push(
widget::progress_bar::linear::Linear::new()
.girth(10.0)
.width(Length::Fill),
)
.push(
widget::progress_bar::circular::Circular::new()
.bar_height(10.0)
.size(50.0)
.progress(self.progress),
)
.push(
widget::progress_bar::linear::Linear::new()
.girth(10.0)
.progress(self.progress)
.width(Length::Fill),
)
.push(
widget::progress_bar::circular::Circular::new()
.size(50.0)
.progress(0.0),
)
.push(
widget::progress_bar::linear::Linear::new()
.girth(10.0)
.progress(0.0)
.width(Length::Fill),
)
.push(
widget::progress_bar::circular::Circular::new()
.size(50.0)
.progress(1.0),
)
.push(
widget::progress_bar::linear::Linear::new()
.girth(10.0)
.progress(1.0)
.width(Length::Fill),
)
.spacing(cosmic::theme::spacing().space_s)
.width(Length::Fill)
.height(Length::Shrink)