From a584fb4de374dcedaebac22fa0fa4b3927b9aad9 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sat, 19 Aug 2023 23:45:19 -0400 Subject: [PATCH] Get the scrollbar to expand with the window --- kifu/gtk/src/main.rs | 4 ++-- kifu/gtk/src/ui/home.rs | 37 ++++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/kifu/gtk/src/main.rs b/kifu/gtk/src/main.rs index 95cda24..499acf0 100644 --- a/kifu/gtk/src/main.rs +++ b/kifu/gtk/src/main.rs @@ -13,8 +13,8 @@ fn handle_response(api: CoreApi, window: gtk::ApplicationWindow, message: CoreRe CoreResponse::HomeView(view) => perftrace("HomeView", || { let api = api.clone(); - let new_game = Home::new(api, view); - window.set_child(Some(&new_game)); + let home = Home::new(api, view); + window.set_child(Some(&home)); }), CoreResponse::PlayingFieldView(view) => perftrace("PlayingFieldView", || { let api = api.clone(); diff --git a/kifu/gtk/src/ui/home.rs b/kifu/gtk/src/ui/home.rs index 533821b..3777454 100644 --- a/kifu/gtk/src/ui/home.rs +++ b/kifu/gtk/src/ui/home.rs @@ -1,14 +1,11 @@ -use crate::{ui::GamePreview, CoreApi}; -use glib::{Object, Properties}; +use crate::CoreApi; +use glib::Object; use gtk::{glib, prelude::*, subclass::prelude::*}; use kifu_core::{ - ui::{GamePreviewElement, HomeView, PlayerElement}, + ui::{HomeView, PlayerElement}, CoreRequest, CreateGameRequest, HotseatPlayerRequest, PlayerInfoRequest, }; -use std::{ - cell::{Cell, RefCell}, - rc::Rc, -}; +use std::{cell::RefCell, rc::Rc}; use super::GameDatabase; @@ -105,39 +102,49 @@ impl Default for HomePrivate { impl ObjectSubclass for HomePrivate { const NAME: &'static str = "Home"; type Type = Home; - type ParentType = gtk::Grid; + type ParentType = gtk::Box; } impl ObjectImpl for HomePrivate {} impl WidgetImpl for HomePrivate {} -impl GridImpl for HomePrivate {} +impl BoxImpl for HomePrivate {} glib::wrapper! { - pub struct Home(ObjectSubclass) @extends gtk::Grid, gtk::Widget; + pub struct Home(ObjectSubclass) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable; } impl Home { pub fn new(api: CoreApi, view: HomeView) -> Home { let s: Self = Object::builder().build(); + s.set_spacing(4); + s.set_homogeneous(false); + s.set_orientation(gtk::Orientation::Vertical); + + let players = gtk::Box::builder() + .spacing(4) + .orientation(gtk::Orientation::Horizontal) + .build(); + s.append(&players); let black_player = PlayerDataEntry::new(view.black_player); - s.attach(&black_player, 1, 1, 1, 1); + players.append(&black_player); *s.imp().black_player.borrow_mut() = Some(black_player.clone()); - let white_player = PlayerDataEntry::new(view.white_player); - s.attach(&white_player, 2, 1, 1, 1); + players.append(&white_player); *s.imp().white_player.borrow_mut() = Some(white_player.clone()); let new_game_button = gtk::Button::builder().label(&view.start_game.label).build(); - s.attach(&new_game_button, 2, 2, 1, 1); + s.append(&new_game_button); let library = GameDatabase::new(); let library_view = gtk::ScrolledWindow::builder() .hscrollbar_policy(gtk::PolicyType::Never) .min_content_width(360) + .vexpand(true) + .hexpand(true) .child(&library) .build(); - s.attach(&library_view, 0, 3, 4, 2); + s.append(&library_view); library.set_games(view.games);