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
|
|
@ -39,8 +39,8 @@ src/widgets/print.ui
|
||||||
src/widgets/print_preview.rs
|
src/widgets/print_preview.rs
|
||||||
src/widgets/properties_view.rs
|
src/widgets/properties_view.rs
|
||||||
src/widgets/properties_view.ui
|
src/widgets/properties_view.ui
|
||||||
|
src/widgets/shy_bin.rs
|
||||||
src/widgets/sliding_view.rs
|
src/widgets/sliding_view.rs
|
||||||
src/widgets/window_title.rs
|
|
||||||
src/window.rs
|
src/window.rs
|
||||||
src/window.ui
|
src/window.ui
|
||||||
src/window/controls.rs
|
src/window/controls.rs
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ use crate::{about, config};
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::widgets::LpShyBin;
|
||||||
|
|
||||||
// The basic struct that holds our
|
// The basic struct that holds our
|
||||||
// state and widgets
|
// state and widgets
|
||||||
|
|
@ -73,6 +74,11 @@ mod imp {
|
||||||
|
|
||||||
// Overrides GApplication vfuncs
|
// Overrides GApplication vfuncs
|
||||||
impl ApplicationImpl for LpApplication {
|
impl ApplicationImpl for LpApplication {
|
||||||
|
fn startup(&self) {
|
||||||
|
self.parent_startup();
|
||||||
|
LpShyBin::ensure_type();
|
||||||
|
}
|
||||||
|
|
||||||
fn activate(&self) {
|
fn activate(&self) {
|
||||||
let application = self.obj();
|
let application = self.obj();
|
||||||
let window = LpWindow::new(&*application);
|
let window = LpWindow::new(&*application);
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ impl imp::LpImage {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.rotation.set(rotation);
|
self.rotation.set(rotation);
|
||||||
obj.configure_adjustments();
|
self.configure_adjustments();
|
||||||
obj.notify_rotation();
|
obj.notify_rotation();
|
||||||
obj.queue_draw();
|
obj.queue_draw();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ mod image_view;
|
||||||
mod print;
|
mod print;
|
||||||
mod print_preview;
|
mod print_preview;
|
||||||
mod properties_view;
|
mod properties_view;
|
||||||
|
mod shy_bin;
|
||||||
mod sliding_view;
|
mod sliding_view;
|
||||||
mod window_title;
|
|
||||||
|
|
||||||
pub use drag_overlay::LpDragOverlay;
|
pub use drag_overlay::LpDragOverlay;
|
||||||
pub use image::LpImage;
|
pub use image::LpImage;
|
||||||
|
|
@ -34,5 +34,5 @@ pub use image_view::LpImageView;
|
||||||
pub use print::LpPrint;
|
pub use print::LpPrint;
|
||||||
pub use print_preview::LpPrintPreview;
|
pub use print_preview::LpPrintPreview;
|
||||||
pub use properties_view::LpPropertiesView;
|
pub use properties_view::LpPropertiesView;
|
||||||
|
pub use shy_bin::LpShyBin;
|
||||||
pub use sliding_view::LpSlidingView;
|
pub use sliding_view::LpSlidingView;
|
||||||
pub use window_title::LpWindowTitle;
|
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,12 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// 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
|
//! This bin does not claim its complete width as natural width. The HeaderBar
|
||||||
//! avoids the window to grow to a large file name title instead of just
|
//! is wrapped in with this widget. This prevents the window from growing based
|
||||||
//! fittingly for the image size.
|
//! on a long file name in the title instead of just fitting to the image
|
||||||
|
//! size.
|
||||||
|
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
|
|
@ -29,46 +30,29 @@ use crate::deps::*;
|
||||||
mod imp {
|
mod imp {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(Debug, Default, glib::Properties)]
|
#[derive(Debug, Default)]
|
||||||
#[properties(wrapper_type = super::LpWindowTitle)]
|
pub struct LpShyBin {}
|
||||||
pub struct LpWindowTitle {
|
|
||||||
#[property(type = String, set = Self::set_title)]
|
|
||||||
_title: (),
|
|
||||||
window_title: adw::WindowTitle,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
impl ObjectSubclass for LpWindowTitle {
|
impl ObjectSubclass for LpShyBin {
|
||||||
const NAME: &'static str = "LpWindowTitle";
|
const NAME: &'static str = "LpShyBin";
|
||||||
type Type = super::LpWindowTitle;
|
type Type = super::LpShyBin;
|
||||||
type ParentType = adw::Bin;
|
type ParentType = adw::Bin;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectImpl for LpWindowTitle {
|
impl ObjectImpl for LpShyBin {
|
||||||
fn constructed(&self) {
|
fn constructed(&self) {
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
let obj = self.obj();
|
let obj = self.obj();
|
||||||
|
|
||||||
obj.set_layout_manager(None::<gtk::LayoutManager>);
|
obj.set_layout_manager(None::<gtk::LayoutManager>);
|
||||||
obj.set_child(Some(&self.window_title));
|
|
||||||
obj.set_hexpand(true);
|
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) {
|
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 {
|
if orientation == gtk::Orientation::Horizontal {
|
||||||
// Set natural size to minimal size
|
// Set natural size to minimal size
|
||||||
|
|
@ -79,19 +63,17 @@ mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_allocate(&self, width: i32, height: i32, baseline: i32) {
|
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 {
|
impl BinImpl for LpShyBin {}
|
||||||
fn set_title(&self, title: String) {
|
|
||||||
self.window_title.set_title(&title);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct LpWindowTitle(ObjectSubclass<imp::LpWindowTitle>)
|
pub struct LpShyBin(ObjectSubclass<imp::LpShyBin>)
|
||||||
@extends gtk::Widget, adw::Bin;
|
@extends gtk::Widget, adw::Bin;
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +53,6 @@ const HIDE_CONTROLS_IDLE_TIMEOUT: u64 = 3000;
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::widgets::LpWindowTitle;
|
|
||||||
|
|
||||||
// To use composite templates, you need
|
// To use composite templates, you need
|
||||||
// to use derive macro. Derive macros generate
|
// to use derive macro. Derive macros generate
|
||||||
|
|
@ -80,8 +79,6 @@ mod imp {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub(super) headerbar: TemplateChild<adw::HeaderBar>,
|
pub(super) headerbar: TemplateChild<adw::HeaderBar>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub(super) title: TemplateChild<LpWindowTitle>,
|
|
||||||
#[template_child]
|
|
||||||
pub(super) headerbar_events: TemplateChild<gtk::EventControllerMotion>,
|
pub(super) headerbar_events: TemplateChild<gtk::EventControllerMotion>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub(super) properties_button: TemplateChild<gtk::ToggleButton>,
|
pub(super) properties_button: TemplateChild<gtk::ToggleButton>,
|
||||||
|
|
|
||||||
127
src/window.ui
127
src/window.ui
|
|
@ -70,72 +70,71 @@
|
||||||
<property name="content">
|
<property name="content">
|
||||||
<object class="AdwToolbarView" id="toolbar_view">
|
<object class="AdwToolbarView" id="toolbar_view">
|
||||||
<child type="top">
|
<child type="top">
|
||||||
<object class="AdwHeaderBar" id="headerbar">
|
<object class="LpShyBin">
|
||||||
<property name="show-end-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean" />
|
<property name="child">
|
||||||
<property name="show-start-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean" />
|
<object class="AdwHeaderBar" id="headerbar">
|
||||||
<property name="title-widget">
|
<property name="show-end-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean" />
|
||||||
<object class="LpWindowTitle" id="title">
|
<property name="show-start-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean" />
|
||||||
<property name="title" bind-source="LpWindow" bind-property="title" />
|
<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>
|
</object>
|
||||||
</property>
|
</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>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<property name="content">
|
<property name="content">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue