Remove trait-specific draw logic in iced_native
This commit is contained in:
parent
3aae45c191
commit
03b3493138
71 changed files with 641 additions and 3126 deletions
|
|
@ -189,7 +189,7 @@ where
|
|||
) -> Element<'a, Message, Renderer>
|
||||
where
|
||||
Message: 'static,
|
||||
Renderer: 'a + layout::Debugger,
|
||||
Renderer: 'a,
|
||||
{
|
||||
Element {
|
||||
widget: Box::new(Explain::new(self, color.into())),
|
||||
|
|
@ -245,7 +245,7 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
) {
|
||||
self.widget
|
||||
.draw(renderer, defaults, layout, cursor_position, viewport)
|
||||
}
|
||||
|
|
@ -340,7 +340,7 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
) {
|
||||
self.widget
|
||||
.draw(renderer, defaults, layout, cursor_position, viewport)
|
||||
}
|
||||
|
|
@ -378,7 +378,7 @@ where
|
|||
impl<'a, Message, Renderer> Widget<Message, Renderer>
|
||||
for Explain<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: crate::Renderer + layout::Debugger,
|
||||
Renderer: crate::Renderer,
|
||||
{
|
||||
fn width(&self) -> Length {
|
||||
self.element.widget.width()
|
||||
|
|
@ -417,20 +417,12 @@ where
|
|||
|
||||
fn draw(
|
||||
&self,
|
||||
renderer: &mut Renderer,
|
||||
defaults: &Renderer::Defaults,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.explain(
|
||||
defaults,
|
||||
self.element.widget.as_ref(),
|
||||
layout,
|
||||
cursor_position,
|
||||
viewport,
|
||||
self.color,
|
||||
)
|
||||
_renderer: &mut Renderer,
|
||||
_defaults: &Renderer::Defaults,
|
||||
_layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) {
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
//! Position your widgets properly.
|
||||
mod debugger;
|
||||
mod limits;
|
||||
mod node;
|
||||
|
||||
pub mod flex;
|
||||
|
||||
pub use debugger::Debugger;
|
||||
pub use limits::Limits;
|
||||
pub use node::Node;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
use crate::{Color, Layout, Point, Rectangle, Renderer, Widget};
|
||||
|
||||
/// A renderer able to graphically explain a [`Layout`].
|
||||
pub trait Debugger: Renderer {
|
||||
/// Explains the [`Layout`] of an [`Element`] for debugging purposes.
|
||||
///
|
||||
/// This will be called when [`Element::explain`] has been used. It should
|
||||
/// _explain_ the given [`Layout`] graphically.
|
||||
///
|
||||
/// A common approach consists in recursively rendering the bounds of the
|
||||
/// [`Layout`] and its children.
|
||||
///
|
||||
/// [`Element`]: crate::Element
|
||||
/// [`Element::explain`]: crate::Element::explain
|
||||
fn explain<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
widget: &dyn Widget<Message, Self>,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
color: Color,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@
|
|||
//! [`druid`]: https://github.com/xi-editor/druid
|
||||
//! [`raw-window-handle`]: https://github.com/rust-windowing/raw-window-handle
|
||||
//! [renderer]: crate::renderer
|
||||
#![deny(missing_docs)]
|
||||
//#![deny(missing_docs)]
|
||||
#![deny(missing_debug_implementations)]
|
||||
#![deny(unused_results)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ where
|
|||
defaults: &Renderer::Defaults,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
) -> Renderer::Output;
|
||||
);
|
||||
|
||||
/// Computes the _layout_ hash of the [`Overlay`].
|
||||
///
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ where
|
|||
defaults: &Renderer::Defaults,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
) -> Renderer::Output {
|
||||
) {
|
||||
self.overlay
|
||||
.draw(renderer, defaults, layout, cursor_position)
|
||||
}
|
||||
|
|
@ -145,7 +145,7 @@ where
|
|||
defaults: &Renderer::Defaults,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
) -> Renderer::Output {
|
||||
) {
|
||||
self.content
|
||||
.draw(renderer, defaults, layout, cursor_position)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,21 +239,22 @@ where
|
|||
defaults: &Renderer::Defaults,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
) -> Renderer::Output {
|
||||
let primitives = self.container.draw(
|
||||
renderer,
|
||||
defaults,
|
||||
layout,
|
||||
cursor_position,
|
||||
&layout.bounds(),
|
||||
);
|
||||
) {
|
||||
// TODO
|
||||
// let primitives = self.container.draw(
|
||||
// renderer,
|
||||
// defaults,
|
||||
// layout,
|
||||
// cursor_position,
|
||||
// &layout.bounds(),
|
||||
// );
|
||||
|
||||
renderer.decorate(
|
||||
layout.bounds(),
|
||||
cursor_position,
|
||||
&self.style,
|
||||
primitives,
|
||||
)
|
||||
// renderer.decorate(
|
||||
// layout.bounds(),
|
||||
// cursor_position,
|
||||
// &self.style,
|
||||
// primitives,
|
||||
// )
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -378,24 +379,13 @@ where
|
|||
|
||||
fn draw(
|
||||
&self,
|
||||
renderer: &mut Renderer,
|
||||
_renderer: &mut Renderer,
|
||||
_defaults: &Renderer::Defaults,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
layout.bounds(),
|
||||
cursor_position,
|
||||
viewport,
|
||||
self.options,
|
||||
*self.hovered_option,
|
||||
self.padding,
|
||||
self.text_size.unwrap_or(renderer.default_size()),
|
||||
self.font,
|
||||
&self.style,
|
||||
)
|
||||
_layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -410,31 +400,6 @@ pub trait Renderer:
|
|||
{
|
||||
/// The [`Menu`] style supported by this renderer.
|
||||
type Style: Default + Clone;
|
||||
|
||||
/// Decorates a the list of options of a [`Menu`].
|
||||
///
|
||||
/// This method can be used to draw a background for the [`Menu`].
|
||||
fn decorate(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
cursor_position: Point,
|
||||
style: &<Self as Renderer>::Style,
|
||||
primitive: Self::Output,
|
||||
) -> Self::Output;
|
||||
|
||||
/// Draws the list of options of a [`Menu`].
|
||||
fn draw<T: ToString>(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
options: &[T],
|
||||
hovered_option: Option<usize>,
|
||||
padding: Padding,
|
||||
text_size: u16,
|
||||
font: Self::Font,
|
||||
style: &<Self as Renderer>::Style,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, T, Message, Renderer> Into<Element<'a, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
Cache, Clipboard, Command, Debug, Event, Point, Program, Renderer, Size,
|
||||
Cache, Clipboard, Command, Debug, Event, Point, Program, Size,
|
||||
UserInterface,
|
||||
};
|
||||
|
||||
|
|
@ -12,7 +12,6 @@ where
|
|||
{
|
||||
program: P,
|
||||
cache: Option<Cache>,
|
||||
primitive: <P::Renderer as Renderer>::Output,
|
||||
queued_events: Vec<Event>,
|
||||
queued_messages: Vec<P::Message>,
|
||||
}
|
||||
|
|
@ -38,16 +37,11 @@ where
|
|||
debug,
|
||||
);
|
||||
|
||||
debug.draw_started();
|
||||
let primitive = user_interface.draw(renderer, cursor_position);
|
||||
debug.draw_finished();
|
||||
|
||||
let cache = Some(user_interface.into_cache());
|
||||
|
||||
State {
|
||||
program,
|
||||
cache,
|
||||
primitive,
|
||||
queued_events: Vec::new(),
|
||||
queued_messages: Vec::new(),
|
||||
}
|
||||
|
|
@ -58,11 +52,6 @@ where
|
|||
&self.program
|
||||
}
|
||||
|
||||
/// Returns a reference to the current rendering primitive of the [`State`].
|
||||
pub fn primitive(&self) -> &<P::Renderer as Renderer>::Output {
|
||||
&self.primitive
|
||||
}
|
||||
|
||||
/// Queues an event in the [`State`] for processing during an [`update`].
|
||||
///
|
||||
/// [`update`]: Self::update
|
||||
|
|
@ -120,7 +109,7 @@ where
|
|||
|
||||
if messages.is_empty() {
|
||||
debug.draw_started();
|
||||
self.primitive = user_interface.draw(renderer, cursor_position);
|
||||
user_interface.draw(renderer, cursor_position);
|
||||
debug.draw_finished();
|
||||
|
||||
self.cache = Some(user_interface.into_cache());
|
||||
|
|
@ -151,7 +140,7 @@ where
|
|||
);
|
||||
|
||||
debug.draw_started();
|
||||
self.primitive = user_interface.draw(renderer, cursor_position);
|
||||
user_interface.draw(renderer, cursor_position);
|
||||
debug.draw_finished();
|
||||
|
||||
self.cache = Some(user_interface.into_cache());
|
||||
|
|
|
|||
|
|
@ -30,12 +30,6 @@ use crate::{layout, Element, Rectangle};
|
|||
/// A component that can take the state of a user interface and produce an
|
||||
/// output for its users.
|
||||
pub trait Renderer: Sized {
|
||||
/// The type of output of the [`Renderer`].
|
||||
///
|
||||
/// If you are implementing a graphical renderer, your output will most
|
||||
/// likely be a tree of visual primitives.
|
||||
type Output;
|
||||
|
||||
/// The default styling attributes of the [`Renderer`].
|
||||
///
|
||||
/// This type can be leveraged to implement style inheritance.
|
||||
|
|
@ -53,12 +47,5 @@ pub trait Renderer: Sized {
|
|||
element.layout(self, limits)
|
||||
}
|
||||
|
||||
/// Overlays the `overlay` output with the given bounds on top of the `base`
|
||||
/// output.
|
||||
fn overlay(
|
||||
&mut self,
|
||||
base: Self::Output,
|
||||
overlay: Self::Output,
|
||||
overlay_bounds: Rectangle,
|
||||
) -> Self::Output;
|
||||
fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,15 @@
|
|||
use crate::alignment;
|
||||
use crate::button;
|
||||
use crate::checkbox;
|
||||
use crate::column;
|
||||
use crate::container;
|
||||
use crate::pane_grid;
|
||||
use crate::progress_bar;
|
||||
use crate::radio;
|
||||
use crate::row;
|
||||
use crate::scrollable;
|
||||
use crate::slider;
|
||||
use crate::text;
|
||||
use crate::text_input;
|
||||
use crate::toggler;
|
||||
use crate::{
|
||||
Color, Element, Font, Layout, Padding, Point, Rectangle, Renderer, Size,
|
||||
};
|
||||
use crate::{Font, Padding, Point, Rectangle, Renderer, Size};
|
||||
|
||||
/// A renderer that does nothing.
|
||||
///
|
||||
|
|
@ -30,35 +25,9 @@ impl Null {
|
|||
}
|
||||
|
||||
impl Renderer for Null {
|
||||
type Output = ();
|
||||
type Defaults = ();
|
||||
|
||||
fn overlay(&mut self, _base: (), _overlay: (), _overlay_bounds: Rectangle) {
|
||||
}
|
||||
}
|
||||
|
||||
impl column::Renderer for Null {
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
_defaults: &Self::Defaults,
|
||||
_content: &[Element<'_, Message, Self>],
|
||||
_layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl row::Renderer for Null {
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
_defaults: &Self::Defaults,
|
||||
_content: &[Element<'_, Message, Self>],
|
||||
_layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) {
|
||||
}
|
||||
fn with_layer(&mut self, _bounds: Rectangle, _f: impl FnOnce(&mut Self)) {}
|
||||
}
|
||||
|
||||
impl text::Renderer for Null {
|
||||
|
|
@ -89,19 +58,6 @@ impl text::Renderer for Null {
|
|||
) -> Option<text::Hit> {
|
||||
None
|
||||
}
|
||||
|
||||
fn draw(
|
||||
&mut self,
|
||||
_defaults: &Self::Defaults,
|
||||
_bounds: Rectangle,
|
||||
_content: &str,
|
||||
_size: u16,
|
||||
_font: Font,
|
||||
_color: Option<Color>,
|
||||
_horizontal_alignment: alignment::Horizontal,
|
||||
_vertical_alignment: alignment::Vertical,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl scrollable::Renderer for Null {
|
||||
|
|
@ -118,20 +74,6 @@ impl scrollable::Renderer for Null {
|
|||
) -> Option<scrollable::Scrollbar> {
|
||||
None
|
||||
}
|
||||
|
||||
fn draw(
|
||||
&mut self,
|
||||
_scrollable: &scrollable::State,
|
||||
_bounds: Rectangle,
|
||||
_content_bounds: Rectangle,
|
||||
_is_mouse_over: bool,
|
||||
_is_mouse_over_scrollbar: bool,
|
||||
_scrollbar: Option<scrollable::Scrollbar>,
|
||||
_offset: u32,
|
||||
_style: &Self::Style,
|
||||
_content: Self::Output,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl text_input::Renderer for Null {
|
||||
|
|
@ -151,39 +93,12 @@ impl text_input::Renderer for Null {
|
|||
) -> f32 {
|
||||
0.0
|
||||
}
|
||||
|
||||
fn draw(
|
||||
&mut self,
|
||||
_bounds: Rectangle,
|
||||
_text_bounds: Rectangle,
|
||||
_cursor_position: Point,
|
||||
_font: Font,
|
||||
_size: u16,
|
||||
_placeholder: &str,
|
||||
_value: &text_input::Value,
|
||||
_state: &text_input::State,
|
||||
_style: &Self::Style,
|
||||
) -> Self::Output {
|
||||
}
|
||||
}
|
||||
|
||||
impl button::Renderer for Null {
|
||||
const DEFAULT_PADDING: Padding = Padding::ZERO;
|
||||
|
||||
type Style = ();
|
||||
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
_defaults: &Self::Defaults,
|
||||
_bounds: Rectangle,
|
||||
_cursor_position: Point,
|
||||
_is_disabled: bool,
|
||||
_is_pressed: bool,
|
||||
_style: &Self::Style,
|
||||
_content: &Element<'_, Message, Self>,
|
||||
_content_layout: Layout<'_>,
|
||||
) -> Self::Output {
|
||||
}
|
||||
}
|
||||
|
||||
impl radio::Renderer for Null {
|
||||
|
|
@ -191,16 +106,6 @@ impl radio::Renderer for Null {
|
|||
|
||||
const DEFAULT_SIZE: u16 = 20;
|
||||
const DEFAULT_SPACING: u16 = 15;
|
||||
|
||||
fn draw(
|
||||
&mut self,
|
||||
_bounds: Rectangle,
|
||||
_is_selected: bool,
|
||||
_is_mouse_over: bool,
|
||||
_label: Self::Output,
|
||||
_style: &Self::Style,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl checkbox::Renderer for Null {
|
||||
|
|
@ -208,122 +113,30 @@ impl checkbox::Renderer for Null {
|
|||
|
||||
const DEFAULT_SIZE: u16 = 20;
|
||||
const DEFAULT_SPACING: u16 = 15;
|
||||
|
||||
fn draw(
|
||||
&mut self,
|
||||
_bounds: Rectangle,
|
||||
_is_checked: bool,
|
||||
_is_mouse_over: bool,
|
||||
_label: Self::Output,
|
||||
_style: &Self::Style,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl slider::Renderer for Null {
|
||||
type Style = ();
|
||||
|
||||
const DEFAULT_HEIGHT: u16 = 30;
|
||||
|
||||
fn draw(
|
||||
&mut self,
|
||||
_bounds: Rectangle,
|
||||
_cursor_position: Point,
|
||||
_range: std::ops::RangeInclusive<f32>,
|
||||
_value: f32,
|
||||
_is_dragging: bool,
|
||||
_style_sheet: &Self::Style,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl progress_bar::Renderer for Null {
|
||||
type Style = ();
|
||||
|
||||
const DEFAULT_HEIGHT: u16 = 30;
|
||||
|
||||
fn draw(
|
||||
&self,
|
||||
_bounds: Rectangle,
|
||||
_range: std::ops::RangeInclusive<f32>,
|
||||
_value: f32,
|
||||
_style: &Self::Style,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl container::Renderer for Null {
|
||||
type Style = ();
|
||||
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
_defaults: &Self::Defaults,
|
||||
_bounds: Rectangle,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
_style: &Self::Style,
|
||||
_content: &Element<'_, Message, Self>,
|
||||
_content_layout: Layout<'_>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl pane_grid::Renderer for Null {
|
||||
type Style = ();
|
||||
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
_defaults: &Self::Defaults,
|
||||
_content: &[(pane_grid::Pane, pane_grid::Content<'_, Message, Self>)],
|
||||
_dragging: Option<(pane_grid::Pane, Point)>,
|
||||
_resizing: Option<(pane_grid::Axis, Rectangle, bool)>,
|
||||
_layout: Layout<'_>,
|
||||
_style: &<Self as pane_grid::Renderer>::Style,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) {
|
||||
}
|
||||
|
||||
fn draw_pane<Message>(
|
||||
&mut self,
|
||||
_defaults: &Self::Defaults,
|
||||
_bounds: Rectangle,
|
||||
_style: &<Self as container::Renderer>::Style,
|
||||
_title_bar: Option<(
|
||||
&pane_grid::TitleBar<'_, Message, Self>,
|
||||
Layout<'_>,
|
||||
)>,
|
||||
_body: (&Element<'_, Message, Self>, Layout<'_>),
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) {
|
||||
}
|
||||
|
||||
fn draw_title_bar<Message>(
|
||||
&mut self,
|
||||
_defaults: &Self::Defaults,
|
||||
_bounds: Rectangle,
|
||||
_style: &<Self as container::Renderer>::Style,
|
||||
_content: (&Element<'_, Message, Self>, Layout<'_>),
|
||||
_controls: Option<(&Element<'_, Message, Self>, Layout<'_>)>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl toggler::Renderer for Null {
|
||||
type Style = ();
|
||||
|
||||
const DEFAULT_SIZE: u16 = 20;
|
||||
|
||||
fn draw(
|
||||
&mut self,
|
||||
_bounds: Rectangle,
|
||||
_is_checked: bool,
|
||||
_is_mouse_over: bool,
|
||||
_label: Option<Self::Output>,
|
||||
_style: &Self::Style,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -329,11 +329,7 @@ where
|
|||
/// // Flush rendering operations...
|
||||
/// }
|
||||
/// ```
|
||||
pub fn draw(
|
||||
&mut self,
|
||||
renderer: &mut Renderer,
|
||||
cursor_position: Point,
|
||||
) -> Renderer::Output {
|
||||
pub fn draw(&mut self, renderer: &mut Renderer, cursor_position: Point) {
|
||||
let viewport = Rectangle::with_size(self.bounds);
|
||||
|
||||
let overlay = if let Some(mut overlay) =
|
||||
|
|
@ -348,40 +344,36 @@ where
|
|||
|
||||
let overlay_bounds = layer.layout.bounds();
|
||||
|
||||
let overlay_primitives = overlay.draw(
|
||||
renderer,
|
||||
&Renderer::Defaults::default(),
|
||||
Layout::new(&layer.layout),
|
||||
cursor_position,
|
||||
);
|
||||
renderer.with_layer(overlay_bounds, |renderer| {
|
||||
overlay.draw(
|
||||
renderer,
|
||||
&Renderer::Defaults::default(),
|
||||
Layout::new(&layer.layout),
|
||||
cursor_position,
|
||||
);
|
||||
});
|
||||
|
||||
self.overlay = Some(layer);
|
||||
|
||||
Some((overlay_primitives, overlay_bounds))
|
||||
Some(overlay_bounds)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some((overlay_primitives, overlay_bounds)) = overlay {
|
||||
if let Some(overlay_bounds) = overlay {
|
||||
let base_cursor = if overlay_bounds.contains(cursor_position) {
|
||||
Point::new(-1.0, -1.0)
|
||||
} else {
|
||||
cursor_position
|
||||
};
|
||||
|
||||
let base_primitives = self.root.widget.draw(
|
||||
self.root.widget.draw(
|
||||
renderer,
|
||||
&Renderer::Defaults::default(),
|
||||
Layout::new(&self.base.layout),
|
||||
base_cursor,
|
||||
&viewport,
|
||||
);
|
||||
|
||||
renderer.overlay(
|
||||
base_primitives,
|
||||
overlay_primitives,
|
||||
overlay_bounds,
|
||||
)
|
||||
} else {
|
||||
self.root.widget.draw(
|
||||
renderer,
|
||||
|
|
@ -389,7 +381,7 @@ where
|
|||
Layout::new(&self.base.layout),
|
||||
cursor_position,
|
||||
&viewport,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output;
|
||||
);
|
||||
|
||||
/// Computes the _layout_ hash of the [`Widget`].
|
||||
///
|
||||
|
|
|
|||
|
|
@ -248,17 +248,7 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.draw(
|
||||
defaults,
|
||||
layout.bounds(),
|
||||
cursor_position,
|
||||
self.on_press.is_none(),
|
||||
self.state.is_pressed,
|
||||
&self.style,
|
||||
&self.content,
|
||||
layout.children().next().unwrap(),
|
||||
)
|
||||
) {
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -289,19 +279,6 @@ pub trait Renderer: crate::Renderer + Sized {
|
|||
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// Draws a [`Button`].
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
bounds: Rectangle,
|
||||
cursor_position: Point,
|
||||
is_disabled: bool,
|
||||
is_pressed: bool,
|
||||
style: &Self::Style,
|
||||
content: &Element<'_, Message, Self>,
|
||||
content_layout: Layout<'_>,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Button<'a, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ use crate::alignment::{self, Alignment};
|
|||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::row;
|
||||
use crate::text;
|
||||
use crate::touch;
|
||||
use crate::{
|
||||
|
|
@ -121,7 +120,7 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
|
|||
impl<Message, Renderer> Widget<Message, Renderer>
|
||||
for Checkbox<Message, Renderer>
|
||||
where
|
||||
Renderer: self::Renderer + text::Renderer + row::Renderer,
|
||||
Renderer: self::Renderer + text::Renderer,
|
||||
{
|
||||
fn width(&self) -> Length {
|
||||
self.width
|
||||
|
|
@ -187,36 +186,29 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
let bounds = layout.bounds();
|
||||
let mut children = layout.children();
|
||||
) {
|
||||
// let bounds = layout.bounds();
|
||||
// let mut children = layout.children();
|
||||
|
||||
let checkbox_layout = children.next().unwrap();
|
||||
let label_layout = children.next().unwrap();
|
||||
let checkbox_bounds = checkbox_layout.bounds();
|
||||
// let checkbox_layout = children.next().unwrap();
|
||||
// let label_layout = children.next().unwrap();
|
||||
// let checkbox_bounds = checkbox_layout.bounds();
|
||||
|
||||
let label = text::Renderer::draw(
|
||||
renderer,
|
||||
defaults,
|
||||
label_layout.bounds(),
|
||||
&self.label,
|
||||
self.text_size.unwrap_or(renderer.default_size()),
|
||||
self.font,
|
||||
self.text_color,
|
||||
alignment::Horizontal::Left,
|
||||
alignment::Vertical::Center,
|
||||
);
|
||||
// let label = text::Renderer::draw(
|
||||
// renderer,
|
||||
// defaults,
|
||||
// label_layout.bounds(),
|
||||
// &self.label,
|
||||
// self.text_size.unwrap_or(renderer.default_size()),
|
||||
// self.font,
|
||||
// self.text_color,
|
||||
// alignment::Horizontal::Left,
|
||||
// alignment::Vertical::Center,
|
||||
// );
|
||||
|
||||
let is_mouse_over = bounds.contains(cursor_position);
|
||||
// let is_mouse_over = bounds.contains(cursor_position);
|
||||
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
checkbox_bounds,
|
||||
self.is_checked,
|
||||
is_mouse_over,
|
||||
label,
|
||||
&self.style,
|
||||
)
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -242,28 +234,12 @@ pub trait Renderer: crate::Renderer {
|
|||
|
||||
/// The default spacing of a [`Checkbox`].
|
||||
const DEFAULT_SPACING: u16;
|
||||
|
||||
/// Draws a [`Checkbox`].
|
||||
///
|
||||
/// It receives:
|
||||
/// * the bounds of the [`Checkbox`]
|
||||
/// * whether the [`Checkbox`] is selected or not
|
||||
/// * whether the mouse is over the [`Checkbox`] or not
|
||||
/// * the drawn label of the [`Checkbox`]
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
is_checked: bool,
|
||||
is_mouse_over: bool,
|
||||
label: Self::Output,
|
||||
style: &Self::Style,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Checkbox<Message, Renderer>>
|
||||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: 'a + self::Renderer + text::Renderer + row::Renderer,
|
||||
Renderer: 'a + self::Renderer + text::Renderer,
|
||||
Message: 'a,
|
||||
{
|
||||
fn from(
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
|||
impl<'a, Message, Renderer> Widget<Message, Renderer>
|
||||
for Column<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: self::Renderer,
|
||||
Renderer: crate::Renderer,
|
||||
{
|
||||
fn width(&self) -> Length {
|
||||
self.width
|
||||
|
|
@ -169,14 +169,8 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.draw(
|
||||
defaults,
|
||||
&self.children,
|
||||
layout,
|
||||
cursor_position,
|
||||
viewport,
|
||||
)
|
||||
) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -208,33 +202,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// The renderer of a [`Column`].
|
||||
///
|
||||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Column`] in your user interface.
|
||||
///
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer + Sized {
|
||||
/// Draws a [`Column`].
|
||||
///
|
||||
/// It receives:
|
||||
/// - the children of the [`Column`]
|
||||
/// - the [`Layout`] of the [`Column`] and its children
|
||||
/// - the cursor position
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
content: &[Element<'_, Message, Self>],
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Column<'a, Message, Renderer>>
|
||||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: 'a + self::Renderer,
|
||||
Renderer: 'a + crate::Renderer,
|
||||
Message: 'a,
|
||||
{
|
||||
fn from(
|
||||
|
|
|
|||
|
|
@ -179,16 +179,8 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.draw(
|
||||
defaults,
|
||||
layout.bounds(),
|
||||
cursor_position,
|
||||
viewport,
|
||||
&self.style,
|
||||
&self.content,
|
||||
layout.children().next().unwrap(),
|
||||
)
|
||||
) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -221,18 +213,6 @@ where
|
|||
pub trait Renderer: crate::Renderer {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// Draws a [`Container`].
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
bounds: Rectangle,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
style: &Self::Style,
|
||||
content: &Element<'_, Message, Self>,
|
||||
content_layout: Layout<'_>,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Container<'a, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -96,8 +96,8 @@ where
|
|||
layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.draw(self.handle.clone(), layout)
|
||||
) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -225,9 +225,6 @@ impl std::fmt::Debug for Data {
|
|||
pub trait Renderer: crate::Renderer {
|
||||
/// Returns the dimensions of an [`Image`] located on the given path.
|
||||
fn dimensions(&self, handle: &Handle) -> (u32, u32);
|
||||
|
||||
/// Draws an [`Image`].
|
||||
fn draw(&mut self, handle: Handle, layout: Layout<'_>) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Image> for Element<'a, Message, Renderer>
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ impl<'a> Viewer<'a> {
|
|||
/// will be respected.
|
||||
fn image_size<Renderer>(&self, renderer: &Renderer, bounds: Size) -> Size
|
||||
where
|
||||
Renderer: self::Renderer + image::Renderer,
|
||||
Renderer: image::Renderer,
|
||||
{
|
||||
let (width, height) = renderer.dimensions(&self.handle);
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ impl<'a> Viewer<'a> {
|
|||
|
||||
impl<'a, Message, Renderer> Widget<Message, Renderer> for Viewer<'a>
|
||||
where
|
||||
Renderer: self::Renderer + image::Renderer,
|
||||
Renderer: image::Renderer,
|
||||
{
|
||||
fn width(&self) -> Length {
|
||||
self.width
|
||||
|
|
@ -287,7 +287,7 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
) {
|
||||
let bounds = layout.bounds();
|
||||
|
||||
let image_size = self.image_size(renderer, bounds.size());
|
||||
|
|
@ -302,16 +302,6 @@ where
|
|||
};
|
||||
|
||||
let is_mouse_over = bounds.contains(cursor_position);
|
||||
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
&self.state,
|
||||
bounds,
|
||||
image_size,
|
||||
translation,
|
||||
self.handle.clone(),
|
||||
is_mouse_over,
|
||||
)
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -373,38 +363,9 @@ impl State {
|
|||
}
|
||||
}
|
||||
|
||||
/// The renderer of an [`Viewer`].
|
||||
///
|
||||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Viewer`] in your user interface.
|
||||
///
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer + Sized {
|
||||
/// Draws the [`Viewer`].
|
||||
///
|
||||
/// It receives:
|
||||
/// - the [`State`] of the [`Viewer`]
|
||||
/// - the bounds of the [`Viewer`] widget
|
||||
/// - the [`Size`] of the scaled [`Viewer`] image
|
||||
/// - the translation of the clipped image
|
||||
/// - the [`Handle`] to the underlying image
|
||||
/// - whether the mouse is over the [`Viewer`] or not
|
||||
///
|
||||
/// [`Handle`]: image::Handle
|
||||
fn draw(
|
||||
&mut self,
|
||||
state: &State,
|
||||
bounds: Rectangle,
|
||||
image_size: Size,
|
||||
translation: Vector,
|
||||
handle: image::Handle,
|
||||
is_mouse_over: bool,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Viewer<'a>> for Element<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: 'a + self::Renderer + image::Renderer,
|
||||
Renderer: 'a + image::Renderer,
|
||||
Message: 'a,
|
||||
{
|
||||
fn from(viewer: Viewer<'a>) -> Element<'a, Message, Renderer> {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ use crate::event::{self, Event};
|
|||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::overlay;
|
||||
use crate::row;
|
||||
use crate::touch;
|
||||
use crate::{
|
||||
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Vector,
|
||||
|
|
@ -480,66 +479,56 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
let picked_split = self
|
||||
.state
|
||||
.picked_split()
|
||||
.and_then(|(split, axis)| {
|
||||
let bounds = layout.bounds();
|
||||
) {
|
||||
// let picked_split = self
|
||||
// .state
|
||||
// .picked_split()
|
||||
// .and_then(|(split, axis)| {
|
||||
// let bounds = layout.bounds();
|
||||
|
||||
let splits = self
|
||||
.state
|
||||
.split_regions(f32::from(self.spacing), bounds.size());
|
||||
// let splits = self
|
||||
// .state
|
||||
// .split_regions(f32::from(self.spacing), bounds.size());
|
||||
|
||||
let (_axis, region, ratio) = splits.get(&split)?;
|
||||
// let (_axis, region, ratio) = splits.get(&split)?;
|
||||
|
||||
let region = axis.split_line_bounds(
|
||||
*region,
|
||||
*ratio,
|
||||
f32::from(self.spacing),
|
||||
);
|
||||
// let region = axis.split_line_bounds(
|
||||
// *region,
|
||||
// *ratio,
|
||||
// f32::from(self.spacing),
|
||||
// );
|
||||
|
||||
Some((axis, region + Vector::new(bounds.x, bounds.y), true))
|
||||
})
|
||||
.or_else(|| match self.on_resize {
|
||||
Some((leeway, _)) => {
|
||||
let bounds = layout.bounds();
|
||||
// Some((axis, region + Vector::new(bounds.x, bounds.y), true))
|
||||
// })
|
||||
// .or_else(|| match self.on_resize {
|
||||
// Some((leeway, _)) => {
|
||||
// let bounds = layout.bounds();
|
||||
|
||||
let relative_cursor = Point::new(
|
||||
cursor_position.x - bounds.x,
|
||||
cursor_position.y - bounds.y,
|
||||
);
|
||||
// let relative_cursor = Point::new(
|
||||
// cursor_position.x - bounds.x,
|
||||
// cursor_position.y - bounds.y,
|
||||
// );
|
||||
|
||||
let splits = self
|
||||
.state
|
||||
.split_regions(f32::from(self.spacing), bounds.size());
|
||||
// let splits = self
|
||||
// .state
|
||||
// .split_regions(f32::from(self.spacing), bounds.size());
|
||||
|
||||
let (_split, axis, region) = hovered_split(
|
||||
splits.iter(),
|
||||
f32::from(self.spacing + leeway),
|
||||
relative_cursor,
|
||||
)?;
|
||||
// let (_split, axis, region) = hovered_split(
|
||||
// splits.iter(),
|
||||
// f32::from(self.spacing + leeway),
|
||||
// relative_cursor,
|
||||
// )?;
|
||||
|
||||
Some((
|
||||
axis,
|
||||
region + Vector::new(bounds.x, bounds.y),
|
||||
false,
|
||||
))
|
||||
}
|
||||
None => None,
|
||||
});
|
||||
// Some((
|
||||
// axis,
|
||||
// region + Vector::new(bounds.x, bounds.y),
|
||||
// false,
|
||||
// ))
|
||||
// }
|
||||
// None => None,
|
||||
// });
|
||||
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
defaults,
|
||||
&self.elements,
|
||||
self.state.picked_pane(),
|
||||
picked_split,
|
||||
layout,
|
||||
&self.style,
|
||||
cursor_position,
|
||||
viewport,
|
||||
)
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -578,69 +567,12 @@ where
|
|||
pub trait Renderer: crate::Renderer + container::Renderer + Sized {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// Draws a [`PaneGrid`].
|
||||
///
|
||||
/// It receives:
|
||||
/// - the elements of the [`PaneGrid`]
|
||||
/// - the [`Pane`] that is currently being dragged
|
||||
/// - the [`Axis`] that is currently being resized
|
||||
/// - the [`Layout`] of the [`PaneGrid`] and its elements
|
||||
/// - the cursor position
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
content: &[(Pane, Content<'_, Message, Self>)],
|
||||
dragging: Option<(Pane, Point)>,
|
||||
resizing: Option<(Axis, Rectangle, bool)>,
|
||||
layout: Layout<'_>,
|
||||
style: &<Self as self::Renderer>::Style,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Self::Output;
|
||||
|
||||
/// Draws a [`Pane`].
|
||||
///
|
||||
/// It receives:
|
||||
/// - the [`TitleBar`] of the [`Pane`], if any
|
||||
/// - the [`Content`] of the [`Pane`]
|
||||
/// - the [`Layout`] of the [`Pane`] and its elements
|
||||
/// - the cursor position
|
||||
fn draw_pane<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
bounds: Rectangle,
|
||||
style: &<Self as container::Renderer>::Style,
|
||||
title_bar: Option<(&TitleBar<'_, Message, Self>, Layout<'_>)>,
|
||||
body: (&Element<'_, Message, Self>, Layout<'_>),
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Self::Output;
|
||||
|
||||
/// Draws a [`TitleBar`].
|
||||
///
|
||||
/// It receives:
|
||||
/// - the bounds, style of the [`TitleBar`]
|
||||
/// - the style of the [`TitleBar`]
|
||||
/// - the content of the [`TitleBar`] with its layout
|
||||
/// - the controls of the [`TitleBar`] with their [`Layout`], if any
|
||||
/// - the cursor position
|
||||
fn draw_title_bar<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
bounds: Rectangle,
|
||||
style: &<Self as container::Renderer>::Style,
|
||||
content: (&Element<'_, Message, Self>, Layout<'_>),
|
||||
controls: Option<(&Element<'_, Message, Self>, Layout<'_>)>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<PaneGrid<'a, Message, Renderer>>
|
||||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: 'a + self::Renderer + row::Renderer,
|
||||
Renderer: 'a + self::Renderer,
|
||||
Message: 'a,
|
||||
{
|
||||
fn from(
|
||||
|
|
|
|||
|
|
@ -61,32 +61,33 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
if let Some(title_bar) = &self.title_bar {
|
||||
let mut children = layout.children();
|
||||
let title_bar_layout = children.next().unwrap();
|
||||
let body_layout = children.next().unwrap();
|
||||
) {
|
||||
// TODO
|
||||
// if let Some(title_bar) = &self.title_bar {
|
||||
// let mut children = layout.children();
|
||||
// let title_bar_layout = children.next().unwrap();
|
||||
// let body_layout = children.next().unwrap();
|
||||
|
||||
renderer.draw_pane(
|
||||
defaults,
|
||||
layout.bounds(),
|
||||
&self.style,
|
||||
Some((title_bar, title_bar_layout)),
|
||||
(&self.body, body_layout),
|
||||
cursor_position,
|
||||
viewport,
|
||||
)
|
||||
} else {
|
||||
renderer.draw_pane(
|
||||
defaults,
|
||||
layout.bounds(),
|
||||
&self.style,
|
||||
None,
|
||||
(&self.body, layout),
|
||||
cursor_position,
|
||||
viewport,
|
||||
)
|
||||
}
|
||||
// renderer.draw_pane(
|
||||
// defaults,
|
||||
// layout.bounds(),
|
||||
// &self.style,
|
||||
// Some((title_bar, title_bar_layout)),
|
||||
// (&self.body, body_layout),
|
||||
// cursor_position,
|
||||
// viewport,
|
||||
// )
|
||||
// } else {
|
||||
// renderer.draw_pane(
|
||||
// defaults,
|
||||
// layout.bounds(),
|
||||
// &self.style,
|
||||
// None,
|
||||
// (&self.body, layout),
|
||||
// cursor_position,
|
||||
// viewport,
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
/// Returns whether the [`Content`] with the given [`Layout`] can be picked
|
||||
|
|
|
|||
|
|
@ -90,34 +90,34 @@ where
|
|||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
show_controls: bool,
|
||||
) -> Renderer::Output {
|
||||
let mut children = layout.children();
|
||||
let padded = children.next().unwrap();
|
||||
) {
|
||||
// let mut children = layout.children();
|
||||
// let padded = children.next().unwrap();
|
||||
|
||||
let mut children = padded.children();
|
||||
let title_layout = children.next().unwrap();
|
||||
// let mut children = padded.children();
|
||||
// let title_layout = children.next().unwrap();
|
||||
|
||||
let controls = if let Some(controls) = &self.controls {
|
||||
let controls_layout = children.next().unwrap();
|
||||
// let controls = if let Some(controls) = &self.controls {
|
||||
// let controls_layout = children.next().unwrap();
|
||||
|
||||
if show_controls || self.always_show_controls {
|
||||
Some((controls, controls_layout))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
// if show_controls || self.always_show_controls {
|
||||
// Some((controls, controls_layout))
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// } else {
|
||||
// None
|
||||
// };
|
||||
|
||||
renderer.draw_title_bar(
|
||||
defaults,
|
||||
layout.bounds(),
|
||||
&self.style,
|
||||
(&self.content, title_layout),
|
||||
controls,
|
||||
cursor_position,
|
||||
viewport,
|
||||
)
|
||||
// renderer.draw_title_bar(
|
||||
// defaults,
|
||||
// layout.bounds(),
|
||||
// &self.style,
|
||||
// (&self.content, title_layout),
|
||||
// controls,
|
||||
// cursor_position,
|
||||
// viewport,
|
||||
// )
|
||||
}
|
||||
|
||||
/// Returns whether the mouse cursor is over the pick area of the
|
||||
|
|
|
|||
|
|
@ -327,18 +327,8 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
layout.bounds(),
|
||||
cursor_position,
|
||||
self.selected.as_ref().map(ToString::to_string),
|
||||
self.placeholder.as_ref().map(String::as_str),
|
||||
self.padding,
|
||||
self.text_size.unwrap_or(renderer.default_size()),
|
||||
self.font,
|
||||
&self.style,
|
||||
)
|
||||
) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn overlay(
|
||||
|
|
@ -387,19 +377,6 @@ pub trait Renderer: text::Renderer + menu::Renderer {
|
|||
fn menu_style(
|
||||
style: &<Self as Renderer>::Style,
|
||||
) -> <Self as menu::Renderer>::Style;
|
||||
|
||||
/// Draws a [`PickList`].
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
cursor_position: Point,
|
||||
selected: Option<String>,
|
||||
placeholder: Option<&str>,
|
||||
padding: Padding,
|
||||
text_size: u16,
|
||||
font: Self::Font,
|
||||
style: &<Self as Renderer>::Style,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, T: 'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -97,13 +97,8 @@ where
|
|||
layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.draw(
|
||||
layout.bounds(),
|
||||
self.range.clone(),
|
||||
self.value,
|
||||
&self.style,
|
||||
)
|
||||
) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -127,22 +122,6 @@ pub trait Renderer: crate::Renderer {
|
|||
|
||||
/// The default height of a [`ProgressBar`].
|
||||
const DEFAULT_HEIGHT: u16;
|
||||
|
||||
/// Draws a [`ProgressBar`].
|
||||
///
|
||||
/// It receives:
|
||||
/// * the bounds of the [`ProgressBar`]
|
||||
/// * the range of values of the [`ProgressBar`]
|
||||
/// * the current value of the [`ProgressBar`]
|
||||
/// * maybe a specific background of the [`ProgressBar`]
|
||||
/// * maybe a specific active color of the [`ProgressBar`]
|
||||
fn draw(
|
||||
&self,
|
||||
bounds: Rectangle,
|
||||
range: RangeInclusive<f32>,
|
||||
value: f32,
|
||||
style: &Self::Style,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<ProgressBar<Renderer>>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ use crate::alignment::{self, Alignment};
|
|||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::row;
|
||||
use crate::text;
|
||||
use crate::touch;
|
||||
use crate::{
|
||||
|
|
@ -136,7 +135,7 @@ where
|
|||
impl<Message, Renderer> Widget<Message, Renderer> for Radio<Message, Renderer>
|
||||
where
|
||||
Message: Clone,
|
||||
Renderer: self::Renderer + text::Renderer + row::Renderer,
|
||||
Renderer: self::Renderer + text::Renderer,
|
||||
{
|
||||
fn width(&self) -> Length {
|
||||
self.width
|
||||
|
|
@ -199,36 +198,37 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
let bounds = layout.bounds();
|
||||
let mut children = layout.children();
|
||||
) {
|
||||
// TODO
|
||||
// let bounds = layout.bounds();
|
||||
// let mut children = layout.children();
|
||||
|
||||
let radio_layout = children.next().unwrap();
|
||||
let label_layout = children.next().unwrap();
|
||||
let radio_bounds = radio_layout.bounds();
|
||||
// let radio_layout = children.next().unwrap();
|
||||
// let label_layout = children.next().unwrap();
|
||||
// let radio_bounds = radio_layout.bounds();
|
||||
|
||||
let label = text::Renderer::draw(
|
||||
renderer,
|
||||
defaults,
|
||||
label_layout.bounds(),
|
||||
&self.label,
|
||||
self.text_size.unwrap_or(renderer.default_size()),
|
||||
self.font,
|
||||
self.text_color,
|
||||
alignment::Horizontal::Left,
|
||||
alignment::Vertical::Center,
|
||||
);
|
||||
// let label = text::Renderer::draw(
|
||||
// renderer,
|
||||
// defaults,
|
||||
// label_layout.bounds(),
|
||||
// &self.label,
|
||||
// self.text_size.unwrap_or(renderer.default_size()),
|
||||
// self.font,
|
||||
// self.text_color,
|
||||
// alignment::Horizontal::Left,
|
||||
// alignment::Vertical::Center,
|
||||
// );
|
||||
|
||||
let is_mouse_over = bounds.contains(cursor_position);
|
||||
// let is_mouse_over = bounds.contains(cursor_position);
|
||||
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
radio_bounds,
|
||||
self.is_selected,
|
||||
is_mouse_over,
|
||||
label,
|
||||
&self.style,
|
||||
)
|
||||
// self::Renderer::draw(
|
||||
// renderer,
|
||||
// radio_bounds,
|
||||
// self.is_selected,
|
||||
// is_mouse_over,
|
||||
// label,
|
||||
// &self.style,
|
||||
// )
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -254,29 +254,13 @@ pub trait Renderer: crate::Renderer {
|
|||
|
||||
/// The default spacing of a [`Radio`] button.
|
||||
const DEFAULT_SPACING: u16;
|
||||
|
||||
/// Draws a [`Radio`] button.
|
||||
///
|
||||
/// It receives:
|
||||
/// * the bounds of the [`Radio`]
|
||||
/// * whether the [`Radio`] is selected or not
|
||||
/// * whether the mouse is over the [`Radio`] or not
|
||||
/// * the drawn label of the [`Radio`]
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
is_selected: bool,
|
||||
is_mouse_over: bool,
|
||||
label: Self::Output,
|
||||
style: &Self::Style,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Radio<Message, Renderer>>
|
||||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Message: 'a + Clone,
|
||||
Renderer: 'a + self::Renderer + row::Renderer + text::Renderer,
|
||||
Renderer: 'a + self::Renderer + text::Renderer,
|
||||
{
|
||||
fn from(radio: Radio<Message, Renderer>) -> Element<'a, Message, Renderer> {
|
||||
Element::new(radio)
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
|
|||
impl<'a, Message, Renderer> Widget<Message, Renderer>
|
||||
for Row<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: self::Renderer,
|
||||
Renderer: crate::Renderer,
|
||||
{
|
||||
fn width(&self) -> Length {
|
||||
self.width
|
||||
|
|
@ -168,14 +168,15 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.draw(
|
||||
defaults,
|
||||
&self.children,
|
||||
layout,
|
||||
cursor_position,
|
||||
viewport,
|
||||
)
|
||||
) {
|
||||
// TODO
|
||||
// renderer.draw(
|
||||
// defaults,
|
||||
// &self.children,
|
||||
// layout,
|
||||
// cursor_position,
|
||||
// viewport,
|
||||
// )
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -207,33 +208,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// The renderer of a [`Row`].
|
||||
///
|
||||
/// Your [renderer] will need to implement this trait before being
|
||||
/// able to use a [`Row`] in your user interface.
|
||||
///
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: crate::Renderer + Sized {
|
||||
/// Draws a [`Row`].
|
||||
///
|
||||
/// It receives:
|
||||
/// - the children of the [`Row`]
|
||||
/// - the [`Layout`] of the [`Row`] and its children
|
||||
/// - the cursor position
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
children: &[Element<'_, Message, Self>],
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Row<'a, Message, Renderer>>
|
||||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: 'a + self::Renderer,
|
||||
Renderer: 'a + crate::Renderer,
|
||||
Message: 'a,
|
||||
{
|
||||
fn from(row: Row<'a, Message, Renderer>) -> Element<'a, Message, Renderer> {
|
||||
|
|
|
|||
|
|
@ -72,8 +72,9 @@ where
|
|||
layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.draw(layout.bounds(), &self.style, self.is_horizontal)
|
||||
) {
|
||||
// TODO
|
||||
// renderer.draw(layout.bounds(), &self.style, self.is_horizontal)
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -89,19 +90,6 @@ where
|
|||
pub trait Renderer: crate::Renderer {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
/// Draws a [`Rule`].
|
||||
///
|
||||
/// It receives:
|
||||
/// * the bounds of the [`Rule`]
|
||||
/// * the style of the [`Rule`]
|
||||
/// * whether the [`Rule`] is horizontal (true) or vertical (false)
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
style: &Self::Style,
|
||||
is_horizontal: bool,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Rule<Renderer>>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
//! Navigate an endless amount of content with a scrollbar.
|
||||
use crate::column;
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
|
|
@ -381,57 +380,45 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
let bounds = layout.bounds();
|
||||
let content_layout = layout.children().next().unwrap();
|
||||
let content_bounds = content_layout.bounds();
|
||||
let offset = self.state.offset(bounds, content_bounds);
|
||||
let scrollbar = renderer.scrollbar(
|
||||
bounds,
|
||||
content_bounds,
|
||||
offset,
|
||||
self.scrollbar_width,
|
||||
self.scrollbar_margin,
|
||||
self.scroller_width,
|
||||
);
|
||||
) {
|
||||
// TODO
|
||||
// let bounds = layout.bounds();
|
||||
// let content_layout = layout.children().next().unwrap();
|
||||
// let content_bounds = content_layout.bounds();
|
||||
// let offset = self.state.offset(bounds, content_bounds);
|
||||
// let scrollbar = renderer.scrollbar(
|
||||
// bounds,
|
||||
// content_bounds,
|
||||
// offset,
|
||||
// self.scrollbar_width,
|
||||
// self.scrollbar_margin,
|
||||
// self.scroller_width,
|
||||
// );
|
||||
|
||||
let is_mouse_over = bounds.contains(cursor_position);
|
||||
let is_mouse_over_scrollbar = scrollbar
|
||||
.as_ref()
|
||||
.map(|scrollbar| scrollbar.is_mouse_over(cursor_position))
|
||||
.unwrap_or(false);
|
||||
// let is_mouse_over = bounds.contains(cursor_position);
|
||||
// let is_mouse_over_scrollbar = scrollbar
|
||||
// .as_ref()
|
||||
// .map(|scrollbar| scrollbar.is_mouse_over(cursor_position))
|
||||
// .unwrap_or(false);
|
||||
|
||||
let content = {
|
||||
let cursor_position = if is_mouse_over && !is_mouse_over_scrollbar {
|
||||
Point::new(cursor_position.x, cursor_position.y + offset as f32)
|
||||
} else {
|
||||
Point::new(cursor_position.x, -1.0)
|
||||
};
|
||||
// let content = {
|
||||
// let cursor_position = if is_mouse_over && !is_mouse_over_scrollbar {
|
||||
// Point::new(cursor_position.x, cursor_position.y + offset as f32)
|
||||
// } else {
|
||||
// Point::new(cursor_position.x, -1.0)
|
||||
// };
|
||||
|
||||
self.content.draw(
|
||||
renderer,
|
||||
defaults,
|
||||
content_layout,
|
||||
cursor_position,
|
||||
&Rectangle {
|
||||
y: bounds.y + offset as f32,
|
||||
..bounds
|
||||
},
|
||||
)
|
||||
};
|
||||
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
&self.state,
|
||||
bounds,
|
||||
content_layout.bounds(),
|
||||
is_mouse_over,
|
||||
is_mouse_over_scrollbar,
|
||||
scrollbar,
|
||||
offset,
|
||||
&self.style,
|
||||
content,
|
||||
)
|
||||
// self.content.draw(
|
||||
// renderer,
|
||||
// defaults,
|
||||
// content_layout,
|
||||
// cursor_position,
|
||||
// &Rectangle {
|
||||
// y: bounds.y + offset as f32,
|
||||
// ..bounds
|
||||
// },
|
||||
// )
|
||||
// };
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -635,7 +622,7 @@ pub struct Scroller {
|
|||
/// able to use a [`Scrollable`] in your user interface.
|
||||
///
|
||||
/// [renderer]: crate::renderer
|
||||
pub trait Renderer: column::Renderer + Sized {
|
||||
pub trait Renderer: crate::Renderer + Sized {
|
||||
/// The style supported by this renderer.
|
||||
type Style: Default;
|
||||
|
||||
|
|
@ -650,30 +637,6 @@ pub trait Renderer: column::Renderer + Sized {
|
|||
scrollbar_margin: u16,
|
||||
scroller_width: u16,
|
||||
) -> Option<Scrollbar>;
|
||||
|
||||
/// Draws the [`Scrollable`].
|
||||
///
|
||||
/// It receives:
|
||||
/// - the [`State`] of the [`Scrollable`]
|
||||
/// - the bounds of the [`Scrollable`] widget
|
||||
/// - the bounds of the [`Scrollable`] content
|
||||
/// - whether the mouse is over the [`Scrollable`] or not
|
||||
/// - whether the mouse is over the [`Scrollbar`] or not
|
||||
/// - a optional [`Scrollbar`] to be rendered
|
||||
/// - the scrolling offset
|
||||
/// - the drawn content
|
||||
fn draw(
|
||||
&mut self,
|
||||
scrollable: &State,
|
||||
bounds: Rectangle,
|
||||
content_bounds: Rectangle,
|
||||
is_mouse_over: bool,
|
||||
is_mouse_over_scrollbar: bool,
|
||||
scrollbar: Option<Scrollbar>,
|
||||
offset: u32,
|
||||
style: &Self::Style,
|
||||
content: Self::Output,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Scrollable<'a, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -250,18 +250,19 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
let start = *self.range.start();
|
||||
let end = *self.range.end();
|
||||
) {
|
||||
// TODO
|
||||
// let start = *self.range.start();
|
||||
// let end = *self.range.end();
|
||||
|
||||
renderer.draw(
|
||||
layout.bounds(),
|
||||
cursor_position,
|
||||
start.into() as f32..=end.into() as f32,
|
||||
self.value.into() as f32,
|
||||
self.state.is_dragging,
|
||||
&self.style,
|
||||
)
|
||||
// renderer.draw(
|
||||
// layout.bounds(),
|
||||
// cursor_position,
|
||||
// start.into() as f32..=end.into() as f32,
|
||||
// self.value.into() as f32,
|
||||
// self.state.is_dragging,
|
||||
// &self.style,
|
||||
// )
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -284,24 +285,6 @@ pub trait Renderer: crate::Renderer {
|
|||
|
||||
/// The default height of a [`Slider`].
|
||||
const DEFAULT_HEIGHT: u16;
|
||||
|
||||
/// Draws a [`Slider`].
|
||||
///
|
||||
/// It receives:
|
||||
/// * the current cursor position
|
||||
/// * the bounds of the [`Slider`]
|
||||
/// * the local state of the [`Slider`]
|
||||
/// * the range of values of the [`Slider`]
|
||||
/// * the current value of the [`Slider`]
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
cursor_position: Point,
|
||||
range: RangeInclusive<f32>,
|
||||
value: f32,
|
||||
is_dragging: bool,
|
||||
style: &Self::Style,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, T, Message, Renderer> From<Slider<'a, T, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ impl Space {
|
|||
|
||||
impl<Message, Renderer> Widget<Message, Renderer> for Space
|
||||
where
|
||||
Renderer: self::Renderer,
|
||||
Renderer: crate::Renderer,
|
||||
{
|
||||
fn width(&self) -> Length {
|
||||
self.width
|
||||
|
|
@ -66,8 +66,7 @@ where
|
|||
layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.draw(layout.bounds())
|
||||
) {
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -78,17 +77,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// The renderer of an amount of [`Space`].
|
||||
pub trait Renderer: crate::Renderer {
|
||||
/// Draws an amount of empty [`Space`].
|
||||
///
|
||||
/// You should most likely return an empty primitive here.
|
||||
fn draw(&mut self, bounds: Rectangle) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Space> for Element<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: self::Renderer,
|
||||
Renderer: crate::Renderer,
|
||||
Message: 'a,
|
||||
{
|
||||
fn from(space: Space) -> Element<'a, Message, Renderer> {
|
||||
|
|
|
|||
|
|
@ -94,8 +94,9 @@ where
|
|||
layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.draw(self.handle.clone(), layout)
|
||||
) {
|
||||
// TODO
|
||||
// renderer.draw(self.handle.clone(), layout)
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -187,9 +188,6 @@ impl std::fmt::Debug for Data {
|
|||
pub trait Renderer: crate::Renderer {
|
||||
/// Returns the default dimensions of an [`Svg`] for the given [`Handle`].
|
||||
fn dimensions(&self, handle: &Handle) -> (u32, u32);
|
||||
|
||||
/// Draws an [`Svg`].
|
||||
fn draw(&mut self, handle: Handle, layout: Layout<'_>) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Svg> for Element<'a, Message, Renderer>
|
||||
|
|
|
|||
|
|
@ -133,22 +133,13 @@ where
|
|||
|
||||
fn draw(
|
||||
&self,
|
||||
renderer: &mut Renderer,
|
||||
defaults: &Renderer::Defaults,
|
||||
layout: Layout<'_>,
|
||||
_renderer: &mut Renderer,
|
||||
_defaults: &Renderer::Defaults,
|
||||
_layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
renderer.draw(
|
||||
defaults,
|
||||
layout.bounds(),
|
||||
&self.content,
|
||||
self.size.unwrap_or(renderer.default_size()),
|
||||
self.font,
|
||||
self.color,
|
||||
self.horizontal_alignment,
|
||||
self.vertical_alignment,
|
||||
)
|
||||
) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -201,27 +192,6 @@ pub trait Renderer: crate::Renderer {
|
|||
point: Point,
|
||||
nearest_only: bool,
|
||||
) -> Option<Hit>;
|
||||
|
||||
/// Draws a [`Text`] fragment.
|
||||
///
|
||||
/// It receives:
|
||||
/// * the bounds of the [`Text`]
|
||||
/// * the contents of the [`Text`]
|
||||
/// * the size of the [`Text`]
|
||||
/// * the color of the [`Text`]
|
||||
/// * the [`HorizontalAlignment`] of the [`Text`]
|
||||
/// * the [`VerticalAlignment`] of the [`Text`]
|
||||
fn draw(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
bounds: Rectangle,
|
||||
content: &str,
|
||||
size: u16,
|
||||
font: Self::Font,
|
||||
color: Option<Color>,
|
||||
horizontal_alignment: alignment::Horizontal,
|
||||
vertical_alignment: alignment::Vertical,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Text<Renderer>>
|
||||
|
|
|
|||
|
|
@ -170,38 +170,39 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
value: Option<&Value>,
|
||||
) -> Renderer::Output {
|
||||
let value = value.unwrap_or(&self.value);
|
||||
let bounds = layout.bounds();
|
||||
let text_bounds = layout.children().next().unwrap().bounds();
|
||||
) {
|
||||
// TODO
|
||||
// let value = value.unwrap_or(&self.value);
|
||||
// let bounds = layout.bounds();
|
||||
// let text_bounds = layout.children().next().unwrap().bounds();
|
||||
|
||||
if self.is_secure {
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
bounds,
|
||||
text_bounds,
|
||||
cursor_position,
|
||||
self.font,
|
||||
self.size.unwrap_or(renderer.default_size()),
|
||||
&self.placeholder,
|
||||
&value.secure(),
|
||||
&self.state,
|
||||
&self.style,
|
||||
)
|
||||
} else {
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
bounds,
|
||||
text_bounds,
|
||||
cursor_position,
|
||||
self.font,
|
||||
self.size.unwrap_or(renderer.default_size()),
|
||||
&self.placeholder,
|
||||
value,
|
||||
&self.state,
|
||||
&self.style,
|
||||
)
|
||||
}
|
||||
// if self.is_secure {
|
||||
// self::Renderer::draw(
|
||||
// renderer,
|
||||
// bounds,
|
||||
// text_bounds,
|
||||
// cursor_position,
|
||||
// self.font,
|
||||
// self.size.unwrap_or(renderer.default_size()),
|
||||
// &self.placeholder,
|
||||
// &value.secure(),
|
||||
// &self.state,
|
||||
// &self.style,
|
||||
// )
|
||||
// } else {
|
||||
// self::Renderer::draw(
|
||||
// renderer,
|
||||
// bounds,
|
||||
// text_bounds,
|
||||
// cursor_position,
|
||||
// self.font,
|
||||
// self.size.unwrap_or(renderer.default_size()),
|
||||
// &self.placeholder,
|
||||
// value,
|
||||
// &self.state,
|
||||
// &self.style,
|
||||
// )
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -630,7 +631,7 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
) {
|
||||
self.draw(renderer, layout, cursor_position, None)
|
||||
}
|
||||
|
||||
|
|
@ -673,28 +674,6 @@ pub trait Renderer: text::Renderer + Sized {
|
|||
state: &State,
|
||||
) -> f32;
|
||||
|
||||
/// Draws a [`TextInput`].
|
||||
///
|
||||
/// It receives:
|
||||
/// - the bounds of the [`TextInput`]
|
||||
/// - the bounds of the text (i.e. the current value)
|
||||
/// - the cursor position
|
||||
/// - the placeholder to show when the value is empty
|
||||
/// - the current [`Value`]
|
||||
/// - the current [`State`]
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
text_bounds: Rectangle,
|
||||
cursor_position: Point,
|
||||
font: Self::Font,
|
||||
size: u16,
|
||||
placeholder: &str,
|
||||
value: &Value,
|
||||
state: &State,
|
||||
style: &Self::Style,
|
||||
) -> Self::Output;
|
||||
|
||||
/// Computes the position of the text cursor at the given X coordinate of
|
||||
/// a [`TextInput`].
|
||||
fn find_cursor_position(
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ use crate::alignment;
|
|||
use crate::event;
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::row;
|
||||
use crate::text;
|
||||
use crate::{
|
||||
Alignment, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
||||
|
|
@ -119,7 +118,7 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
|
|||
|
||||
impl<Message, Renderer> Widget<Message, Renderer> for Toggler<Message, Renderer>
|
||||
where
|
||||
Renderer: self::Renderer + text::Renderer + row::Renderer,
|
||||
Renderer: self::Renderer + text::Renderer,
|
||||
{
|
||||
fn width(&self) -> Length {
|
||||
self.width
|
||||
|
|
@ -190,43 +189,35 @@ where
|
|||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
let bounds = layout.bounds();
|
||||
let mut children = layout.children();
|
||||
) {
|
||||
// TODO
|
||||
// let bounds = layout.bounds();
|
||||
// let mut children = layout.children();
|
||||
|
||||
let label = match &self.label {
|
||||
Some(label) => {
|
||||
let label_layout = children.next().unwrap();
|
||||
// let label = match &self.label {
|
||||
// Some(label) => {
|
||||
// let label_layout = children.next().unwrap();
|
||||
|
||||
Some(text::Renderer::draw(
|
||||
renderer,
|
||||
defaults,
|
||||
label_layout.bounds(),
|
||||
&label,
|
||||
self.text_size.unwrap_or(renderer.default_size()),
|
||||
self.font,
|
||||
None,
|
||||
self.text_alignment,
|
||||
alignment::Vertical::Center,
|
||||
))
|
||||
}
|
||||
// Some(text::Renderer::draw(
|
||||
// renderer,
|
||||
// defaults,
|
||||
// label_layout.bounds(),
|
||||
// &label,
|
||||
// self.text_size.unwrap_or(renderer.default_size()),
|
||||
// self.font,
|
||||
// None,
|
||||
// self.text_alignment,
|
||||
// alignment::Vertical::Center,
|
||||
// ))
|
||||
// }
|
||||
|
||||
None => None,
|
||||
};
|
||||
// None => None,
|
||||
// };
|
||||
|
||||
let toggler_layout = children.next().unwrap();
|
||||
let toggler_bounds = toggler_layout.bounds();
|
||||
// let toggler_layout = children.next().unwrap();
|
||||
// let toggler_bounds = toggler_layout.bounds();
|
||||
|
||||
let is_mouse_over = bounds.contains(cursor_position);
|
||||
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
toggler_bounds,
|
||||
self.is_active,
|
||||
is_mouse_over,
|
||||
label,
|
||||
&self.style,
|
||||
)
|
||||
// let is_mouse_over = bounds.contains(cursor_position);
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -249,29 +240,12 @@ pub trait Renderer: crate::Renderer {
|
|||
|
||||
/// The default size of a [`Toggler`].
|
||||
const DEFAULT_SIZE: u16;
|
||||
|
||||
/// Draws a [`Toggler`].
|
||||
///
|
||||
/// It receives:
|
||||
/// * the bounds of the [`Toggler`]
|
||||
/// * whether the [`Toggler`] is activated or not
|
||||
/// * whether the mouse is over the [`Toggler`] or not
|
||||
/// * the drawn label of the [`Toggler`]
|
||||
/// * the style of the [`Toggler`]
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
is_active: bool,
|
||||
is_mouse_over: bool,
|
||||
label: Option<Self::Output>,
|
||||
style: &Self::Style,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Toggler<Message, Renderer>>
|
||||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: 'a + self::Renderer + text::Renderer + row::Renderer,
|
||||
Renderer: 'a + self::Renderer + text::Renderer,
|
||||
Message: 'a,
|
||||
{
|
||||
fn from(
|
||||
|
|
|
|||
|
|
@ -136,25 +136,13 @@ where
|
|||
|
||||
fn draw(
|
||||
&self,
|
||||
renderer: &mut Renderer,
|
||||
defaults: &Renderer::Defaults,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) -> Renderer::Output {
|
||||
self::Renderer::draw(
|
||||
renderer,
|
||||
defaults,
|
||||
cursor_position,
|
||||
layout,
|
||||
viewport,
|
||||
&self.content,
|
||||
&self.tooltip,
|
||||
self.position,
|
||||
&self.style,
|
||||
self.gap,
|
||||
self.padding,
|
||||
)
|
||||
_renderer: &mut Renderer,
|
||||
_defaults: &Renderer::Defaults,
|
||||
_layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
|
|
@ -177,23 +165,6 @@ pub trait Renderer:
|
|||
{
|
||||
/// The default padding of a [`Tooltip`] drawn by this renderer.
|
||||
const DEFAULT_PADDING: u16;
|
||||
|
||||
/// Draws a [`Tooltip`].
|
||||
///
|
||||
/// [`Tooltip`]: struct.Tooltip.html
|
||||
fn draw<Message>(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
cursor_position: Point,
|
||||
content_layout: Layout<'_>,
|
||||
viewport: &Rectangle,
|
||||
content: &Element<'_, Message, Self>,
|
||||
tooltip: &Text<Self>,
|
||||
position: Position,
|
||||
style: &<Self as container::Renderer>::Style,
|
||||
gap: u16,
|
||||
padding: u16,
|
||||
) -> Self::Output;
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Tooltip<'a, Message, Renderer>>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue