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:
parent
e30668ca8e
commit
fe5e4ed044
|
@ -87,7 +87,7 @@ impl AppWindow {
|
||||||
let initial_view = View::Placeholder(PlaceholderView::new().upcast());
|
let initial_view = View::Placeholder(PlaceholderView::new().upcast());
|
||||||
|
|
||||||
layout.append(&header);
|
layout.append(&header);
|
||||||
layout.append(initial_view.widget());
|
layout.append(&initial_view.widget());
|
||||||
|
|
||||||
window.set_content(Some(&layout));
|
window.set_content(Some(&layout));
|
||||||
window.present();
|
window.present();
|
||||||
|
@ -130,9 +130,9 @@ impl AppWindow {
|
||||||
// position.
|
// position.
|
||||||
fn swap_main(&self, view: View) {
|
fn swap_main(&self, view: View) {
|
||||||
let mut current_widget = self.current_view.borrow_mut();
|
let mut current_widget = self.current_view.borrow_mut();
|
||||||
self.layout.remove(&*current_widget.widget());
|
self.layout.remove(¤t_widget.widget());
|
||||||
*current_widget = view;
|
*current_widget = view;
|
||||||
self.layout.append(&*current_widget.widget());
|
self.layout.append(¤t_widget.widget());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn construct_view(&self, view: ViewName) -> View {
|
fn construct_view(&self, view: ViewName) -> View {
|
||||||
|
|
|
@ -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/>.
|
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;
|
mod historical_view;
|
||||||
pub use historical_view::HistoricalView;
|
pub use historical_view::HistoricalView;
|
||||||
|
|
||||||
|
@ -30,17 +32,17 @@ pub enum ViewName {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum View {
|
pub enum View {
|
||||||
Placeholder(gtk::Widget),
|
Placeholder(PlaceholderView),
|
||||||
Welcome(gtk::Widget),
|
Welcome(WelcomeView),
|
||||||
Historical(gtk::Widget),
|
Historical(HistoricalView),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl View {
|
impl View {
|
||||||
pub fn widget<'a>(&'a self) -> &'a gtk::Widget {
|
pub fn widget(&self) -> gtk::Widget {
|
||||||
match self {
|
match self {
|
||||||
View::Placeholder(widget) => widget,
|
View::Placeholder(widget) => widget.clone().upcast::<gtk::Widget>(),
|
||||||
View::Welcome(widget) => widget,
|
View::Welcome(widget) => widget.clone().upcast::<gtk::Widget>(),
|
||||||
View::Historical(widget) => widget,
|
View::Historical(widget) => widget.clone().upcast::<gtk::Widget>(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue