Save the views as their original widgets

This allows me to directly reference functions that occur on those
widgets without losing them behind a gtk::Widget upcast or needing to
later downcast them.
This commit is contained in:
Savanni D'Gerinel 2023-12-28 12:59:29 -05:00
parent e30668ca8e
commit fe5e4ed044
2 changed files with 12 additions and 10 deletions

View File

@ -87,7 +87,7 @@ impl AppWindow {
let initial_view = View::Placeholder(PlaceholderView::new().upcast());
layout.append(&header);
layout.append(initial_view.widget());
layout.append(&initial_view.widget());
window.set_content(Some(&layout));
window.present();
@ -130,9 +130,9 @@ impl AppWindow {
// position.
fn swap_main(&self, view: View) {
let mut current_widget = self.current_view.borrow_mut();
self.layout.remove(&*current_widget.widget());
self.layout.remove(&current_widget.widget());
*current_widget = view;
self.layout.append(&*current_widget.widget());
self.layout.append(&current_widget.widget());
}
fn construct_view(&self, view: ViewName) -> View {

View File

@ -14,6 +14,8 @@ General Public License for more details.
You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
*/
use gtk::prelude::*;
mod historical_view;
pub use historical_view::HistoricalView;
@ -30,17 +32,17 @@ pub enum ViewName {
}
pub enum View {
Placeholder(gtk::Widget),
Welcome(gtk::Widget),
Historical(gtk::Widget),
Placeholder(PlaceholderView),
Welcome(WelcomeView),
Historical(HistoricalView),
}
impl View {
pub fn widget<'a>(&'a self) -> &'a gtk::Widget {
pub fn widget(&self) -> gtk::Widget {
match self {
View::Placeholder(widget) => widget,
View::Welcome(widget) => widget,
View::Historical(widget) => widget,
View::Placeholder(widget) => widget.clone().upcast::<gtk::Widget>(),
View::Welcome(widget) => widget.clone().upcast::<gtk::Widget>(),
View::Historical(widget) => widget.clone().upcast::<gtk::Widget>(),
}
}
}