Skip to content

Commit

Permalink
fix: add scale factor to renderer style
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Aug 18, 2023
1 parent 340d312 commit 3f5e8c1
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ pub struct Quad {
pub struct Style {
/// The text color
pub text_color: Color,
/// The scale factor
pub scale_factor: f64,
}

impl Default for Style {
fn default() -> Self {
Style {
text_color: Color::BLACK,
scale_factor: 1.0,
}
}
}
3 changes: 2 additions & 1 deletion examples/integration/src/controls.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use iced_wgpu::core::window::Id;
use iced_wgpu::Renderer;
use iced_widget::{slider, text_input, Column, Row, Text};
use iced_winit::core::{Alignment, Color, Element, Length};
Expand Down Expand Up @@ -45,7 +46,7 @@ impl Program for Controls {
Command::none()
}

fn view(&self) -> Element<Message, Renderer<Theme>> {
fn view(&self, _: Id) -> Element<Message, Renderer<Theme>> {
let background_color = self.background_color;
let text = &self.text;

Expand Down
4 changes: 4 additions & 0 deletions examples/integration/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod scene;
use controls::Controls;
use scene::Scene;

use iced_wgpu::core::window::Id;
use iced_wgpu::graphics::Viewport;
use iced_wgpu::{wgpu, Backend, Renderer, Settings};
use iced_winit::core::mouse;
Expand Down Expand Up @@ -151,6 +152,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
));

let mut state = program::State::new(
Id(0),
controls,
viewport.logical_size(),
&mut renderer,
Expand Down Expand Up @@ -194,6 +196,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
if !state.is_queue_empty() {
// We update iced
let _ = state.update(
Id(0),
viewport.logical_size(),
cursor_position
.map(|p| {
Expand All @@ -208,6 +211,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
&Theme::Dark,
&renderer::Style {
text_color: Color::WHITE,
scale_factor: viewport.scale_factor(),
},
&mut clipboard,
&mut debug,
Expand Down
2 changes: 2 additions & 0 deletions sctk/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ where
state.theme(),
&Style {
text_color: state.text_color(),
scale_factor: state.scale_factor(),
},
state.cursor(),
);
Expand Down Expand Up @@ -1306,6 +1307,7 @@ where
state.theme(),
&Style {
text_color: state.text_color(),
scale_factor: state.scale_factor(),
},
state.cursor(),
);
Expand Down
3 changes: 2 additions & 1 deletion widget/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ where
tree: &Tree,
renderer: &mut Renderer,
theme: &Renderer::Theme,
_style: &renderer::Style,
renderer_style: &renderer::Style,
layout: Layout<'_>,
cursor: mouse::Cursor,
_viewport: &Rectangle,
Expand All @@ -317,6 +317,7 @@ where
theme,
&renderer::Style {
text_color: styling.text_color,
scale_factor: renderer_style.scale_factor,
},
content_layout,
cursor,
Expand Down
1 change: 1 addition & 0 deletions widget/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ where
text_color: style
.text_color
.unwrap_or(renderer_style.text_color),
scale_factor: renderer_style.scale_factor,
},
layout.children().next().unwrap(),
cursor,
Expand Down
1 change: 1 addition & 0 deletions widget/src/pane_grid/title_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ where
let style = theme.appearance(&self.style);
let inherited_style = renderer::Style {
text_color: style.text_color.unwrap_or(inherited_style.text_color),
scale_factor: inherited_style.scale_factor,
};

container::draw_background(renderer, &style, bounds);
Expand Down
1 change: 1 addition & 0 deletions widget/src/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ where

let defaults = renderer::Style {
text_color: style.text_color.unwrap_or(inherited_style.text_color),
scale_factor: inherited_style.scale_factor,
};

Widget::<(), Renderer>::draw(
Expand Down
2 changes: 2 additions & 0 deletions winit/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ async fn run_instance<A, E, C>(
state.theme(),
&renderer::Style {
text_color: state.text_color(),
scale_factor: state.scale_factor(),
},
state.cursor(),
);
Expand Down Expand Up @@ -671,6 +672,7 @@ async fn run_instance<A, E, C>(
state.theme(),
&renderer::Style {
text_color: state.text_color(),
scale_factor: state.scale_factor(),
},
state.cursor(),
);
Expand Down

0 comments on commit 3f5e8c1

Please sign in to comment.