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::{
|
use cosmic::{
|
||||||
iced::{
|
iced::{
|
||||||
Element,
|
Alignment, Element,
|
||||||
core::{
|
core::{
|
||||||
Background, Border, Clipboard, Color, Event, Layout, Length, Rectangle,
|
Background, Border, Clipboard, Color, Event, Layout, Length, Rectangle,
|
||||||
Renderer as IcedRenderer, Shell, Size, layout, mouse, overlay,
|
Renderer as IcedRenderer, Shell, Size, layout, mouse, overlay,
|
||||||
|
|
@ -75,11 +75,26 @@ where
|
||||||
viewport: &Rectangle,
|
viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
let widget_state = state.state.downcast_ref::<State>();
|
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)
|
theme.hovered(true, false, &self.styling)
|
||||||
} else {
|
} else {
|
||||||
theme.active(true, false, &self.styling)
|
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(
|
renderer.fill_quad(
|
||||||
Quad {
|
Quad {
|
||||||
|
|
@ -87,7 +102,7 @@ where
|
||||||
bounds: layout.bounds(),
|
bounds: layout.bounds(),
|
||||||
border: Border {
|
border: Border {
|
||||||
radius: styling.border_radius,
|
radius: styling.border_radius,
|
||||||
width: styling.border_width,
|
width: 0.,
|
||||||
color: styling.border_color,
|
color: styling.border_color,
|
||||||
},
|
},
|
||||||
shadow: Default::default(),
|
shadow: Default::default(),
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ use cosmic::{
|
||||||
iced::{
|
iced::{
|
||||||
Alignment, Background,
|
Alignment, Background,
|
||||||
core::{Border, Length, Rectangle as IcedRectangle, alignment::Horizontal},
|
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,
|
theme,
|
||||||
widget::{button, divider, icon::from_name, space, text},
|
widget::{button, divider, icon::from_name, menu::menu_column::MenuColumn, space, text},
|
||||||
};
|
};
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{
|
backend::{
|
||||||
|
|
@ -300,7 +300,7 @@ impl Program for ContextMenu {
|
||||||
Rectangle::new(
|
Rectangle::new(
|
||||||
position
|
position
|
||||||
+ Point::from((
|
+ Point::from((
|
||||||
bounds.width.ceil() as i32,
|
bounds.width.floor() as i32,
|
||||||
bounds.y.ceil() as i32,
|
bounds.y.ceil() as i32,
|
||||||
)),
|
)),
|
||||||
min_size.as_global(),
|
min_size.as_global(),
|
||||||
|
|
@ -309,7 +309,7 @@ impl Program for ContextMenu {
|
||||||
Rectangle::new(
|
Rectangle::new(
|
||||||
position
|
position
|
||||||
+ Point::from((
|
+ Point::from((
|
||||||
bounds.width.ceil() as i32,
|
bounds.width.floor() as i32,
|
||||||
bounds.y.ceil() as i32 + bounds.height.ceil() as i32
|
bounds.y.ceil() as i32 + bounds.height.ceil() as i32
|
||||||
- min_size.h,
|
- min_size.h,
|
||||||
)),
|
)),
|
||||||
|
|
@ -317,14 +317,15 @@ impl Program for ContextMenu {
|
||||||
),
|
),
|
||||||
// to the left -> down
|
// to the left -> down
|
||||||
Rectangle::new(
|
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(),
|
min_size.as_global(),
|
||||||
),
|
),
|
||||||
// to the left -> up
|
// to the left -> up
|
||||||
Rectangle::new(
|
Rectangle::new(
|
||||||
position
|
position
|
||||||
+ Point::from((
|
+ Point::from((
|
||||||
-min_size.w,
|
-min_size.w + 1,
|
||||||
bounds.y.ceil() as i32 + bounds.height.ceil() as i32
|
bounds.y.ceil() as i32 + bounds.height.ceil() as i32
|
||||||
- min_size.h,
|
- min_size.h,
|
||||||
)),
|
)),
|
||||||
|
|
@ -390,9 +391,11 @@ impl Program for ContextMenu {
|
||||||
_ => Length::Fill,
|
_ => Length::Fill,
|
||||||
};
|
};
|
||||||
|
|
||||||
Column::with_children(self.items.iter().enumerate().map(|(idx, item)| {
|
MenuColumn::with_children(self.items.iter().enumerate().map(|(idx, item)| {
|
||||||
match 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![
|
Item::Submenu { title, .. } => Row::with_children(vec![
|
||||||
space::horizontal().width(16).into(),
|
space::horizontal().width(16).into(),
|
||||||
text::body(title).width(mode).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);
|
PointerTarget::motion(&element.iced, &self.seat, state, &new_event);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
elements.iter_mut().for_each(|element| {
|
elements
|
||||||
if element.pointer_entered {
|
.iter_mut()
|
||||||
|
.filter(|element| element.pointer_entered)
|
||||||
|
.skip(1)
|
||||||
|
.for_each(|element| {
|
||||||
PointerTarget::leave(
|
PointerTarget::leave(
|
||||||
&element.iced,
|
&element.iced,
|
||||||
&self.seat,
|
&self.seat,
|
||||||
|
|
@ -571,8 +577,7 @@ impl PointerGrab<State> for MenuGrab {
|
||||||
event.time,
|
event.time,
|
||||||
);
|
);
|
||||||
element.pointer_entered = false;
|
element.pointer_entered = false;
|
||||||
}
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handle.motion(state, None, event);
|
handle.motion(state, None, event);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue