feat: progress bars

much of the code is adapted from the iced example
This commit is contained in:
Ashley Wulber 2026-04-06 20:01:05 -04:00
parent 9aa87cd66b
commit 6a48eae8e0
6 changed files with 820 additions and 3 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,45 @@ 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()
.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)