summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu/src/renderer')
-rw-r--r--wgpu/src/renderer/widget.rs18
-rw-r--r--wgpu/src/renderer/widget/button.rs94
-rw-r--r--wgpu/src/renderer/widget/checkbox.rs59
-rw-r--r--wgpu/src/renderer/widget/column.rs34
-rw-r--r--wgpu/src/renderer/widget/container.rs49
-rw-r--r--wgpu/src/renderer/widget/image.rs22
-rw-r--r--wgpu/src/renderer/widget/progress_bar.rs54
-rw-r--r--wgpu/src/renderer/widget/radio.rs64
-rw-r--r--wgpu/src/renderer/widget/row.rs34
-rw-r--r--wgpu/src/renderer/widget/scrollable.rs127
-rw-r--r--wgpu/src/renderer/widget/slider.rs106
-rw-r--r--wgpu/src/renderer/widget/space.rs8
-rw-r--r--wgpu/src/renderer/widget/svg.rs22
-rw-r--r--wgpu/src/renderer/widget/text.rs47
-rw-r--r--wgpu/src/renderer/widget/text_input.rs182
15 files changed, 0 insertions, 920 deletions
diff --git a/wgpu/src/renderer/widget.rs b/wgpu/src/renderer/widget.rs
deleted file mode 100644
index 84f908e7..00000000
--- a/wgpu/src/renderer/widget.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-mod button;
-mod checkbox;
-mod column;
-mod container;
-mod progress_bar;
-mod radio;
-mod row;
-mod scrollable;
-mod slider;
-mod space;
-mod text;
-mod text_input;
-
-#[cfg(feature = "svg")]
-mod svg;
-
-#[cfg(feature = "image")]
-mod image;
diff --git a/wgpu/src/renderer/widget/button.rs b/wgpu/src/renderer/widget/button.rs
deleted file mode 100644
index 0de5bf5c..00000000
--- a/wgpu/src/renderer/widget/button.rs
+++ /dev/null
@@ -1,94 +0,0 @@
-use crate::{button::StyleSheet, defaults, Defaults, Primitive, Renderer};
-use iced_native::{
- Background, Color, Element, Layout, MouseCursor, Point, Rectangle, Vector,
-};
-
-impl iced_native::button::Renderer for Renderer {
- const DEFAULT_PADDING: u16 = 5;
-
- type Style = Box<dyn StyleSheet>;
-
- fn draw<Message>(
- &mut self,
- defaults: &Defaults,
- bounds: Rectangle,
- cursor_position: Point,
- is_disabled: bool,
- is_pressed: bool,
- style: &Box<dyn StyleSheet>,
- content: &Element<'_, Message, Self>,
- content_layout: Layout<'_>,
- ) -> Self::Output {
- let is_mouse_over = bounds.contains(cursor_position);
-
- let styling = if is_disabled {
- style.disabled()
- } else if is_mouse_over {
- if is_pressed {
- style.pressed()
- } else {
- style.hovered()
- }
- } else {
- style.active()
- };
-
- let (content, _) = content.draw(
- self,
- &Defaults {
- text: defaults::Text {
- color: styling.text_color,
- },
- ..*defaults
- },
- content_layout,
- cursor_position,
- );
-
- (
- if styling.background.is_some() || styling.border_width > 0 {
- let background = Primitive::Quad {
- bounds,
- background: styling
- .background
- .unwrap_or(Background::Color(Color::TRANSPARENT)),
- border_radius: styling.border_radius,
- border_width: styling.border_width,
- border_color: styling.border_color,
- };
-
- if styling.shadow_offset == Vector::default() {
- Primitive::Group {
- primitives: vec![background, content],
- }
- } else {
- // TODO: Implement proper shadow support
- let shadow = Primitive::Quad {
- bounds: Rectangle {
- x: bounds.x + styling.shadow_offset.x,
- y: bounds.y + styling.shadow_offset.y,
- ..bounds
- },
- background: Background::Color(
- [0.0, 0.0, 0.0, 0.5].into(),
- ),
- border_radius: styling.border_radius,
- border_width: 0,
- border_color: Color::TRANSPARENT,
- };
-
- Primitive::Group {
- primitives: vec![shadow, background, content],
- }
- }
- } else {
- content
- },
- if is_mouse_over {
- MouseCursor::Pointer
- } else {
- MouseCursor::OutOfBounds
- },
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/checkbox.rs b/wgpu/src/renderer/widget/checkbox.rs
deleted file mode 100644
index 1a0585d3..00000000
--- a/wgpu/src/renderer/widget/checkbox.rs
+++ /dev/null
@@ -1,59 +0,0 @@
-use crate::{checkbox::StyleSheet, Primitive, Renderer};
-use iced_native::{
- checkbox, HorizontalAlignment, MouseCursor, Rectangle, VerticalAlignment,
-};
-
-impl checkbox::Renderer for Renderer {
- type Style = Box<dyn StyleSheet>;
-
- 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_sheet: &Self::Style,
- ) -> Self::Output {
- let style = if is_mouse_over {
- style_sheet.hovered(is_checked)
- } else {
- style_sheet.active(is_checked)
- };
-
- let checkbox = Primitive::Quad {
- bounds,
- background: style.background,
- border_radius: style.border_radius,
- border_width: style.border_width,
- border_color: style.border_color,
- };
-
- (
- Primitive::Group {
- primitives: if is_checked {
- let check = Primitive::Text {
- content: crate::text::CHECKMARK_ICON.to_string(),
- font: crate::text::BUILTIN_ICONS,
- size: bounds.height * 0.7,
- bounds: bounds,
- color: style.checkmark_color,
- horizontal_alignment: HorizontalAlignment::Center,
- vertical_alignment: VerticalAlignment::Center,
- };
-
- vec![checkbox, check, label]
- } else {
- vec![checkbox, label]
- },
- },
- if is_mouse_over {
- MouseCursor::Pointer
- } else {
- MouseCursor::OutOfBounds
- },
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/column.rs b/wgpu/src/renderer/widget/column.rs
deleted file mode 100644
index 95a7463a..00000000
--- a/wgpu/src/renderer/widget/column.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-use crate::{Primitive, Renderer};
-use iced_native::{column, Element, Layout, MouseCursor, Point};
-
-impl column::Renderer for Renderer {
- fn draw<Message>(
- &mut self,
- defaults: &Self::Defaults,
- content: &[Element<'_, Message, Self>],
- layout: Layout<'_>,
- cursor_position: Point,
- ) -> Self::Output {
- let mut mouse_cursor = MouseCursor::OutOfBounds;
-
- (
- Primitive::Group {
- primitives: content
- .iter()
- .zip(layout.children())
- .map(|(child, layout)| {
- let (primitive, new_mouse_cursor) =
- child.draw(self, defaults, layout, cursor_position);
-
- if new_mouse_cursor > mouse_cursor {
- mouse_cursor = new_mouse_cursor;
- }
-
- primitive
- })
- .collect(),
- },
- mouse_cursor,
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/container.rs b/wgpu/src/renderer/widget/container.rs
deleted file mode 100644
index 2d4d1db8..00000000
--- a/wgpu/src/renderer/widget/container.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-use crate::{container, defaults, Defaults, Primitive, Renderer};
-use iced_native::{Background, Color, Element, Layout, Point, Rectangle};
-
-impl iced_native::container::Renderer for Renderer {
- type Style = Box<dyn container::StyleSheet>;
-
- fn draw<Message>(
- &mut self,
- defaults: &Defaults,
- bounds: Rectangle,
- cursor_position: Point,
- style_sheet: &Self::Style,
- content: &Element<'_, Message, Self>,
- content_layout: Layout<'_>,
- ) -> Self::Output {
- let style = style_sheet.style();
-
- let defaults = Defaults {
- text: defaults::Text {
- color: style.text_color.unwrap_or(defaults.text.color),
- },
- ..*defaults
- };
-
- let (content, mouse_cursor) =
- content.draw(self, &defaults, content_layout, cursor_position);
-
- if style.background.is_some() || style.border_width > 0 {
- let quad = Primitive::Quad {
- bounds,
- background: style
- .background
- .unwrap_or(Background::Color(Color::TRANSPARENT)),
- border_radius: style.border_radius,
- border_width: style.border_width,
- border_color: style.border_color,
- };
-
- (
- Primitive::Group {
- primitives: vec![quad, content],
- },
- mouse_cursor,
- )
- } else {
- (content, mouse_cursor)
- }
- }
-}
diff --git a/wgpu/src/renderer/widget/image.rs b/wgpu/src/renderer/widget/image.rs
deleted file mode 100644
index 70dc5d97..00000000
--- a/wgpu/src/renderer/widget/image.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-use crate::{Primitive, Renderer};
-use iced_native::{image, Layout, MouseCursor};
-
-impl image::Renderer for Renderer {
- fn dimensions(&self, handle: &image::Handle) -> (u32, u32) {
- self.image_pipeline.dimensions(handle)
- }
-
- fn draw(
- &mut self,
- handle: image::Handle,
- layout: Layout<'_>,
- ) -> Self::Output {
- (
- Primitive::Image {
- handle,
- bounds: layout.bounds(),
- },
- MouseCursor::OutOfBounds,
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/progress_bar.rs b/wgpu/src/renderer/widget/progress_bar.rs
deleted file mode 100644
index 34e33276..00000000
--- a/wgpu/src/renderer/widget/progress_bar.rs
+++ /dev/null
@@ -1,54 +0,0 @@
-use crate::{progress_bar::StyleSheet, Primitive, Renderer};
-use iced_native::{progress_bar, Color, MouseCursor, Rectangle};
-
-impl progress_bar::Renderer for Renderer {
- type Style = Box<dyn StyleSheet>;
-
- const DEFAULT_HEIGHT: u16 = 30;
-
- fn draw(
- &self,
- bounds: Rectangle,
- range: std::ops::RangeInclusive<f32>,
- value: f32,
- style_sheet: &Self::Style,
- ) -> Self::Output {
- let style = style_sheet.style();
-
- let (range_start, range_end) = range.into_inner();
- let active_progress_width = bounds.width
- * ((value - range_start) / (range_end - range_start).max(1.0));
-
- let background = Primitive::Group {
- primitives: vec![Primitive::Quad {
- bounds: Rectangle { ..bounds },
- background: style.background,
- border_radius: style.border_radius,
- border_width: 0,
- border_color: Color::TRANSPARENT,
- }],
- };
-
- (
- if active_progress_width > 0.0 {
- let bar = Primitive::Quad {
- bounds: Rectangle {
- width: active_progress_width,
- ..bounds
- },
- background: style.bar,
- border_radius: style.border_radius,
- border_width: 0,
- border_color: Color::TRANSPARENT,
- };
-
- Primitive::Group {
- primitives: vec![background, bar],
- }
- } else {
- background
- },
- MouseCursor::OutOfBounds,
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/radio.rs b/wgpu/src/renderer/widget/radio.rs
deleted file mode 100644
index 564f066b..00000000
--- a/wgpu/src/renderer/widget/radio.rs
+++ /dev/null
@@ -1,64 +0,0 @@
-use crate::{radio::StyleSheet, Primitive, Renderer};
-use iced_native::{radio, Background, Color, MouseCursor, Rectangle};
-
-const SIZE: f32 = 28.0;
-const DOT_SIZE: f32 = SIZE / 2.0;
-
-impl radio::Renderer for Renderer {
- type Style = Box<dyn StyleSheet>;
-
- fn default_size(&self) -> u32 {
- SIZE as u32
- }
-
- fn draw(
- &mut self,
- bounds: Rectangle,
- is_selected: bool,
- is_mouse_over: bool,
- (label, _): Self::Output,
- style_sheet: &Self::Style,
- ) -> Self::Output {
- let style = if is_mouse_over {
- style_sheet.hovered()
- } else {
- style_sheet.active()
- };
-
- let radio = Primitive::Quad {
- bounds,
- background: style.background,
- border_radius: (SIZE / 2.0) as u16,
- border_width: style.border_width,
- border_color: style.border_color,
- };
-
- (
- Primitive::Group {
- primitives: if is_selected {
- let radio_circle = Primitive::Quad {
- bounds: Rectangle {
- x: bounds.x + DOT_SIZE / 2.0,
- y: bounds.y + DOT_SIZE / 2.0,
- width: bounds.width - DOT_SIZE,
- height: bounds.height - DOT_SIZE,
- },
- background: Background::Color(style.dot_color),
- border_radius: (DOT_SIZE / 2.0) as u16,
- border_width: 0,
- border_color: Color::TRANSPARENT,
- };
-
- vec![radio, radio_circle, label]
- } else {
- vec![radio, label]
- },
- },
- if is_mouse_over {
- MouseCursor::Pointer
- } else {
- MouseCursor::OutOfBounds
- },
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/row.rs b/wgpu/src/renderer/widget/row.rs
deleted file mode 100644
index bd9f1a04..00000000
--- a/wgpu/src/renderer/widget/row.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-use crate::{Primitive, Renderer};
-use iced_native::{row, Element, Layout, MouseCursor, Point};
-
-impl row::Renderer for Renderer {
- fn draw<Message>(
- &mut self,
- defaults: &Self::Defaults,
- children: &[Element<'_, Message, Self>],
- layout: Layout<'_>,
- cursor_position: Point,
- ) -> Self::Output {
- let mut mouse_cursor = MouseCursor::OutOfBounds;
-
- (
- Primitive::Group {
- primitives: children
- .iter()
- .zip(layout.children())
- .map(|(child, layout)| {
- let (primitive, new_mouse_cursor) =
- child.draw(self, defaults, layout, cursor_position);
-
- if new_mouse_cursor > mouse_cursor {
- mouse_cursor = new_mouse_cursor;
- }
-
- primitive
- })
- .collect(),
- },
- mouse_cursor,
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/scrollable.rs b/wgpu/src/renderer/widget/scrollable.rs
deleted file mode 100644
index bfee7411..00000000
--- a/wgpu/src/renderer/widget/scrollable.rs
+++ /dev/null
@@ -1,127 +0,0 @@
-use crate::{Primitive, Renderer};
-use iced_native::{
- scrollable, Background, Color, MouseCursor, Rectangle, Vector,
-};
-
-const SCROLLBAR_WIDTH: u16 = 10;
-const SCROLLBAR_MARGIN: u16 = 2;
-
-impl scrollable::Renderer for Renderer {
- type Style = Box<dyn iced_style::scrollable::StyleSheet>;
-
- fn scrollbar(
- &self,
- bounds: Rectangle,
- content_bounds: Rectangle,
- offset: u32,
- ) -> Option<scrollable::Scrollbar> {
- if content_bounds.height > bounds.height {
- let scrollbar_bounds = Rectangle {
- x: bounds.x + bounds.width
- - f32::from(SCROLLBAR_WIDTH + 2 * SCROLLBAR_MARGIN),
- y: bounds.y,
- width: f32::from(SCROLLBAR_WIDTH + 2 * SCROLLBAR_MARGIN),
- height: bounds.height,
- };
-
- let ratio = bounds.height / content_bounds.height;
- let scrollbar_height = bounds.height * ratio;
- let y_offset = offset as f32 * ratio;
-
- let scroller_bounds = Rectangle {
- x: scrollbar_bounds.x + f32::from(SCROLLBAR_MARGIN),
- y: scrollbar_bounds.y + y_offset,
- width: scrollbar_bounds.width - f32::from(2 * SCROLLBAR_MARGIN),
- height: scrollbar_height,
- };
-
- Some(scrollable::Scrollbar {
- bounds: scrollbar_bounds,
- scroller: scrollable::Scroller {
- bounds: scroller_bounds,
- },
- })
- } else {
- None
- }
- }
-
- fn draw(
- &mut self,
- state: &scrollable::State,
- bounds: Rectangle,
- _content_bounds: Rectangle,
- is_mouse_over: bool,
- is_mouse_over_scrollbar: bool,
- scrollbar: Option<scrollable::Scrollbar>,
- offset: u32,
- style_sheet: &Self::Style,
- (content, mouse_cursor): Self::Output,
- ) -> Self::Output {
- let clip = Primitive::Clip {
- bounds,
- offset: Vector::new(0, offset),
- content: Box::new(content),
- };
-
- (
- if let Some(scrollbar) = scrollbar {
- let style = if state.is_scroller_grabbed() {
- style_sheet.dragging()
- } else if is_mouse_over_scrollbar {
- style_sheet.hovered()
- } else {
- style_sheet.active()
- };
-
- let is_scrollbar_visible =
- style.background.is_some() || style.border_width > 0;
-
- let scroller = if is_mouse_over
- || state.is_scroller_grabbed()
- || is_scrollbar_visible
- {
- Primitive::Quad {
- bounds: scrollbar.scroller.bounds,
- background: Background::Color(style.scroller.color),
- border_radius: style.scroller.border_radius,
- border_width: style.scroller.border_width,
- border_color: style.scroller.border_color,
- }
- } else {
- Primitive::None
- };
-
- let scrollbar = if is_scrollbar_visible {
- Primitive::Quad {
- bounds: Rectangle {
- x: scrollbar.bounds.x + f32::from(SCROLLBAR_MARGIN),
- width: scrollbar.bounds.width
- - f32::from(2 * SCROLLBAR_MARGIN),
- ..scrollbar.bounds
- },
- background: style
- .background
- .unwrap_or(Background::Color(Color::TRANSPARENT)),
- border_radius: style.border_radius,
- border_width: style.border_width,
- border_color: style.border_color,
- }
- } else {
- Primitive::None
- };
-
- Primitive::Group {
- primitives: vec![clip, scrollbar, scroller],
- }
- } else {
- clip
- },
- if is_mouse_over_scrollbar || state.is_scroller_grabbed() {
- MouseCursor::Idle
- } else {
- mouse_cursor
- },
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/slider.rs b/wgpu/src/renderer/widget/slider.rs
deleted file mode 100644
index c8ebd0da..00000000
--- a/wgpu/src/renderer/widget/slider.rs
+++ /dev/null
@@ -1,106 +0,0 @@
-use crate::{
- slider::{HandleShape, StyleSheet},
- Primitive, Renderer,
-};
-use iced_native::{slider, Background, Color, MouseCursor, Point, Rectangle};
-
-const HANDLE_HEIGHT: f32 = 22.0;
-
-impl slider::Renderer for Renderer {
- type Style = Box<dyn StyleSheet>;
-
- fn height(&self) -> u32 {
- 30
- }
-
- fn draw(
- &mut self,
- bounds: Rectangle,
- cursor_position: Point,
- range: std::ops::RangeInclusive<f32>,
- value: f32,
- is_dragging: bool,
- style_sheet: &Self::Style,
- ) -> Self::Output {
- let is_mouse_over = bounds.contains(cursor_position);
-
- let style = if is_dragging {
- style_sheet.dragging()
- } else if is_mouse_over {
- style_sheet.hovered()
- } else {
- style_sheet.active()
- };
-
- let rail_y = bounds.y + (bounds.height / 2.0).round();
-
- let (rail_top, rail_bottom) = (
- Primitive::Quad {
- bounds: Rectangle {
- x: bounds.x,
- y: rail_y,
- width: bounds.width,
- height: 2.0,
- },
- background: Background::Color(style.rail_colors.0),
- border_radius: 0,
- border_width: 0,
- border_color: Color::TRANSPARENT,
- },
- Primitive::Quad {
- bounds: Rectangle {
- x: bounds.x,
- y: rail_y + 2.0,
- width: bounds.width,
- height: 2.0,
- },
- background: Background::Color(style.rail_colors.1),
- border_radius: 0,
- border_width: 0,
- border_color: Color::TRANSPARENT,
- },
- );
-
- let (range_start, range_end) = range.into_inner();
-
- let (handle_width, handle_height, handle_border_radius) =
- match style.handle.shape {
- HandleShape::Circle { radius } => {
- (f32::from(radius * 2), f32::from(radius * 2), radius)
- }
- HandleShape::Rectangle {
- width,
- border_radius,
- } => (f32::from(width), HANDLE_HEIGHT, border_radius),
- };
-
- let handle_offset = (bounds.width - handle_width)
- * ((value - range_start) / (range_end - range_start).max(1.0));
-
- let handle = Primitive::Quad {
- bounds: Rectangle {
- x: bounds.x + handle_offset.round(),
- y: rail_y - handle_height / 2.0,
- width: handle_width,
- height: handle_height,
- },
- background: Background::Color(style.handle.color),
- border_radius: handle_border_radius,
- border_width: style.handle.border_width,
- border_color: style.handle.border_color,
- };
-
- (
- Primitive::Group {
- primitives: vec![rail_top, rail_bottom, handle],
- },
- if is_dragging {
- MouseCursor::Grabbing
- } else if is_mouse_over {
- MouseCursor::Grab
- } else {
- MouseCursor::OutOfBounds
- },
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/space.rs b/wgpu/src/renderer/widget/space.rs
deleted file mode 100644
index 28e05437..00000000
--- a/wgpu/src/renderer/widget/space.rs
+++ /dev/null
@@ -1,8 +0,0 @@
-use crate::{Primitive, Renderer};
-use iced_native::{space, MouseCursor, Rectangle};
-
-impl space::Renderer for Renderer {
- fn draw(&mut self, _bounds: Rectangle) -> Self::Output {
- (Primitive::None, MouseCursor::OutOfBounds)
- }
-}
diff --git a/wgpu/src/renderer/widget/svg.rs b/wgpu/src/renderer/widget/svg.rs
deleted file mode 100644
index 67bc3fe1..00000000
--- a/wgpu/src/renderer/widget/svg.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-use crate::{Primitive, Renderer};
-use iced_native::{svg, Layout, MouseCursor};
-
-impl svg::Renderer for Renderer {
- fn dimensions(&self, handle: &svg::Handle) -> (u32, u32) {
- self.image_pipeline.viewport_dimensions(handle)
- }
-
- fn draw(
- &mut self,
- handle: svg::Handle,
- layout: Layout<'_>,
- ) -> Self::Output {
- (
- Primitive::Svg {
- handle,
- bounds: layout.bounds(),
- },
- MouseCursor::OutOfBounds,
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/text.rs b/wgpu/src/renderer/widget/text.rs
deleted file mode 100644
index 33e549cd..00000000
--- a/wgpu/src/renderer/widget/text.rs
+++ /dev/null
@@ -1,47 +0,0 @@
-use crate::{Primitive, Renderer};
-use iced_native::{
- text, Color, Font, HorizontalAlignment, MouseCursor, Rectangle, Size,
- VerticalAlignment,
-};
-
-use std::f32;
-
-impl text::Renderer for Renderer {
- const DEFAULT_SIZE: u16 = 20;
-
- fn measure(
- &self,
- content: &str,
- size: u16,
- font: Font,
- bounds: Size,
- ) -> (f32, f32) {
- self.text_pipeline
- .measure(content, f32::from(size), font, bounds)
- }
-
- fn draw(
- &mut self,
- defaults: &Self::Defaults,
- bounds: Rectangle,
- content: &str,
- size: u16,
- font: Font,
- color: Option<Color>,
- horizontal_alignment: HorizontalAlignment,
- vertical_alignment: VerticalAlignment,
- ) -> Self::Output {
- (
- Primitive::Text {
- content: content.to_string(),
- size: f32::from(size),
- bounds,
- color: color.unwrap_or(defaults.text.color),
- font,
- horizontal_alignment,
- vertical_alignment,
- },
- MouseCursor::OutOfBounds,
- )
- }
-}
diff --git a/wgpu/src/renderer/widget/text_input.rs b/wgpu/src/renderer/widget/text_input.rs
deleted file mode 100644
index e2a1b3a9..00000000
--- a/wgpu/src/renderer/widget/text_input.rs
+++ /dev/null
@@ -1,182 +0,0 @@
-use crate::{text_input::StyleSheet, Primitive, Renderer};
-
-use iced_native::{
- text_input, Background, Color, Font, HorizontalAlignment, MouseCursor,
- Point, Rectangle, Size, Vector, VerticalAlignment,
-};
-use std::f32;
-
-impl text_input::Renderer for Renderer {
- type Style = Box<dyn StyleSheet>;
-
- fn default_size(&self) -> u16 {
- // TODO: Make this configurable
- 20
- }
-
- fn measure_value(&self, value: &str, size: u16, font: Font) -> f32 {
- let (mut width, _) = self.text_pipeline.measure(
- value,
- f32::from(size),
- font,
- Size::INFINITY,
- );
-
- let spaces_at_the_end = value.len() - value.trim_end().len();
-
- if spaces_at_the_end > 0 {
- let space_width = self.text_pipeline.space_width(size as f32);
- width += spaces_at_the_end as f32 * space_width;
- }
-
- width
- }
-
- fn offset(
- &self,
- text_bounds: Rectangle,
- size: u16,
- value: &text_input::Value,
- state: &text_input::State,
- font: Font,
- ) -> f32 {
- if state.is_focused() {
- let (_, offset) = measure_cursor_and_scroll_offset(
- self,
- text_bounds,
- value,
- size,
- state.cursor_position(value),
- font,
- );
-
- offset
- } else {
- 0.0
- }
- }
-
- fn draw(
- &mut self,
- bounds: Rectangle,
- text_bounds: Rectangle,
- cursor_position: Point,
- size: u16,
- font: Font,
- placeholder: &str,
- value: &text_input::Value,
- state: &text_input::State,
- style_sheet: &Self::Style,
- ) -> Self::Output {
- let is_mouse_over = bounds.contains(cursor_position);
-
- let style = if state.is_focused() {
- style_sheet.focused()
- } else if is_mouse_over {
- style_sheet.hovered()
- } else {
- style_sheet.active()
- };
-
- let input = Primitive::Quad {
- bounds,
- background: style.background,
- border_radius: style.border_radius,
- border_width: style.border_width,
- border_color: style.border_color,
- };
-
- let text = value.to_string();
-
- let text_value = Primitive::Text {
- content: if text.is_empty() {
- placeholder.to_string()
- } else {
- text.clone()
- },
- color: if text.is_empty() {
- style_sheet.placeholder_color()
- } else {
- style_sheet.value_color()
- }
- .into(),
- font,
- bounds: Rectangle {
- width: f32::INFINITY,
- ..text_bounds
- },
- size: f32::from(size),
- horizontal_alignment: HorizontalAlignment::Left,
- vertical_alignment: VerticalAlignment::Center,
- };
-
- let (contents_primitive, offset) = if state.is_focused() {
- let (text_value_width, offset) = measure_cursor_and_scroll_offset(
- self,
- text_bounds,
- value,
- size,
- state.cursor_position(value),
- font,
- );
-
- let cursor = Primitive::Quad {
- bounds: Rectangle {
- x: text_bounds.x + text_value_width,
- y: text_bounds.y,
- width: 1.0,
- height: text_bounds.height,
- },
- background: Background::Color(style_sheet.value_color()),
- border_radius: 0,
- border_width: 0,
- border_color: Color::TRANSPARENT,
- };
-
- (
- Primitive::Group {
- primitives: vec![text_value, cursor],
- },
- Vector::new(offset as u32, 0),
- )
- } else {
- (text_value, Vector::new(0, 0))
- };
-
- let contents = Primitive::Clip {
- bounds: text_bounds,
- offset,
- content: Box::new(contents_primitive),
- };
-
- (
- Primitive::Group {
- primitives: vec![input, contents],
- },
- if is_mouse_over {
- MouseCursor::Text
- } else {
- MouseCursor::OutOfBounds
- },
- )
- }
-}
-
-fn measure_cursor_and_scroll_offset(
- renderer: &Renderer,
- text_bounds: Rectangle,
- value: &text_input::Value,
- size: u16,
- cursor_index: usize,
- font: Font,
-) -> (f32, f32) {
- use iced_native::text_input::Renderer;
-
- let text_before_cursor = value.until(cursor_index).to_string();
-
- let text_value_width =
- renderer.measure_value(&text_before_cursor, size, font);
- let offset = ((text_value_width + 5.0) - text_bounds.width).max(0.0);
-
- (text_value_width, offset)
-}