shell/menu: Use new MenuColumn widget
This commit is contained in:
parent
4f8aed4149
commit
1f48a5e866
2 changed files with 35 additions and 15 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use cosmic::{
|
||||
iced::{
|
||||
Element,
|
||||
Alignment, Element,
|
||||
core::{
|
||||
Background, Border, Clipboard, Color, Event, Layout, Length, Rectangle,
|
||||
Renderer as IcedRenderer, Shell, Size, layout, mouse, overlay,
|
||||
|
|
@ -75,11 +75,26 @@ where
|
|||
viewport: &Rectangle,
|
||||
) {
|
||||
let widget_state = state.state.downcast_ref::<State>();
|
||||
let styling = if widget_state.cursor_over {
|
||||
let mut styling = if widget_state.cursor_over {
|
||||
theme.hovered(true, false, &self.styling)
|
||||
} else {
|
||||
theme.active(true, false, &self.styling)
|
||||
};
|
||||
if matches!(self.styling, cosmic::theme::Button::MenuItem) {
|
||||
match theme.list_item_position {
|
||||
Some((Alignment::Start, _)) => {
|
||||
styling.border_radius =
|
||||
styling.border_radius.bottom(theme.cosmic().radius_0()[3]);
|
||||
}
|
||||
Some((Alignment::End, _)) => {
|
||||
styling.border_radius = styling.border_radius.top(theme.cosmic().radius_0()[0]);
|
||||
}
|
||||
Some((Alignment::Center, _)) => {}
|
||||
None => {
|
||||
styling.border_radius = theme.cosmic().radius_0().into();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
renderer.fill_quad(
|
||||
Quad {
|
||||
|
|
@ -87,7 +102,7 @@ where
|
|||
bounds: layout.bounds(),
|
||||
border: Border {
|
||||
radius: styling.border_radius,
|
||||
width: styling.border_width,
|
||||
width: 0.,
|
||||
color: styling.border_color,
|
||||
},
|
||||
shadow: Default::default(),
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ use cosmic::{
|
|||
iced::{
|
||||
Alignment, Background,
|
||||
core::{Border, Length, Rectangle as IcedRectangle, alignment::Horizontal},
|
||||
widget::{self as iced_widget, Column, Row, text::Style as TextStyle},
|
||||
widget::{self as iced_widget, Row, text::Style as TextStyle},
|
||||
},
|
||||
theme,
|
||||
widget::{button, divider, icon::from_name, space, text},
|
||||
widget::{button, divider, icon::from_name, menu::menu_column::MenuColumn, space, text},
|
||||
};
|
||||
use smithay::{
|
||||
backend::{
|
||||
|
|
@ -300,7 +300,7 @@ impl Program for ContextMenu {
|
|||
Rectangle::new(
|
||||
position
|
||||
+ Point::from((
|
||||
bounds.width.ceil() as i32,
|
||||
bounds.width.floor() as i32,
|
||||
bounds.y.ceil() as i32,
|
||||
)),
|
||||
min_size.as_global(),
|
||||
|
|
@ -309,7 +309,7 @@ impl Program for ContextMenu {
|
|||
Rectangle::new(
|
||||
position
|
||||
+ Point::from((
|
||||
bounds.width.ceil() as i32,
|
||||
bounds.width.floor() as i32,
|
||||
bounds.y.ceil() as i32 + bounds.height.ceil() as i32
|
||||
- min_size.h,
|
||||
)),
|
||||
|
|
@ -317,14 +317,15 @@ impl Program for ContextMenu {
|
|||
),
|
||||
// to the left -> down
|
||||
Rectangle::new(
|
||||
position + Point::from((-min_size.w, bounds.y.ceil() as i32)),
|
||||
position
|
||||
+ Point::from((-min_size.w + 1, bounds.y.ceil() as i32)),
|
||||
min_size.as_global(),
|
||||
),
|
||||
// to the left -> up
|
||||
Rectangle::new(
|
||||
position
|
||||
+ Point::from((
|
||||
-min_size.w,
|
||||
-min_size.w + 1,
|
||||
bounds.y.ceil() as i32 + bounds.height.ceil() as i32
|
||||
- min_size.h,
|
||||
)),
|
||||
|
|
@ -390,9 +391,11 @@ impl Program for ContextMenu {
|
|||
_ => Length::Fill,
|
||||
};
|
||||
|
||||
Column::with_children(self.items.iter().enumerate().map(|(idx, item)| {
|
||||
MenuColumn::with_children(self.items.iter().enumerate().map(|(idx, item)| {
|
||||
match item {
|
||||
Item::Separator => divider::horizontal::light().into(),
|
||||
Item::Separator => divider::horizontal::light()
|
||||
.class(theme::Rule::Default)
|
||||
.into(),
|
||||
Item::Submenu { title, .. } => Row::with_children(vec![
|
||||
space::horizontal().width(16).into(),
|
||||
text::body(title).width(mode).into(),
|
||||
|
|
@ -561,8 +564,11 @@ impl PointerGrab<State> for MenuGrab {
|
|||
PointerTarget::motion(&element.iced, &self.seat, state, &new_event);
|
||||
}
|
||||
} else {
|
||||
elements.iter_mut().for_each(|element| {
|
||||
if element.pointer_entered {
|
||||
elements
|
||||
.iter_mut()
|
||||
.filter(|element| element.pointer_entered)
|
||||
.skip(1)
|
||||
.for_each(|element| {
|
||||
PointerTarget::leave(
|
||||
&element.iced,
|
||||
&self.seat,
|
||||
|
|
@ -571,7 +577,6 @@ impl PointerGrab<State> for MenuGrab {
|
|||
event.time,
|
||||
);
|
||||
element.pointer_entered = false;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue