Skip to content

Commit

Permalink
improv: add window border
Browse files Browse the repository at this point in the history
  • Loading branch information
git-f0x authored and mmstick committed Nov 5, 2024
1 parent 36b3cfa commit 127ce17
Show file tree
Hide file tree
Showing 26 changed files with 130 additions and 114 deletions.
6 changes: 3 additions & 3 deletions examples/application/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ impl cosmic::Application for App {
]
.width(iced::Length::Fill)
.height(iced::Length::Shrink)
.align_x(iced::alignment::Horizontal::Center),
.align_x(iced::Alignment::Center),
)
.width(iced::Length::Fill)
.height(iced::Length::Shrink)
.align_x(iced::alignment::Horizontal::Center)
.align_y(iced::alignment::Vertical::Center);
.align_x(iced::Alignment::Center)
.align_y(iced::Alignment::Center);

Element::from(centered)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/calendar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ impl cosmic::Application for App {
let centered = cosmic::widget::container(content)
.width(iced::Length::Fill)
.height(iced::Length::Shrink)
.align_x(iced::alignment::Horizontal::Center)
.align_y(iced::alignment::Vertical::Center);
.align_x(iced::Alignment::Center)
.align_y(iced::Alignment::Center);

Element::from(centered)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/context-menu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl cosmic::Application for App {
let centered = cosmic::widget::container(widget)
.width(iced::Length::Fill)
.height(iced::Length::Fill)
.align_x(iced::alignment::Horizontal::Center)
.align_y(iced::alignment::Vertical::Center);
.align_x(iced::Alignment::Center)
.align_y(iced::Alignment::Center);

Element::from(centered)
}
Expand Down
9 changes: 3 additions & 6 deletions examples/cosmic/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,9 @@ impl Application for Window {
};

widgets.push(
scrollable(
container(content.debug(self.debug))
.align_x(iced::alignment::Horizontal::Center),
)
.width(Length::Fill)
.into(),
scrollable(container(content.debug(self.debug)).align_x(iced::Alignment::Center))
.width(Length::Fill)
.into(),
);
}

Expand Down
4 changes: 2 additions & 2 deletions examples/image-button/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ impl cosmic::Application for App {
let centered = cosmic::widget::container(content)
.width(iced::Length::Fill)
.height(iced::Length::Shrink)
.align_x(iced::alignment::Horizontal::Center)
.align_y(iced::alignment::Vertical::Center);
.align_x(iced::Alignment::Center)
.align_y(iced::Alignment::Center);

Element::from(centered)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/nav-context/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ impl cosmic::Application for App {
let centered = cosmic::widget::container(text)
.width(iced::Length::Fill)
.height(iced::Length::Shrink)
.align_x(iced::alignment::Horizontal::Center)
.align_y(iced::alignment::Vertical::Center);
.align_x(iced::Alignment::Center)
.align_y(iced::Alignment::Center);

Element::from(centered)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/open-dialog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn center<'a>(input: impl Into<Element<'a, Message>> + 'a) -> Element<'a, Messag
iced::widget::container(input.into())
.width(iced::Length::Fill)
.height(iced::Length::Fill)
.align_x(iced::alignment::Horizontal::Center)
.align_y(iced::alignment::Vertical::Center)
.align_x(iced::Alignment::Center)
.align_y(iced::Alignment::Center)
.into()
}
4 changes: 2 additions & 2 deletions examples/text-input/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ impl cosmic::Application for App {
let centered = cosmic::widget::container(column.width(200))
.width(iced::Length::Fill)
.height(iced::Length::Shrink)
.align_x(iced::alignment::Horizontal::Center)
.align_y(iced::alignment::Vertical::Center);
.align_x(iced::Alignment::Center)
.align_y(iced::Alignment::Center);

Element::from(centered)
}
Expand Down
2 changes: 1 addition & 1 deletion iced
Submodule iced updated 1 files
+2 −2 widget/src/scrollable.rs
56 changes: 39 additions & 17 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ pub use self::core::Core;
pub use self::settings::Settings;
use crate::prelude::*;
use crate::theme::THEME;
use crate::widget::{context_drawer, horizontal_space, id_container, menu, nav_bar, popover};
use crate::widget::{
container, context_drawer, horizontal_space, id_container, menu, nav_bar, popover,
};
use apply::Apply;
use iced::window;
use iced::{Length, Subscription};
Expand Down Expand Up @@ -694,6 +696,9 @@ impl<App: Application> ApplicationExt for App {
fn view_main(&self) -> Element<Message<Self::Message>> {
let core = self.core();
let is_condensed = core.is_condensed();
// TODO: More granularity might be needed for different resize border
// and window border handling of maximized and tiled windows
let sharp_corners = core.window.sharp_corners;
let focused = core
.focused_window()
.is_some_and(|i| Some(i) == self.core().main_window_id());
Expand All @@ -706,18 +711,13 @@ impl<App: Application> ApplicationExt for App {
.nav_bar()
.map(|nav| id_container(nav, iced_core::id::Id::new("COSMIC_nav_bar")))
{
widgets.push(nav.into());
widgets.push(container(nav).padding([0, 0, 8, 8]).into());
true
} else {
false
};

if self.nav_model().is_none() || core.show_content() {
// Manual spacing must be used due to state workarounds below
if has_nav {
widgets.push(horizontal_space().width(Length::Fixed(8.0)).into());
}

let main_content = self.view().map(Message::App);

//TODO: reduce duplication
Expand All @@ -737,14 +737,21 @@ impl<App: Application> ApplicationExt for App {
drawer,
iced_core::id::Id::new("COSMIC_context_drawer"),
))
}),
})
.apply(container)
.padding([0, 8, 8, 0])
.into(),
);
} else {
widgets.push(main_content);
//TODO: container and padding are temporary, until
//the `resize_border` is moved to not cover window content
widgets.push(container(main_content).padding([0, 8, 8, 8]).into());
}
} else {
//TODO: hide content when out of space
widgets.push(main_content);
//TODO: container and padding are temporary, until
//the `resize_border` is moved to not cover window content
widgets.push(container(main_content).padding([0, 8, 8, 8]).into());
if let Some(context) = self.context_drawer() {
widgets.push(
crate::widget::ContextDrawer::new_inner(
Expand All @@ -753,15 +760,18 @@ impl<App: Application> ApplicationExt for App {
Message::Cosmic(cosmic::Message::ContextDrawer(false)),
context_width,
)
.apply(crate::widget::container)
.apply(container)
.width(context_width)
.apply(|drawer| {
Element::from(id_container(
drawer,
iced_core::id::Id::new("COSMIC_context_drawer"),
))
}),
);
})
.apply(container)
.padding([0, 8, 8, 0])
.into(),
)
} else {
//TODO: this element is added to workaround state issues
widgets.push(horizontal_space().width(Length::Shrink).into());
Expand All @@ -774,11 +784,13 @@ impl<App: Application> ApplicationExt for App {
let content_col = crate::widget::column::with_capacity(2)
.spacing(8)
.push(content_row)
.push_maybe(self.footer().map(|footer| footer.map(Message::App)));
.push_maybe(
self.footer()
.map(|footer| container(footer.map(Message::App)).padding([0, 8, 8, 8])),
);
let content: Element<_> = if core.window.content_container {
content_col
.apply(crate::widget::container)
.padding([0, 8, 8, 8])
.apply(container)
.width(iced::Length::Fill)
.height(iced::Length::Fill)
.class(crate::theme::Container::WindowBackground)
Expand Down Expand Up @@ -842,7 +854,17 @@ impl<App: Application> ApplicationExt for App {
None
})
// The content element contains every element beneath the header.
.push(content);
.push(content)
.apply(container)
.padding(if sharp_corners { 0 } else { 1 })
.style(move |theme| container::Style {
border: iced::Border {
color: theme.cosmic().bg_divider().into(),
width: if sharp_corners { 0.0 } else { 1.0 },
radius: theme.cosmic().radius_s().map(|x| x + 1.0).into(),
},
..Default::default()
});

// Show any current dialog on top and centered over the view content
// We have to use a popover even without a dialog to keep the tree from changing
Expand Down
5 changes: 1 addition & 4 deletions src/applet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,7 @@ impl Context {
.width(Length::Fixed(suggested.0 as f32))
.height(Length::Fixed(suggested.1 as f32)),
)
.align_x(Horizontal::Center)
.align_y(Vertical::Center)
.width(Length::Fill)
.height(Length::Fill),
.center(Length::Fill),
)
.width(Length::Fixed((suggested.0 + 2 * applet_padding) as f32))
.height(Length::Fixed((suggested.1 + 2 * applet_padding) as f32))
Expand Down
16 changes: 12 additions & 4 deletions src/widget/aspect_ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
use iced::widget::Container;
use iced::Size;
use iced_core::alignment;
use iced_core::event::{self, Event};
use iced_core::layout;
use iced_core::mouse;
use iced_core::overlay;
use iced_core::renderer;
use iced_core::widget::Tree;
use iced_core::{Clipboard, Element, Layout, Length, Padding, Rectangle, Shell, Vector, Widget};
use iced_core::{
Alignment, Clipboard, Element, Layout, Length, Padding, Rectangle, Shell, Vector, Widget,
};

use iced_widget::container;
pub use iced_widget::container::{Catalog, Style};
Expand Down Expand Up @@ -104,14 +105,14 @@ where

/// Sets the content alignment for the horizontal axis of the [`Container`].
#[must_use]
pub fn align_x(mut self, alignment: alignment::Horizontal) -> Self {
pub fn align_x(mut self, alignment: Alignment) -> Self {
self.container = self.container.align_x(alignment);
self
}

/// Sets the content alignment for the vertical axis of the [`Container`].
#[must_use]
pub fn align_y(mut self, alignment: alignment::Vertical) -> Self {
pub fn align_y(mut self, alignment: Alignment) -> Self {
self.container = self.container.align_y(alignment);
self
}
Expand All @@ -130,6 +131,13 @@ where
self
}

/// Centers the contents in the horizontal and vertical axis of the [`Container`].
#[must_use]
pub fn center(mut self, length: Length) -> Self {
self.container = self.container.center(length);
self
}

/// Sets the style of the [`Container`].
#[must_use]
pub fn class(mut self, style: impl Into<crate::style::Container<'a>>) -> Self {
Expand Down
19 changes: 7 additions & 12 deletions src/widget/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
use std::cmp;

use crate::iced_core::{Length, Padding};
use crate::iced_core::{Alignment, Length, Padding};
use crate::widget::{button, column, grid, icon, row, text, Grid};
use chrono::{Datelike, Days, Months, NaiveDate, Weekday};
use iced::alignment::{Horizontal, Vertical};

/// A widget that displays an interactive calendar.
pub fn calendar<M>(
Expand Down Expand Up @@ -62,7 +61,7 @@ where
{
fn from(this: Calendar<'a, Message>) -> Self {
let date = text(this.selected.format("%B %-d, %Y").to_string()).size(18);
let day_of_week = text(this.selected.format("%A").to_string()).size(14);
let day_of_week = text::body(this.selected.format("%A").to_string());

let month_controls = row::with_capacity(2)
.push(
Expand All @@ -86,7 +85,7 @@ where
text(first_day_of_week.to_string())
.size(12)
.width(Length::Fixed(36.0))
.align_x(Horizontal::Center),
.align_x(Alignment::Center),
);

first_day_of_week = first_day_of_week.succ();
Expand Down Expand Up @@ -143,14 +142,10 @@ fn date_button<Message>(
button::ButtonClass::Text
};

let button = button::custom(
text(format!("{}", date.day()))
.align_x(Horizontal::Center)
.align_y(Vertical::Center),
)
.class(style)
.height(Length::Fixed(36.0))
.width(Length::Fixed(36.0));
let button = button::custom(text(format!("{}", date.day())).center())
.class(style)
.height(Length::Fixed(36.0))
.width(Length::Fixed(36.0));

if is_month {
button.on_press((on_select)(set_day(date, date.day())))
Expand Down
6 changes: 3 additions & 3 deletions src/widget/color_picker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ where
button::custom(
text(reset_to_default)
.width(self.width)
.align_x(iced_core::alignment::Horizontal::Center)
.align_x(iced_core::Alignment::Center)
)
.width(self.width)
.on_press(on_update(ColorPickerUpdate::Reset))
Expand All @@ -574,14 +574,14 @@ where
button::custom(
text(cancel)
.width(self.width)
.align_x(iced_core::alignment::Horizontal::Center)
.align_x(iced_core::Alignment::Center)
)
.width(self.width)
.on_press(on_update(ColorPickerUpdate::Cancel)),
button::custom(
text(save)
.width(self.width)
.align_x(iced_core::alignment::Horizontal::Center)
.align_x(iced_core::Alignment::Center)
)
.width(self.width)
.on_press(on_update(ColorPickerUpdate::AppliedColor))
Expand Down
Loading

0 comments on commit 127ce17

Please sign in to comment.