Remove uneeded commented code, add notes to remaining commented code, use source rect calculations from conrod backend code

This commit is contained in:
Imbris 2020-11-01 16:42:07 -05:00
parent 64d885a192
commit 61c0780872
23 changed files with 135 additions and 219 deletions

View File

@ -268,6 +268,7 @@ impl PlayState for MainMenuState {
global_state.singleplayer = Some(singleplayer);
},
MainMenuEvent::Quit => return PlayStateResult::Shutdown,
// Note: Keeping in case we re-add the disclaimer
/*MainMenuEvent::DisclaimerAccepted => {
global_state.settings.show_disclaimer = false
},*/

View File

@ -398,7 +398,6 @@ impl LoginBanner {
.into(),
])
.spacing(5)
//.height(Length::Units(200))
.into(),
Space::new(Length::Fill, Length::Units(8)).into(),
Column::with_children(vec![
@ -430,7 +429,5 @@ impl LoginBanner {
.height(Length::Fill)
.center_y()
.into()
//.padding(Padding::new().horizontal(8).vertical(15))
//.max_width(350);
}
}

View File

@ -1,4 +1,5 @@
mod connecting;
// Note: Keeping in case we re-add the disclaimer
//mod disclaimer;
mod login;
mod servers;
@ -26,10 +27,6 @@ use std::time::Duration;
// TODO: what is this? (showed up in rebase)
//const COL1: Color = Color::Rgba(0.07, 0.1, 0.1, 0.9);
// UI Color-Theme
/*const UI_MAIN: Color = Color::Rgba(0.61, 0.70, 0.70, 1.0); // Greenish Blue
const UI_HIGHLIGHT_0: Color = Color::Rgba(0.79, 1.09, 1.09, 1.0);*/
pub const TEXT_COLOR: iced::Color = iced::Color::from_rgb(1.0, 1.0, 1.0);
pub const DISABLED_TEXT_COLOR: iced::Color = iced::Color::from_rgba(1.0, 1.0, 1.0, 0.2);
@ -95,7 +92,7 @@ pub enum Event {
#[cfg(feature = "singleplayer")]
StartSingleplayer,
Quit,
//DisclaimerClosed, TODO: remove all traces?
// Note: Keeping in case we re-add the disclaimer
//DisclaimerAccepted,
AuthServerTrust(String, bool),
}
@ -112,6 +109,7 @@ enum ConnectionState {
}
enum Screen {
// Note: Keeping in case we re-add the disclaimer
/*Disclaimer {
screen: disclaimer::Screen,
},*/
@ -169,7 +167,7 @@ enum Message {
TrustPromptAdd,
TrustPromptCancel,
CloseError,
/*CloseDisclaimer,
/* Note: Keeping in case we re-add the disclaimer
*AcceptDisclaimer, */
}
@ -184,6 +182,7 @@ impl Controls {
let version = common::util::DISPLAY_VERSION_LONG.clone();
let alpha = format!("Veloren {}", common::util::DISPLAY_VERSION.as_str());
// Note: Keeping in case we re-add the disclaimer
let screen = /* if settings.show_disclaimer {
Screen::Disclaimer {
screen: disclaimer::Screen::new(),
@ -274,6 +273,7 @@ impl Controls {
// TODO: make any large text blocks scrollable so that if the area is to
// small they can still be read
let content = match &mut self.screen {
// Note: Keeping in case we re-add the disclaimer
//Screen::Disclaimer { screen } => screen.view(&self.fonts, &self.i18n, button_style),
Screen::Login { screen, error } => screen.view(
&self.fonts,
@ -389,11 +389,7 @@ impl Controls {
connection_state, ..
} = &mut self.screen
{
if let ConnectionState::AuthTrustPrompt {
auth_server,
..
} = connection_state
{
if let ConnectionState::AuthTrustPrompt { auth_server, .. } = connection_state {
let auth_server = std::mem::take(auth_server);
let added = matches!(msg, Message::TrustPromptAdd);
@ -407,9 +403,7 @@ impl Controls {
*error = None;
}
},
//Message::CloseDisclaimer => {
// events.push(Event::DisclaimerClosed);
//},
/* Note: Keeping in case we re-add the disclaimer */
/*Message::AcceptDisclaimer => {
if let Screen::Disclaimer { .. } = &self.screen {
events.push(Event::DisclaimerAccepted);

View File

@ -1,4 +1,7 @@
use common::util::{linear_to_srgba, srgba_to_linear};
use common::{
span,
util::{linear_to_srgba, srgba_to_linear},
};
/// Pixel art scaling
/// Note: The current ui is locked to the pixel grid with little animation, if
/// we want smoothly moving pixel art this should be done in the shaders
@ -35,6 +38,7 @@ const EPSILON: f32 = 0.0001;
// E9: c3 = (A1 * c1 * a1 + A2 * c2 * a2) / a3
#[allow(clippy::manual_saturating_arithmetic)] // TODO: Pending review in #587
pub fn resize_pixel_art(image: &RgbaImage, new_width: u32, new_height: u32) -> RgbaImage {
span!(_guard, "resize_pixel_art");
let (width, height) = image.dimensions();
let mut new_image = RgbaImage::new(new_width, new_height);

View File

@ -113,7 +113,6 @@ pub struct IcedRenderer {
start: usize,
// Draw commands for the next render
draw_commands: Vec<DrawCommand>,
//current_scissor: Aabr<u16>,
}
impl IcedRenderer {
pub fn new(
@ -141,7 +140,6 @@ impl IcedRenderer {
win_dims: scaled_dims,
window_scissor: default_scissor(renderer),
start: 0,
//current_scissor: default_scissor(renderer),
})
}
@ -186,8 +184,6 @@ impl IcedRenderer {
self.current_state = State::Plain;
self.start = 0;
//self.current_scissor = default_scissor(renderer);
self.draw_primitive(primitive, Vec2::zero(), 1.0, renderer);
// Enter the final command.
@ -309,20 +305,6 @@ impl IcedRenderer {
}
// Update model with new mesh.
renderer.update_model(&self.model, &self.mesh, 0).unwrap();
// Handle window resizing.
/*if let Some(new_dims) = self.window_resized.take() {
let (old_w, old_h) = self.scale.scaled_window_size().into_tuple();
self.scale.window_resized(new_dims, renderer);
let (w, h) = self.scale.scaled_window_size().into_tuple();
self.ui.handle_event(Input::Resize(w, h));
// Avoid panic in graphic cache when minimizing.
// Avoid resetting cache if window size didn't change
// Somewhat inefficient for elements that won't change size after a window resize
let res = renderer.get_resolution();
self.need_cache_resize = res.x > 0 && res.y > 0 && !(old_w == w && old_h == h);
}*/
}
// Returns (half_res, align)
@ -346,19 +328,6 @@ impl IcedRenderer {
}
fn gl_aabr(&self, bounds: iced::Rectangle) -> Aabr<f32> {
/*let (ui_win_w, ui_win_h) = self.win_dims.into_tuple();
let (l, b) = aabr.min.into_tuple();
let (r, t) = aabr.max.into_tuple();
let vx = |x: f64| (x / ui_win_w * 2.0) as f32;
let vy = |y: f64| (y / ui_win_h * 2.0) as f32;
let min = Vec2::new(
((vx(l) * half_res.x + x_align).round() - x_align) / half_res.x,
((vy(b) * half_res.y + y_align).round() - y_align) / half_res.y,
);
let max = Vec2::new(
((vx(r) * half_res.x + x_align).round() - x_align) / half_res.x,
((vy(t) * half_res.y + y_align).round() - y_align) / half_res.y,
);*/
let flipped_y = self.win_dims.y - bounds.y;
let half_win_dims = self.win_dims.map(|e| e / 2.0);
let half_res = self.half_res;
@ -458,6 +427,7 @@ impl IcedRenderer {
handle,
bounds,
color,
source_rect,
} => {
let color = srgba_to_linear(color.map(|e| e as f32 / 255.0));
let color = apply_alpha(color, alpha);
@ -473,9 +443,78 @@ impl IcedRenderer {
..bounds
});
let graphic_cache = self.cache.graphic_cache_mut();
let half_res = self.half_res; // Make borrow checker happy by avoiding self in closure
let (source_aabr, gl_size) = {
// Transform the source rectangle into uv coordinate.
// TODO: Make sure this is right. Especially the conversions.
let ((uv_l, uv_r, uv_b, uv_t), gl_size) = match graphic_cache
.get_graphic(graphic_id)
{
Some(Graphic::Blank) | None => return,
Some(Graphic::Image(image, ..)) => {
source_rect.and_then(|src_rect| {
#[rustfmt::skip] use ::image::GenericImageView;
let (image_w, image_h) = image.dimensions();
let (source_w, source_h) = src_rect.size().into_tuple();
let gl_size = gl_aabr.size();
if image_w == 0
|| image_h == 0
|| source_w < 1.0
|| source_h < 1.0
|| gl_size.reduce_partial_min() < f32::EPSILON
{
None
} else {
// TODO: do this earlier
// Multiply drawn image size by ratio of original image
// size to
// source rectangle size (since as the proportion of the
// image gets
// smaller, the drawn size should get bigger), up to the
// actual
// size of the original image.
let ratio_x = (image_w as f32 / source_w)
.min((image_w as f32 / (gl_size.w * half_res.x)).max(1.0));
let ratio_y = (image_h as f32 / source_h)
.min((image_h as f32 / (gl_size.h * half_res.y)).max(1.0));
let (l, b) = src_rect.min.into_tuple();
let (r, t) = src_rect.max.into_tuple();
Some((
(
l / image_w as f32, /* * ratio_x*/
r / image_w as f32, /* * ratio_x*/
b / image_h as f32, /* * ratio_y*/
t / image_h as f32, /* * ratio_y*/
),
Extent2::new(
gl_size.w as f32 * ratio_x,
gl_size.h as f32 * ratio_y,
),
))
/* ((l / image_w as f32),
(r / image_w as f32),
(b / image_h as f32),
(t / image_h as f32)) */
}
})
},
// No easy way to interpret source_rect for voxels...
Some(Graphic::Voxel(..)) => None,
}
.unwrap_or_else(|| ((0.0, 1.0, 0.0, 1.0), gl_aabr.size()));
(
Aabr {
min: Vec2::new(uv_l, uv_b),
max: Vec2::new(uv_r, uv_t),
},
gl_size,
)
};
let resolution = Vec2::new(
(gl_aabr.size().w * self.half_res.x).round() as u16,
(gl_aabr.size().h * self.half_res.y).round() as u16,
(gl_size.w * self.half_res.x).round() as u16,
(gl_size.h * self.half_res.y).round() as u16,
);
// Don't do anything if resolution is zero
@ -484,39 +523,13 @@ impl IcedRenderer {
// TODO: consider logging uneeded elements
}
let graphic_cache = self.cache.graphic_cache_mut();
match graphic_cache.get_graphic(graphic_id) {
Some(Graphic::Blank) | None => return,
_ => {},
}
// Transform the source rectangle into uv coordinate.
// TODO: Make sure this is right.
let source_aabr = {
let (uv_l, uv_r, uv_b, uv_t) = (0.0, 1.0, 0.0, 1.0);
/*match source_rect {
Some(src_rect) => {
let (l, r, b, t) = src_rect.l_r_b_t();
((l / image_w) as f32,
(r / image_w) as f32,
(b / image_h) as f32,
(t / image_h) as f32)
}
None => (0.0, 1.0, 0.0, 1.0),
};*/
Aabr {
min: Vec2::new(uv_l, uv_b),
max: Vec2::new(uv_r, uv_t),
}
};
// Cache graphic at particular resolution.
let (uv_aabr, tex_id) = match graphic_cache.cache_res(
renderer,
graphic_id,
resolution,
source_aabr,
// TODO: take f32 here
source_aabr.map(|e| e as f64),
rotation,
) {
// TODO: get dims from graphic_cache (or have it return floats directly)
@ -601,11 +614,8 @@ impl IcedRenderer {
},
Primitive::Text {
glyphs,
bounds: _bounds, // iced::Rectangle
bounds: _, // iced::Rectangle
linear_color,
/*font,
*horizontal_alignment,
*vertical_alignment, */
} => {
let linear_color = apply_alpha(linear_color, alpha);
self.switch_state(State::Plain);
@ -627,6 +637,7 @@ impl IcedRenderer {
// Note: we can't actually use this because dropping glyphs messeses up the
// counting and there is not a method provided to drop out of bounds
// glyphs while positioning them
// Note: keeping commented code in case how we handle text changes
glyph_brush::ab_glyph::Rect {
min: glyph_brush::ab_glyph::point(
-10000.0, //bounds.x * self.p_scale,
@ -688,11 +699,11 @@ impl IcedRenderer {
Aabr::new_empty(Vec2::zero())
}
};
// Not expecting this case: new_cursor == current_scissor
// Not expecting this case: new_scissor == current_scissor
// So not optimizing for it
// Finish the current command.
// TODO: ensure we never push empty commands (make fields private & debug assert
// in constructors?)
// TODO: ensure we never push empty commands
self.draw_commands.push(match self.current_state {
State::Plain => DrawCommand::plain(self.start..self.mesh.vertices().len()),
State::Image(id) => {

View File

@ -10,6 +10,7 @@ pub enum Primitive {
handle: (image::Handle, graphic::Rotation),
bounds: iced::Rectangle,
color: vek::Rgba<u8>,
source_rect: Option<vek::Aabr<f32>>,
},
// A vertical gradient
// TODO: could be combined with rectangle
@ -24,12 +25,8 @@ pub enum Primitive {
},
Text {
glyphs: Vec<glyph_brush::SectionGlyph>,
//size: f32,
bounds: iced::Rectangle,
linear_color: vek::Rgba<f32>,
/*font: iced::Font,
*horizontal_alignment: iced::HorizontalAlignment,
*vertical_alignment: iced::VerticalAlignment, */
},
Clip {
bounds: iced::Rectangle,

View File

@ -27,8 +27,6 @@ pub struct Style {
background: Option<Background>,
enabled_text: Color,
disabled_text: Color,
/* greying out / changing text color
*disabled: , */
}
impl Style {

View File

@ -5,7 +5,6 @@ use super::super::{
use iced::{Element, Layout, Point, Rectangle};
impl aspect_ratio_container::Renderer for IcedRenderer {
//type Style
type ImageHandle = image::Handle;
fn dimensions(&self, handle: &Self::ImageHandle) -> (u32, u32) { self.image_dims(*handle) }
@ -16,11 +15,9 @@ impl aspect_ratio_container::Renderer for IcedRenderer {
_bounds: Rectangle,
cursor_position: Point,
viewport: &Rectangle,
//style: &Self::Style,
content: &Element<'_, M, Self>,
content_layout: Layout<'_>,
) -> Self::Output {
// TODO: stlying to add a background image and such
content.draw(self, defaults, content_layout, cursor_position, viewport)
}
}

View File

@ -45,6 +45,7 @@ impl button::Renderer for IcedRenderer {
handle: (handle, Rotation::None),
bounds,
color,
source_rect: None,
};
Primitive::Group {

View File

@ -7,12 +7,7 @@ use compound_graphic::GraphicKind;
use iced::{mouse, Rectangle};
impl compound_graphic::Renderer for IcedRenderer {
fn draw<I>(
&mut self,
graphics: I,
//color: Rgba<u8>,
_layout: iced::Layout<'_>,
) -> Self::Output
fn draw<I>(&mut self, graphics: I) -> Self::Output
where
I: Iterator<Item = (Rectangle, GraphicKind)>,
{
@ -24,6 +19,7 @@ impl compound_graphic::Renderer for IcedRenderer {
handle: (handle, Rotation::None),
bounds,
color,
source_rect: None,
},
GraphicKind::Color(color) => Primitive::Rectangle {
bounds,

View File

@ -29,6 +29,7 @@ impl container::Renderer for IcedRenderer {
handle: (*handle, Rotation::None),
bounds,
color: *color,
source_rect: None,
};
Primitive::Group {
@ -177,6 +178,7 @@ impl container::Renderer for IcedRenderer {
height: border_size,
},
color,
source_rect: None,
};
let tr_corner = Primitive::Image {
@ -188,6 +190,7 @@ impl container::Renderer for IcedRenderer {
height: border_size,
},
color,
source_rect: None,
};
let bl_corner = Primitive::Image {
@ -199,6 +202,7 @@ impl container::Renderer for IcedRenderer {
height: border_size,
},
color,
source_rect: None,
};
let br_corner = Primitive::Image {
@ -210,6 +214,7 @@ impl container::Renderer for IcedRenderer {
height: border_size,
},
color,
source_rect: None,
};
let top_edge = Primitive::Image {
@ -221,6 +226,7 @@ impl container::Renderer for IcedRenderer {
height: border_size,
},
color,
source_rect: None,
};
let bottom_edge = Primitive::Image {
@ -232,6 +238,7 @@ impl container::Renderer for IcedRenderer {
height: border_size,
},
color,
source_rect: None,
};
let left_edge = Primitive::Image {
@ -243,6 +250,7 @@ impl container::Renderer for IcedRenderer {
height: bounds.height - 2.0 * border_size,
},
color,
source_rect: None,
};
let right_edge = Primitive::Image {
@ -254,6 +262,7 @@ impl container::Renderer for IcedRenderer {
height: bounds.height - 2.0 * border_size,
},
color,
source_rect: None,
};
// Is this worth it as opposed to using a giant image? (Probably)

View File

@ -19,6 +19,7 @@ impl image::Renderer for IcedRenderer {
handle: (handle, Rotation::None),
bounds: layout.bounds(),
color,
source_rect: None,
},
mouse::Interaction::default(),
)

View File

@ -22,7 +22,7 @@ impl scrollable::Renderer for IcedRenderer {
) -> Option<scrollable::Scrollbar> {
if content_bounds.height > bounds.height {
// Area containing both scrollbar and scroller
let outer_width = (scrollbar_width.max(scroller_width) + 2 * scrollbar_margin) as f32 /* * self.p_scale */;
let outer_width = (scrollbar_width.max(scroller_width) + 2 * scrollbar_margin) as f32;
let outer_bounds = Rectangle {
x: bounds.x + bounds.width - outer_width,
width: outer_width,
@ -38,14 +38,14 @@ impl scrollable::Renderer for IcedRenderer {
// Interactive scroller
let visible_fraction = bounds.height / content_bounds.height;
let scroller_height = (bounds.height * visible_fraction)
.max((2 * SCROLLBAR_MIN_HEIGHT) as f32/* * self.p_scale*/);
let scroller_height =
(bounds.height * visible_fraction).max((2 * SCROLLBAR_MIN_HEIGHT) as f32);
let y_offset = offset as f32 * visible_fraction;
let scroller_bounds = Rectangle {
x: bounds.x + bounds.width - outer_width / 2.0 - (scrollbar_width / 2) as f32, /* * self.p_scale*/
x: bounds.x + bounds.width - outer_width / 2.0 - (scrollbar_width / 2) as f32,
y: scrollbar_bounds.y + y_offset,
width: scroller_width as f32, /* * self.p_scale*/
width: scroller_width as f32,
height: scroller_height,
};
Some(scrollable::Scrollbar {
@ -85,6 +85,7 @@ impl scrollable::Renderer for IcedRenderer {
});
let style = style_sheet;
// Note: for future use if we vary style with the state of the scrollable
//let style = if state.is_scroller_grabbed() {
// style_sheet.dragging()
//} else if is_mouse_over_scrollbar {
@ -127,6 +128,7 @@ impl scrollable::Renderer for IcedRenderer {
..bounds
},
color,
source_rect: None,
});
// Middle
primitives.push(Primitive::Image {
@ -137,6 +139,7 @@ impl scrollable::Renderer for IcedRenderer {
..bounds
},
color,
source_rect: None,
});
// Bottom
primitives.push(Primitive::Image {
@ -147,6 +150,7 @@ impl scrollable::Renderer for IcedRenderer {
..bounds
},
color,
source_rect: None,
});
},
}
@ -162,6 +166,7 @@ impl scrollable::Renderer for IcedRenderer {
handle: (handle, Rotation::None),
bounds: scrollbar.bounds,
color,
source_rect: None,
},
});
}

View File

@ -40,6 +40,7 @@ impl slider::Renderer for IcedRenderer {
..bar_bounds
},
color,
source_rect: None,
},
};
@ -64,6 +65,7 @@ impl slider::Renderer for IcedRenderer {
handle: (handle, Rotation::None),
bounds: cursor_bounds,
color,
source_rect: None,
},
};

View File

@ -54,12 +54,8 @@ impl text::Renderer for IcedRenderer {
(
Primitive::Text {
glyphs,
//size: size as f32,
bounds,
linear_color: color.unwrap_or(defaults.text_color).into_linear().into(),
/*font,
*horizontal_alignment,
*vertical_alignment, */
},
mouse::Interaction::default(),
)

View File

@ -31,6 +31,7 @@ impl text_input::Renderer for IcedRenderer {
};
let mut glyph_calculator = self.cache.glyph_calculator();
// Note: keeping comments below for now in case this needs to be debugged again
/* let width = */
glyph_calculator
.glyph_bounds(section)
@ -126,6 +127,8 @@ impl text_input::Renderer for IcedRenderer {
) -> Self::Output {
let is_mouse_over = bounds.contains(cursor_position);
// Note: will be useful in the future if we vary the style with the state of the
// text input
/*
let style = if state.is_focused() {
style.focused()
@ -224,34 +227,11 @@ impl text_input::Renderer for IcedRenderer {
size,
font,
);
// TODO: delete if new arrangment behaves nicely
/*let section = glyph_brush::Section {
screen_position: (text_bounds.x * p_scale, text_bounds.center_y() * p_scale),
bounds: (
10000.0, /* text_bounds.width * p_scale */
text_bounds.height * p_scale,
),
layout: glyph_brush::Layout::SingleLine {
line_breaker: Default::default(),
h_align: glyph_brush::HorizontalAlign::Left,
v_align: glyph_brush::VerticalAlign::Center,
},
text: vec![glyph_brush::Text {
text: display_text,
scale: (size as f32 * p_scale).into(),
font_id: font.0,
extra: (),
}],
};*/
let text_primitive = Primitive::Text {
glyphs,
//size: size as f32,
bounds,
linear_color,
/*font,
*horizontal_alignment,
*vertical_alignment, */
};
let primitive = match cursor_primitive {

View File

@ -169,8 +169,6 @@ where
}
pub trait Renderer: iced::Renderer {
/// The style supported by this renderer.
//type Style: Default;
/// The handle used by this renderer for images.
type ImageHandle: Hash;
@ -182,7 +180,6 @@ pub trait Renderer: iced::Renderer {
bounds: Rectangle,
cursor_position: Point,
viewport: &Rectangle,
//style: &Self::Style,
content: &Element<'_, M, Self>,
content_layout: Layout<'_>,
) -> Self::Output;

View File

@ -86,8 +86,6 @@ pub trait Background<R: iced::Renderer>: Sized {
/// This widget is displays a background image behind it's content
pub struct BackgroundContainer<'a, M, R: self::Renderer, B: Background<R>> {
//width: Length,
//height: Length,
max_width: u32,
max_height: u32,
background: B,
@ -104,8 +102,6 @@ where
{
pub fn new(background: B, content: impl Into<Element<'a, M, R>>) -> Self {
Self {
//width: Length::Shrink,
//height: Length::Shrink,
max_width: u32::MAX,
max_height: u32::MAX,
background,
@ -119,16 +115,6 @@ where
self
}
/*pub fn width(mut self, width: Length) -> Self {
self.width = width;
self
}
pub fn height(mut self, height: Length) -> Self {
self.height = height;
self
}*/
pub fn max_width(mut self, max_width: u32) -> Self {
self.max_width = max_width;
self
@ -138,17 +124,6 @@ where
self.max_height = max_height;
self
}
// Consider having these wire into underlying background
/*pub fn fix_aspect_ratio(mut self) -> Self {
self.fix_aspect_ratio = true;
self
}
pub fn color(mut self, color: Rgba<u8>) -> Self {
self.color = color;
self
}*/
}
impl<'a, M, R, B> Widget<M, R> for BackgroundContainer<'a, M, R, B>
@ -221,7 +196,6 @@ where
// TODO: handle cases where self and/or children are not Length::Fill
// If fill use max_size
//if match self.width(), self.height()
// This time we need to adjust up to meet the aspect ratio
// so that the container is larger than the contents

View File

@ -128,15 +128,7 @@ impl CompoundGraphic {
// self
//}
fn draw<R: self::Renderer>(
&self,
renderer: &mut R,
_defaults: &R::Defaults,
layout: Layout<'_>,
_cursor_position: Point,
// Note: could use to skip elements outside the viewport
_viewport: &Rectangle,
) -> R::Output {
fn draw<R: self::Renderer>(&self, renderer: &mut R, layout: Layout<'_>) -> R::Output {
let [pixel_w, pixel_h] = self.graphics_size;
let bounds = layout.bounds();
let scale = Vec2::new(
@ -158,7 +150,7 @@ impl CompoundGraphic {
(bounds, graphic.kind)
});
renderer.draw(graphics, /* self.color, */ layout)
renderer.draw(graphics)
}
}
@ -194,12 +186,13 @@ where
fn draw(
&self,
renderer: &mut R,
defaults: &R::Defaults,
_defaults: &R::Defaults,
layout: Layout<'_>,
cursor_position: Point,
viewport: &Rectangle,
_cursor_position: Point,
// Note: could use to skip elements outside the viewport
_viewport: &Rectangle,
) -> R::Output {
Self::draw(self, renderer, defaults, layout, cursor_position, viewport)
Self::draw(self, renderer, layout)
}
fn hash_layout(&self, state: &mut Hasher) {
@ -215,12 +208,7 @@ where
}
pub trait Renderer: iced::Renderer {
fn draw<I>(
&mut self,
graphics: I,
//color: Rgba<u8>,
layout: Layout<'_>,
) -> Self::Output
fn draw<I>(&mut self, graphics: I) -> Self::Output
where
I: Iterator<Item = (Rectangle, GraphicKind)>;
}
@ -251,11 +239,11 @@ where
fn draw(
&self,
renderer: &mut R,
defaults: &R::Defaults,
_defaults: &R::Defaults,
layout: Layout<'_>,
cursor_position: Point,
viewport: &Rectangle,
_cursor_position: Point,
_viewport: &Rectangle,
) -> R::Output {
Self::draw(self, renderer, defaults, layout, cursor_position, viewport)
Self::draw(self, renderer, layout)
}
}

View File

@ -16,23 +16,13 @@ impl State {
pub struct MouseDetector<'a> {
width: Length,
height: Length,
//on_enter: M,
//on_exit: M,
state: &'a mut State,
}
impl<'a> MouseDetector<'a> {
pub fn new(
state: &'a mut State,
//on_enter: M,
//on_exit: M,
width: Length,
height: Length,
) -> Self {
pub fn new(state: &'a mut State, width: Length, height: Length) -> Self {
Self {
state,
//on_enter,
//on_exit,
width,
height,
}
@ -70,12 +60,6 @@ where
&& y < bounds.y + bounds.height;
if mouse_over != self.state.mouse_over {
self.state.mouse_over = mouse_over;
/*messages.push(if mouse_over {
self.on_enter.clone()
} else {
self.on_exit.clone()
});*/
}
}
}

View File

@ -213,7 +213,6 @@ pub trait Renderer: iced::Renderer {
bounds: Rectangle,
cursor_position: Point,
viewport: &Rectangle,
//style: &self::Style,
over: &Element<'_, M, Self>,
over_layout: Layout<'_>,
under: &Element<'_, M, Self>,

View File

@ -4,17 +4,6 @@ use std::hash::Hash;
/// Stack up some widgets
pub struct Stack<'a, M, R> {
// Add these if it is useful
/*
padding: u16,
width: Length,
height: Length,
max_width: u32,
max_height: u32,
horizontal_alignment: Align,
vertical_alignment: Align
align_items: Align,
*/
children: Vec<Element<'a, M, R>>,
}

View File

@ -310,14 +310,11 @@ where
const PAD: f32 = 8.0; // TODO: allow configuration
let space_above = (avoid.y - PAD).max(0.0);
let space_below = (bounds.height - avoid.y - avoid.height - PAD).max(0.0);
//let space_left = avoid.x.min(0.0)
//let space_right = (bounds.width - avoid.x - avoid.width).min(0.0);
let limits = layout::Limits::new(
Size::ZERO,
Size::new(bounds.width, space_above.max(space_below)),
);
//.width(self.content.width());
let mut node = self.content.layout(renderer, &limits);
@ -360,7 +357,6 @@ where
self.alpha,
defaults,
cursor_position,
// TODO: hopefully this works
&layout.bounds(),
&self.content,
layout,