wip: update to use latest iced
This commit is contained in:
parent
ca1469a6b2
commit
f4ad098647
49 changed files with 956 additions and 854 deletions
|
|
@ -131,9 +131,11 @@ where
|
|||
}
|
||||
|
||||
// Get the max available width for placing buttons into.
|
||||
let max_size = limits
|
||||
.height(Length::Fixed(total_height))
|
||||
.resolve(Size::new(f32::MAX, total_height));
|
||||
let max_size = limits.height(Length::Fixed(total_height)).resolve(
|
||||
Length::Fill,
|
||||
total_height,
|
||||
Size::new(f32::MAX, total_height),
|
||||
);
|
||||
|
||||
let mut visible_width = f32::from(self.button_height) * 2.0;
|
||||
state.buttons_visible = 0;
|
||||
|
|
@ -162,25 +164,33 @@ where
|
|||
size = limits
|
||||
.width(Length::Fixed(visible_width))
|
||||
.height(Length::Fixed(total_height))
|
||||
.resolve(Size::new(visible_width, total_height));
|
||||
.resolve(
|
||||
visible_width,
|
||||
total_height,
|
||||
Size::new(visible_width, total_height),
|
||||
);
|
||||
} else {
|
||||
// Buttons will be rendered with equal widths.
|
||||
state.buttons_visible = self.model.items.len();
|
||||
let (width, height) = self.max_button_dimensions(state, renderer, limits.max());
|
||||
let total_width = (state.buttons_visible as f32) * (width + spacing);
|
||||
|
||||
size = limits
|
||||
.height(Length::Fixed(height))
|
||||
.resolve(Size::new(total_width, height));
|
||||
size = limits.height(Length::Fixed(height)).resolve(
|
||||
total_width,
|
||||
height,
|
||||
Size::new(total_width, height),
|
||||
);
|
||||
|
||||
let actual_width = size.width as usize;
|
||||
let minimum_width = state.buttons_visible * self.minimum_button_width as usize;
|
||||
state.collapsed = actual_width < minimum_width;
|
||||
|
||||
if state.collapsed {
|
||||
size = limits
|
||||
.height(Length::Fixed(height))
|
||||
.resolve(Size::new(f32::MAX, height));
|
||||
size = limits.height(Length::Fixed(height)).resolve(
|
||||
Length::Fill,
|
||||
height,
|
||||
Size::new(f32::MAX, height),
|
||||
);
|
||||
|
||||
state.buttons_visible =
|
||||
(actual_width / self.minimum_button_width as usize).min(state.buttons_visible);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
// Copyright 2022 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use iced_core::{Background, BorderRadius, Color};
|
||||
use iced_core::{border::Radius, Background, Color};
|
||||
|
||||
/// Appearance of the segmented button.
|
||||
#[derive(Default, Clone, Copy)]
|
||||
pub struct Appearance {
|
||||
pub background: Option<Background>,
|
||||
pub border_radius: BorderRadius,
|
||||
pub border_radius: Radius,
|
||||
pub border_bottom: Option<(f32, Color)>,
|
||||
pub border_end: Option<(f32, Color)>,
|
||||
pub border_start: Option<(f32, Color)>,
|
||||
|
|
@ -21,7 +21,7 @@ pub struct Appearance {
|
|||
/// Appearance of an item in the segmented button.
|
||||
#[derive(Default, Clone, Copy)]
|
||||
pub struct ItemAppearance {
|
||||
pub border_radius: BorderRadius,
|
||||
pub border_radius: Radius,
|
||||
pub border_bottom: Option<(f32, Color)>,
|
||||
pub border_end: Option<(f32, Color)>,
|
||||
pub border_start: Option<(f32, Color)>,
|
||||
|
|
|
|||
|
|
@ -88,9 +88,10 @@ where
|
|||
height = (num as f32 * height) + (num as f32 * spacing) - spacing;
|
||||
}
|
||||
|
||||
let size = limits
|
||||
.height(Length::Fixed(height))
|
||||
.resolve(Size::new(width, height));
|
||||
let size =
|
||||
limits
|
||||
.height(Length::Fixed(height))
|
||||
.resolve(width, height, Size::new(width, height));
|
||||
|
||||
layout::Node::new(size)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use iced_core::mouse::ScrollDelta;
|
|||
use iced_core::text::{LineHeight, Paragraph, Renderer as TextRenderer, Shaping};
|
||||
use iced_core::widget::{self, operation, tree};
|
||||
use iced_core::{layout, renderer, widget::Tree, Clipboard, Layout, Shell, Widget};
|
||||
use iced_core::{Point, Renderer as IcedRenderer, Text};
|
||||
use iced_core::{Border, Point, Renderer as IcedRenderer, Shadow, Text};
|
||||
use slotmap::{Key, SecondaryMap};
|
||||
use std::marker::PhantomData;
|
||||
use std::time::{Duration, Instant};
|
||||
|
|
@ -374,7 +374,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, Variant, SelectionMode, Message> Widget<Message, Renderer>
|
||||
impl<'a, Variant, SelectionMode, Message> Widget<Message, crate::Theme, Renderer>
|
||||
for SegmentedButton<'a, Variant, SelectionMode, Message>
|
||||
where
|
||||
Self: SegmentedVariant,
|
||||
|
|
@ -423,12 +423,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn width(&self) -> Length {
|
||||
self.width
|
||||
}
|
||||
|
||||
fn height(&self) -> Length {
|
||||
self.height
|
||||
fn size(&self) -> Size<Length> {
|
||||
Size::new(self.width, self.height)
|
||||
}
|
||||
|
||||
fn layout(
|
||||
|
|
@ -601,7 +597,7 @@ where
|
|||
|
||||
if state.focused {
|
||||
if let Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
key_code: keyboard::KeyCode::Tab,
|
||||
key: keyboard::Key::Named(keyboard::key::Named::Tab),
|
||||
modifiers,
|
||||
..
|
||||
}) = event
|
||||
|
|
@ -615,7 +611,7 @@ where
|
|||
|
||||
if let Some(on_activate) = self.on_activate.as_ref() {
|
||||
if let Event::Keyboard(keyboard::Event::KeyReleased {
|
||||
key_code: keyboard::KeyCode::Enter,
|
||||
key: keyboard::Key::Named(keyboard::key::Named::Enter),
|
||||
..
|
||||
}) = event
|
||||
{
|
||||
|
|
@ -719,7 +715,6 @@ where
|
|||
cursor: mouse::Cursor,
|
||||
viewport: &iced::Rectangle,
|
||||
) {
|
||||
let cosmic_theme = theme.cosmic();
|
||||
let state = tree.state.downcast_ref::<LocalState>();
|
||||
let appearance = Self::variant_appearance(theme, &self.style);
|
||||
let bounds = layout.bounds();
|
||||
|
|
@ -730,9 +725,11 @@ where
|
|||
renderer.fill_quad(
|
||||
renderer::Quad {
|
||||
bounds,
|
||||
border_radius: appearance.border_radius,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
border: Border {
|
||||
radius: appearance.border_radius,
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
},
|
||||
background,
|
||||
);
|
||||
|
|
@ -758,9 +755,11 @@ where
|
|||
width: f32::from(self.button_height),
|
||||
height: bounds.height,
|
||||
},
|
||||
border_radius: cosmic_theme.radius_s().into(),
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
border: Border {
|
||||
radius: appearance.focus.first.border_radius,
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
},
|
||||
background_appearance
|
||||
.background
|
||||
|
|
@ -808,9 +807,11 @@ where
|
|||
width: f32::from(self.button_height),
|
||||
height: bounds.height,
|
||||
},
|
||||
border_radius: cosmic_theme.radius_s().into(),
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
border: Border {
|
||||
radius: appearance.focus.last.border_radius,
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
},
|
||||
background_appearance
|
||||
.background
|
||||
|
|
@ -871,9 +872,11 @@ where
|
|||
renderer.fill_quad(
|
||||
renderer::Quad {
|
||||
bounds,
|
||||
border_radius: button_appearance.border_radius,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
border: Border {
|
||||
radius: button_appearance.border_radius,
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
},
|
||||
status_appearance
|
||||
.background
|
||||
|
|
@ -891,9 +894,11 @@ where
|
|||
renderer.fill_quad(
|
||||
renderer::Quad {
|
||||
bounds,
|
||||
border_radius: rad_0.into(),
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
border: Border {
|
||||
radius: rad_0.into(),
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
},
|
||||
background,
|
||||
);
|
||||
|
|
@ -1012,7 +1017,7 @@ where
|
|||
_tree: &'b mut Tree,
|
||||
_layout: iced_core::Layout<'_>,
|
||||
_renderer: &Renderer,
|
||||
) -> Option<iced_core::overlay::Element<'b, Message, Renderer>> {
|
||||
) -> Option<iced_core::overlay::Element<'b, Message, crate::Theme, Renderer>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
@ -1134,18 +1139,17 @@ fn draw_icon<Message: 'static>(
|
|||
bounds: Rectangle,
|
||||
icon: Icon,
|
||||
) {
|
||||
let mut layout_node = layout::Node::new(Size {
|
||||
let layout_node = layout::Node::new(Size {
|
||||
width: bounds.width,
|
||||
height: bounds.width,
|
||||
});
|
||||
|
||||
layout_node.move_to(Point {
|
||||
})
|
||||
.move_to(Point {
|
||||
x: bounds.x,
|
||||
y: bounds.y,
|
||||
});
|
||||
|
||||
Widget::<Message, Renderer>::draw(
|
||||
Element::<Message>::from(icon).as_widget(),
|
||||
Widget::<Message, crate::Theme, Renderer>::draw(
|
||||
Element::<Message>::from(icon.clone()).as_widget(),
|
||||
&Tree::empty(),
|
||||
renderer,
|
||||
theme,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue