window: Limit HeaderBar to min width as nat width
Before we were doing the same with just the title in the HeaderBar. This gave problems with correctly measuring for ADW_CENTERING_POLICY_LOOSE.
This commit is contained in:
parent
7ebc902838
commit
446ae5063a
7 changed files with 93 additions and 109 deletions
79
src/widgets/shy_bin.rs
Normal file
79
src/widgets/shy_bin.rs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright (c) 2023 Sophie Herold
|
||||
//
|
||||
// This program 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.
|
||||
//
|
||||
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
//! A bin that only has min width as natural width
|
||||
//!
|
||||
//! This bin does not claim its complete width as natural width. The HeaderBar
|
||||
//! is wrapped in with this widget. This prevents the window from growing based
|
||||
//! on a long file name in the title instead of just fitting to the image
|
||||
//! size.
|
||||
|
||||
use adw::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
|
||||
use crate::deps::*;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct LpShyBin {}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for LpShyBin {
|
||||
const NAME: &'static str = "LpShyBin";
|
||||
type Type = super::LpShyBin;
|
||||
type ParentType = adw::Bin;
|
||||
}
|
||||
|
||||
impl ObjectImpl for LpShyBin {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
let obj = self.obj();
|
||||
|
||||
obj.set_layout_manager(None::<gtk::LayoutManager>);
|
||||
obj.set_hexpand(true);
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for LpShyBin {
|
||||
fn measure(&self, orientation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) {
|
||||
let mut measure = self.obj().child().unwrap().measure(orientation, for_size);
|
||||
|
||||
if orientation == gtk::Orientation::Horizontal {
|
||||
// Set natural size to minimal size
|
||||
measure.1 = measure.0;
|
||||
}
|
||||
|
||||
measure
|
||||
}
|
||||
|
||||
fn size_allocate(&self, width: i32, height: i32, baseline: i32) {
|
||||
self.obj()
|
||||
.child()
|
||||
.unwrap()
|
||||
.allocate(width, height, baseline, None);
|
||||
}
|
||||
}
|
||||
|
||||
impl BinImpl for LpShyBin {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct LpShyBin(ObjectSubclass<imp::LpShyBin>)
|
||||
@extends gtk::Widget, adw::Bin;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue