/* Copyright 2024, Savanni D'Gerinel This file is part of FitnessTrax. FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see . */ use crate::{components::TextEntry, types::ParseError}; use gtk::prelude::*; #[derive(Default)] pub struct Steps { label: gtk::Label, } impl Steps { pub fn new(steps: Option) -> Self { let label = gtk::Label::builder() .css_classes(["card", "step-view"]) .can_focus(true) .build(); match steps { Some(s) => label.set_text(&format!("{}", s)), None => label.set_text("No steps recorded"), } Self { label } } pub fn widget(&self) -> gtk::Widget { self.label.clone().upcast() } } pub fn steps_editor(value: Option, on_update: OnUpdate) -> TextEntry where OnUpdate: Fn(Option) + 'static, { TextEntry::new( "0", value, |v| format!("{}", v), move |v| v.parse::().map_err(|_| ParseError), on_update, ) }