diff options
author | 2019-10-08 03:13:41 +0200 | |
---|---|---|
committer | 2019-10-08 03:13:41 +0200 | |
commit | 10e10e5e06841574425d2633f1c2916733f7b4ff (patch) | |
tree | 0407a0136973a201fe44bfc1a94268544a2f8eb5 /wgpu/src/renderer.rs | |
parent | a0234d5bcea5b25f575af01d3a8e0296b2d0395c (diff) | |
download | iced-10e10e5e06841574425d2633f1c2916733f7b4ff.tar.gz iced-10e10e5e06841574425d2633f1c2916733f7b4ff.tar.bz2 iced-10e10e5e06841574425d2633f1c2916733f7b4ff.zip |
Make `iced_core::Button` customizable
Now it supports:
- Any kind of content
- Custom border radius
- Custom background
Diffstat (limited to 'wgpu/src/renderer.rs')
-rw-r--r-- | wgpu/src/renderer.rs | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index 9883943b..ae5692e3 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -1,5 +1,7 @@ -use crate::{quad, Background, Primitive, Quad, Transformation}; -use iced_native::{renderer::Debugger, Color, Layout, Point, Widget}; +use crate::{quad, Primitive, Quad, Transformation}; +use iced_native::{ + renderer::Debugger, Background, Color, Layout, Point, Widget, +}; use raw_window_handle::HasRawWindowHandle; use wgpu::{ @@ -159,20 +161,74 @@ impl Renderer { content, bounds, size, - } => self.glyph_brush.borrow_mut().queue(Section { - text: &content, - screen_position: (bounds.x, bounds.y), - bounds: (bounds.width, bounds.height), - scale: wgpu_glyph::Scale { x: *size, y: *size }, - ..Default::default() - }), - Primitive::Quad { bounds, background } => { + color, + horizontal_alignment, + vertical_alignment, + } => { + let x = match horizontal_alignment { + iced_native::text::HorizontalAlignment::Left => bounds.x, + iced_native::text::HorizontalAlignment::Center => { + bounds.x + bounds.width / 2.0 + } + iced_native::text::HorizontalAlignment::Right => { + bounds.x + bounds.width + } + }; + + let y = match vertical_alignment { + iced_native::text::VerticalAlignment::Top => bounds.y, + iced_native::text::VerticalAlignment::Center => { + bounds.y + bounds.height / 2.0 + } + iced_native::text::VerticalAlignment::Bottom => { + bounds.y + bounds.height + } + }; + + self.glyph_brush.borrow_mut().queue(Section { + text: &content, + screen_position: (x, y), + bounds: (bounds.width, bounds.height), + scale: wgpu_glyph::Scale { x: *size, y: *size }, + color: color.into_linear(), + layout: wgpu_glyph::Layout::default() + .h_align(match horizontal_alignment { + iced_native::text::HorizontalAlignment::Left => { + wgpu_glyph::HorizontalAlign::Left + } + iced_native::text::HorizontalAlignment::Center => { + wgpu_glyph::HorizontalAlign::Center + } + iced_native::text::HorizontalAlignment::Right => { + wgpu_glyph::HorizontalAlign::Right + } + }) + .v_align(match vertical_alignment { + iced_native::text::VerticalAlignment::Top => { + wgpu_glyph::VerticalAlign::Top + } + iced_native::text::VerticalAlignment::Center => { + wgpu_glyph::VerticalAlign::Center + } + iced_native::text::VerticalAlignment::Bottom => { + wgpu_glyph::VerticalAlign::Bottom + } + }), + ..Default::default() + }) + } + Primitive::Quad { + bounds, + background, + border_radius, + } => { self.quads.push(Quad { position: [bounds.x, bounds.y], scale: [bounds.width, bounds.height], color: match background { Background::Color(color) => color.into_linear(), }, + border_radius: u32::from(*border_radius), }); } } |