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
|
|
@ -29,6 +29,7 @@ use crate::{about, config};
|
|||
|
||||
mod imp {
|
||||
use super::*;
|
||||
use crate::widgets::LpShyBin;
|
||||
|
||||
// The basic struct that holds our
|
||||
// state and widgets
|
||||
|
|
@ -73,6 +74,11 @@ mod imp {
|
|||
|
||||
// Overrides GApplication vfuncs
|
||||
impl ApplicationImpl for LpApplication {
|
||||
fn startup(&self) {
|
||||
self.parent_startup();
|
||||
LpShyBin::ensure_type();
|
||||
}
|
||||
|
||||
fn activate(&self) {
|
||||
let application = self.obj();
|
||||
let window = LpWindow::new(&*application);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ impl imp::LpImage {
|
|||
}
|
||||
|
||||
self.rotation.set(rotation);
|
||||
obj.configure_adjustments();
|
||||
self.configure_adjustments();
|
||||
obj.notify_rotation();
|
||||
obj.queue_draw();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ mod image_view;
|
|||
mod print;
|
||||
mod print_preview;
|
||||
mod properties_view;
|
||||
mod shy_bin;
|
||||
mod sliding_view;
|
||||
mod window_title;
|
||||
|
||||
pub use drag_overlay::LpDragOverlay;
|
||||
pub use image::LpImage;
|
||||
|
|
@ -34,5 +34,5 @@ pub use image_view::LpImageView;
|
|||
pub use print::LpPrint;
|
||||
pub use print_preview::LpPrintPreview;
|
||||
pub use properties_view::LpPropertiesView;
|
||||
pub use shy_bin::LpShyBin;
|
||||
pub use sliding_view::LpSlidingView;
|
||||
pub use window_title::LpWindowTitle;
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@
|
|||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
//! A window title
|
||||
//! A bin that only has min width as natural width
|
||||
//!
|
||||
//! This window title does not claim its complete width as natural width. This
|
||||
//! avoids the window to grow to a large file name title instead of just
|
||||
//! fittingly for the image size.
|
||||
//! 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::*;
|
||||
|
|
@ -29,46 +30,29 @@ use crate::deps::*;
|
|||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default, glib::Properties)]
|
||||
#[properties(wrapper_type = super::LpWindowTitle)]
|
||||
pub struct LpWindowTitle {
|
||||
#[property(type = String, set = Self::set_title)]
|
||||
_title: (),
|
||||
window_title: adw::WindowTitle,
|
||||
}
|
||||
#[derive(Debug, Default)]
|
||||
pub struct LpShyBin {}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for LpWindowTitle {
|
||||
const NAME: &'static str = "LpWindowTitle";
|
||||
type Type = super::LpWindowTitle;
|
||||
impl ObjectSubclass for LpShyBin {
|
||||
const NAME: &'static str = "LpShyBin";
|
||||
type Type = super::LpShyBin;
|
||||
type ParentType = adw::Bin;
|
||||
}
|
||||
|
||||
impl ObjectImpl for LpWindowTitle {
|
||||
impl ObjectImpl for LpShyBin {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
let obj = self.obj();
|
||||
|
||||
obj.set_layout_manager(None::<gtk::LayoutManager>);
|
||||
obj.set_child(Some(&self.window_title));
|
||||
obj.set_hexpand(true);
|
||||
}
|
||||
|
||||
fn properties() -> &'static [glib::ParamSpec] {
|
||||
Self::derived_properties()
|
||||
}
|
||||
|
||||
fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
||||
self.derived_set_property(id, value, pspec)
|
||||
}
|
||||
|
||||
fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
||||
self.derived_property(id, pspec)
|
||||
}
|
||||
}
|
||||
impl WidgetImpl for LpWindowTitle {
|
||||
|
||||
impl WidgetImpl for LpShyBin {
|
||||
fn measure(&self, orientation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) {
|
||||
let mut measure = self.window_title.measure(orientation, for_size);
|
||||
let mut measure = self.obj().child().unwrap().measure(orientation, for_size);
|
||||
|
||||
if orientation == gtk::Orientation::Horizontal {
|
||||
// Set natural size to minimal size
|
||||
|
|
@ -79,19 +63,17 @@ mod imp {
|
|||
}
|
||||
|
||||
fn size_allocate(&self, width: i32, height: i32, baseline: i32) {
|
||||
self.window_title.allocate(width, height, baseline, None);
|
||||
self.obj()
|
||||
.child()
|
||||
.unwrap()
|
||||
.allocate(width, height, baseline, None);
|
||||
}
|
||||
}
|
||||
impl BinImpl for LpWindowTitle {}
|
||||
|
||||
impl LpWindowTitle {
|
||||
fn set_title(&self, title: String) {
|
||||
self.window_title.set_title(&title);
|
||||
}
|
||||
}
|
||||
impl BinImpl for LpShyBin {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct LpWindowTitle(ObjectSubclass<imp::LpWindowTitle>)
|
||||
pub struct LpShyBin(ObjectSubclass<imp::LpShyBin>)
|
||||
@extends gtk::Widget, adw::Bin;
|
||||
}
|
||||
|
|
@ -53,7 +53,6 @@ const HIDE_CONTROLS_IDLE_TIMEOUT: u64 = 3000;
|
|||
|
||||
mod imp {
|
||||
use super::*;
|
||||
use crate::widgets::LpWindowTitle;
|
||||
|
||||
// To use composite templates, you need
|
||||
// to use derive macro. Derive macros generate
|
||||
|
|
@ -80,8 +79,6 @@ mod imp {
|
|||
#[template_child]
|
||||
pub(super) headerbar: TemplateChild<adw::HeaderBar>,
|
||||
#[template_child]
|
||||
pub(super) title: TemplateChild<LpWindowTitle>,
|
||||
#[template_child]
|
||||
pub(super) headerbar_events: TemplateChild<gtk::EventControllerMotion>,
|
||||
#[template_child]
|
||||
pub(super) properties_button: TemplateChild<gtk::ToggleButton>,
|
||||
|
|
|
|||
127
src/window.ui
127
src/window.ui
|
|
@ -70,72 +70,71 @@
|
|||
<property name="content">
|
||||
<object class="AdwToolbarView" id="toolbar_view">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar" id="headerbar">
|
||||
<property name="show-end-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean" />
|
||||
<property name="show-start-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean" />
|
||||
<property name="title-widget">
|
||||
<object class="LpWindowTitle" id="title">
|
||||
<property name="title" bind-source="LpWindow" bind-property="title" />
|
||||
<object class="LpShyBin">
|
||||
<property name="child">
|
||||
<object class="AdwHeaderBar" id="headerbar">
|
||||
<property name="show-end-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean" />
|
||||
<property name="show-start-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean" />
|
||||
<style>
|
||||
<class name="fullscreen-osd" />
|
||||
</style>
|
||||
<child type="start">
|
||||
<object class="GtkButton">
|
||||
<property name="icon-name">edit-copy-symbolic</property>
|
||||
<property name="action-name">win.copy-image</property>
|
||||
<property name="tooltip-text" translatable="yes">Copy to Clipboard</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="start">
|
||||
<object class="GtkButton">
|
||||
<property name="icon-name">user-trash-symbolic</property>
|
||||
<property name="action-name">win.trash</property>
|
||||
<property name="tooltip-text" translatable="yes">Move to Trash</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="end">
|
||||
<object class="GtkMenuButton" id="primary_menu">
|
||||
<property name="icon-name">open-menu-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Main Menu</property>
|
||||
<property name="primary">True</property>
|
||||
<property name="popover">
|
||||
<object class="GtkPopoverMenu">
|
||||
<property name="menu-model">primary_menu</property>
|
||||
<child type="rotate-left">
|
||||
<object class="GtkButton">
|
||||
<property name="icon-name">object-rotate-left-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Rotate Left</property>
|
||||
<property name="action-name">win.rotate_ccw</property>
|
||||
<style>
|
||||
<class name="flat" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child type="rotate-right">
|
||||
<object class="GtkButton">
|
||||
<property name="icon-name">object-rotate-right-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Rotate Right</property>
|
||||
<property name="action-name">win.rotate_cw</property>
|
||||
<style>
|
||||
<class name="flat" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="end">
|
||||
<object class="GtkToggleButton" id="properties_button">
|
||||
<property name="icon-name">info-outline-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Image Properties</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEventControllerMotion" id="headerbar_events" />
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
<style>
|
||||
<class name="fullscreen-osd" />
|
||||
</style>
|
||||
<child type="start">
|
||||
<object class="GtkButton">
|
||||
<property name="icon-name">edit-copy-symbolic</property>
|
||||
<property name="action-name">win.copy-image</property>
|
||||
<property name="tooltip-text" translatable="yes">Copy to Clipboard</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="start">
|
||||
<object class="GtkButton">
|
||||
<property name="icon-name">user-trash-symbolic</property>
|
||||
<property name="action-name">win.trash</property>
|
||||
<property name="tooltip-text" translatable="yes">Move to Trash</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="end">
|
||||
<object class="GtkMenuButton" id="primary_menu">
|
||||
<property name="icon-name">open-menu-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Main Menu</property>
|
||||
<property name="primary">True</property>
|
||||
<property name="popover">
|
||||
<object class="GtkPopoverMenu">
|
||||
<property name="menu-model">primary_menu</property>
|
||||
<child type="rotate-left">
|
||||
<object class="GtkButton">
|
||||
<property name="icon-name">object-rotate-left-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Rotate Left</property>
|
||||
<property name="action-name">win.rotate_ccw</property>
|
||||
<style>
|
||||
<class name="flat" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child type="rotate-right">
|
||||
<object class="GtkButton">
|
||||
<property name="icon-name">object-rotate-right-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Rotate Right</property>
|
||||
<property name="action-name">win.rotate_cw</property>
|
||||
<style>
|
||||
<class name="flat" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="end">
|
||||
<object class="GtkToggleButton" id="properties_button">
|
||||
<property name="icon-name">info-outline-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Image Properties</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEventControllerMotion" id="headerbar_events" />
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue