Skip to content

Commit

Permalink
Yet another iced update
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Jul 21, 2024
1 parent d90b1a3 commit 951e426
Show file tree
Hide file tree
Showing 22 changed files with 197 additions and 226 deletions.
141 changes: 65 additions & 76 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ resolver = "2"

[workspace.dependencies]
wgpu = "0.19"
glyphon = "0.5"
glyphon = { git = "https://github.com/hecrj/glyphon.git", rev = "feef9f5630c2adb3528937e55f7bfad2da561a65" }
# glyphon = "0.5"
log = "0.4"
bytemuck = { version = "1.5", features = ["derive"] }
env_logger = "0.11"
Expand All @@ -34,13 +35,13 @@ nuon = { path = "./nuon" }

profiling = "1.0"

iced_graphics = { git = "https://github.com/iced-rs/iced.git", rev = "b9eb86199afe0f2d936eb4ab90af5b2a2c32a87a" }
iced_core = { git = "https://github.com/iced-rs/iced.git", rev = "b9eb86199afe0f2d936eb4ab90af5b2a2c32a87a" }
iced_runtime = { git = "https://github.com/iced-rs/iced.git", rev = "b9eb86199afe0f2d936eb4ab90af5b2a2c32a87a" }
iced_renderer = { git = "https://github.com/iced-rs/iced.git", rev = "b9eb86199afe0f2d936eb4ab90af5b2a2c32a87a" }
iced_wgpu = { git = "https://github.com/iced-rs/iced.git", rev = "b9eb86199afe0f2d936eb4ab90af5b2a2c32a87a", features = [
iced_graphics = { git = "https://github.com/iced-rs/iced.git", rev = "4b44079f34aa9e01977a7974e5f49ae79ff6cd90" }
iced_core = { git = "https://github.com/iced-rs/iced.git", rev = "4b44079f34aa9e01977a7974e5f49ae79ff6cd90" }
iced_runtime = { git = "https://github.com/iced-rs/iced.git", rev = "4b44079f34aa9e01977a7974e5f49ae79ff6cd90" }
iced_renderer = { git = "https://github.com/iced-rs/iced.git", rev = "4b44079f34aa9e01977a7974e5f49ae79ff6cd90" }
iced_wgpu = { git = "https://github.com/iced-rs/iced.git", rev = "4b44079f34aa9e01977a7974e5f49ae79ff6cd90", features = [
"image",
] }
iced_widget = { git = "https://github.com/iced-rs/iced.git", rev = "b9eb86199afe0f2d936eb4ab90af5b2a2c32a87a", features = [
iced_widget = { git = "https://github.com/iced-rs/iced.git", rev = "4b44079f34aa9e01977a7974e5f49ae79ff6cd90", features = [
"image",
] }
2 changes: 1 addition & 1 deletion neothesia-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Recorder {
self.quad_pipeline
.prepare(&self.gpu.device, &self.gpu.queue);

self.text.update((self.width, self.height), &self.gpu);
self.text.update((self.width, self.height), &mut self.gpu);
}

fn render(
Expand Down
4 changes: 2 additions & 2 deletions neothesia-core/src/render/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl KeyboardRenderer {

let mut buffer =
glyphon::Buffer::new(text.font_system(), glyphon::Metrics::new(size, size));
buffer.set_size(text.font_system(), w, h);
buffer.set_size(text.font_system(), Some(w), Some(h));
buffer.set_wrap(text.font_system(), glyphon::Wrap::None);
buffer.set_text(
text.font_system(),
Expand All @@ -154,7 +154,7 @@ impl KeyboardRenderer {
glyphon::Shaping::Basic,
);
buffer.lines[0].set_align(Some(glyphon::cosmic_text::Align::Center));
buffer.shape_until_scroll(text.font_system());
buffer.shape_until_scroll(text.font_system(), false);

text.queue(super::text::TextArea {
buffer,
Expand Down
48 changes: 31 additions & 17 deletions neothesia-core/src/render/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ pub struct TextArea {
}

pub struct TextRenderer {
viewport: glyphon::Viewport,
font_system: glyphon::FontSystem,
cache: glyphon::SwashCache,
swash_cache: glyphon::SwashCache,
atlas: glyphon::TextAtlas,
text_renderer: glyphon::TextRenderer,

Expand All @@ -37,18 +38,23 @@ impl TextRenderer {
))),
]);

let cache = glyphon::SwashCache::new();
let mut atlas = glyphon::TextAtlas::new(&gpu.device, &gpu.queue, gpu.texture_format);
let swash_cache = glyphon::SwashCache::new();
let cache = glyphon::Cache::new(&gpu.device);
let mut atlas =
glyphon::TextAtlas::new(&gpu.device, &gpu.queue, &cache, gpu.texture_format);
let text_renderer = glyphon::TextRenderer::new(
&mut atlas,
&gpu.device,
wgpu::MultisampleState::default(),
None,
);

let viewport = glyphon::Viewport::new(&gpu.device, &cache);

Self {
viewport,
font_system,
cache,
swash_cache,
atlas,
text_renderer,
queue: Vec::new(),
Expand All @@ -70,14 +76,14 @@ impl TextRenderer {
pub fn queue_text(&mut self, text: &str) {
let mut buffer =
glyphon::Buffer::new(&mut self.font_system, glyphon::Metrics::new(15.0, 15.0));
buffer.set_size(&mut self.font_system, f32::MAX, f32::MAX);
buffer.set_size(&mut self.font_system, Some(f32::MAX), Some(f32::MAX));
buffer.set_text(
&mut self.font_system,
text,
glyphon::Attrs::new().family(glyphon::Family::SansSerif),
glyphon::Shaping::Basic,
);
buffer.shape_until_scroll(&mut self.font_system);
buffer.shape_until_scroll(&mut self.font_system, false);

#[cfg(debug_assertions)]
let top = 20.0;
Expand All @@ -97,14 +103,14 @@ impl TextRenderer {
pub fn queue_icon(&mut self, x: f32, y: f32, size: f32, icon: &str) {
let mut buffer =
glyphon::Buffer::new(&mut self.font_system, glyphon::Metrics::new(size, size));
buffer.set_size(&mut self.font_system, f32::MAX, f32::MAX);
buffer.set_size(&mut self.font_system, Some(f32::MAX), Some(f32::MAX));
buffer.set_text(
&mut self.font_system,
icon,
glyphon::Attrs::new().family(glyphon::Family::Name("bootstrap-icons")),
glyphon::Shaping::Basic,
);
buffer.shape_until_scroll(&mut self.font_system);
buffer.shape_until_scroll(&mut self.font_system, false);

self.queue(TextArea {
buffer,
Expand All @@ -120,14 +126,14 @@ impl TextRenderer {
let text = format!("FPS: {}", fps.round() as u32);
let mut buffer =
glyphon::Buffer::new(&mut self.font_system, glyphon::Metrics::new(15.0, 15.0));
buffer.set_size(&mut self.font_system, f32::MAX, f32::MAX);
buffer.set_size(&mut self.font_system, Some(f32::MAX), Some(f32::MAX));
buffer.set_text(
&mut self.font_system,
&text,
glyphon::Attrs::new().family(glyphon::Family::SansSerif),
glyphon::Shaping::Basic,
);
buffer.shape_until_scroll(&mut self.font_system);
buffer.shape_until_scroll(&mut self.font_system, false);

self.queue(TextArea {
buffer,
Expand All @@ -140,7 +146,7 @@ impl TextRenderer {
}

#[profiling::function]
pub fn update(&mut self, logical_size: (u32, u32), gpu: &Gpu) {
pub fn update(&mut self, logical_size: (u32, u32), gpu: &mut Gpu) {
let elements = self.queue.iter().map(|area| glyphon::TextArea {
buffer: &area.buffer,
left: area.left,
Expand All @@ -150,25 +156,33 @@ impl TextRenderer {
default_color: area.default_color,
});

self.viewport.update(
&gpu.queue,
glyphon::Resolution {
width: logical_size.0,
height: logical_size.1,
},
);

self.text_renderer
.prepare(
&gpu.device,
&gpu.queue,
&mut gpu.encoder,
&mut self.font_system,
&mut self.atlas,
glyphon::Resolution {
width: logical_size.0,
height: logical_size.1,
},
&self.viewport,
elements,
&mut self.cache,
&mut self.swash_cache,
)
.unwrap();

self.queue.clear();
}

pub fn render<'rpass>(&'rpass mut self, render_pass: &mut wgpu::RenderPass<'rpass>) {
self.text_renderer.render(&self.atlas, render_pass).unwrap();
self.text_renderer
.render(&self.atlas, &self.viewport, render_pass)
.unwrap();
}
}
16 changes: 6 additions & 10 deletions neothesia-iced-widgets/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ impl<'a, M: 'static> Layout<'a, M> {
let body = col![body]
.width(Length::Fill)
.height(Length::Fill)
.align_items(Alignment::Center);
.align_x(Alignment::Center);

let top = self
.top
.map(|top| col![top].width(Length::Fill).align_items(Alignment::Center));
let bottom = self.bottom.map(|bottom| {
col![bottom]
.width(Length::Fill)
.align_items(Alignment::Center)
});
.map(|top| col![top].width(Length::Fill).align_x(Alignment::Center));
let bottom = self
.bottom
.map(|bottom| col![bottom].width(Length::Fill).align_x(Alignment::Center));

col![]
.push_maybe(top)
Expand Down Expand Up @@ -113,9 +111,7 @@ impl<'a, M: 'static> BarLayout<'a, M> {
let center = row![].push_maybe(self.center).width(Length::Fill);
let right = row![].push_maybe(self.right).width(Length::Fill);

row![left, center, right]
.align_items(Alignment::Center)
.into()
row![left, center, right].align_y(Alignment::Center).into()
}
}

Expand Down
8 changes: 1 addition & 7 deletions neothesia-iced-widgets/src/neo_btn.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::Renderer;
use iced_core::{
alignment::{Horizontal, Vertical},
border::Radius,
layout, mouse,
renderer::Style,
Expand All @@ -24,12 +23,7 @@ pub struct NeoBtn<'a, Message> {

impl<'a, Message: Clone> NeoBtn<'a, Message> {
pub fn new_with_label(label: &'a str) -> Self {
Self::new(
text(label)
.size(30)
.vertical_alignment(Vertical::Center)
.horizontal_alignment(Horizontal::Center),
)
Self::new(text(label).size(30).center())
}

pub fn new<E>(content: E) -> Self
Expand Down
18 changes: 15 additions & 3 deletions neothesia-iced-widgets/src/piano_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,23 @@ impl<M, R: iced_core::Renderer> Widget<M, Theme, R> for PianoRange {
bounds,
border: Border {
radius: if n == 0 {
Radius::from([12.0, 0.0, 5.0, 12.0])
Radius::new(0.0)
.top_left(12.0)
.top_right(0.0)
.bottom_right(5.0)
.bottom_left(12.0)
} else if neutral.peek().is_none() {
Radius::from([0.0, 12.0, 12.0, 5.0])
Radius::new(0.0)
.top_left(0.0)
.top_right(12.0)
.bottom_right(12.0)
.bottom_left(5.0)
} else {
Radius::from([0.0, 0.0, 5.0, 5.0])
Radius::new(0.0)
.top_left(0.0)
.top_right(0.0)
.bottom_right(5.0)
.bottom_left(5.0)
},
width: 0.0,
color: Color::TRANSPARENT,
Expand Down
2 changes: 1 addition & 1 deletion neothesia-iced-widgets/src/preferences_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn triple_split<'a, T: 'a>(
row = row.push(row![].push_maybe(center).width(Length::Fill));
row = row.push(row![].push_maybe(suffix).width(Length::Shrink));

row.align_items(iced_core::Alignment::Center).spacing(6)
row.align_y(iced_core::Alignment::Center).spacing(6)
}

fn group_header<'a, T: 'a>(data: PreferencesGroupHeader) -> Element<'a, T> {
Expand Down
8 changes: 2 additions & 6 deletions neothesia-iced-widgets/src/segment_button/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{Element, Renderer};
use iced_core::{
alignment::{Horizontal, Vertical},
Color, Length, Theme,
};
use iced_core::{Color, Length, Theme};

mod theme;

Expand Down Expand Up @@ -46,8 +43,7 @@ impl<MSG> SegmentButton<MSG> {
fn segment<'a, MSG: 'a>(label: &str) -> iced_widget::Button<'a, MSG, Theme, Renderer> {
iced_widget::button(
iced_widget::text(label.to_string())
.horizontal_alignment(Horizontal::Center)
.vertical_alignment(Vertical::Center)
.center()
.width(Length::Fill)
.height(Length::Fill),
)
Expand Down
14 changes: 12 additions & 2 deletions neothesia-iced-widgets/src/segment_button/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ pub fn segment_button<T>(
match status {
button::Status::Active => {
let border_radius = match kind {
ButtonSegmentKind::Start => Radius::from([255.0, 0.0, 0.0, 255.0]),
ButtonSegmentKind::Start => Radius {
top_left: 255.0,
top_right: 0.0,
bottom_right: 0.0,
bottom_left: 255.0,
},
ButtonSegmentKind::Center => Radius::from(0.0),
ButtonSegmentKind::End => Radius::from([0.0, 255.0, 255.0, 0.0]),
ButtonSegmentKind::End => Radius {
top_left: 0.0,
top_right: 255.0,
bottom_right: 255.0,
bottom_left: 0.0,
},
};

let background = if active {
Expand Down
2 changes: 1 addition & 1 deletion neothesia-iced-widgets/src/track_card/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a, M: Clone + 'a> From<TrackCard<'a, M>> for Element<'a, M> {
iced_widget::text(card.subtitle).size(14).into(),
])
.spacing(4)
.align_items(Alignment::Start),
.align_x(Alignment::Start),
]
.spacing(16)
};
Expand Down
Binary file modified neothesia/src/iced_utils/bootstrap-icons.ttf
Binary file not shown.
8 changes: 4 additions & 4 deletions neothesia/src/iced_utils/iced_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! https://github.com/hecrj/iced/blob/master/winit/src/conversion.rs
use iced_core::{
keyboard::{self},
mouse, touch, window, Event, Point,
mouse, touch, window, Event, Point, Size,
};

/// The position of a window in a given screen.
Expand Down Expand Up @@ -54,10 +54,10 @@ pub fn window_event(
WindowEvent::Resized(new_size) => {
let logical_size = new_size.to_logical(scale_factor);

Some(Event::Window(window::Event::Resized {
Some(Event::Window(window::Event::Resized(Size {
width: logical_size.width,
height: logical_size.height,
}))
})))
}
WindowEvent::CloseRequested => Some(Event::Window(window::Event::CloseRequested)),
WindowEvent::CursorMoved { position, .. } => {
Expand Down Expand Up @@ -149,7 +149,7 @@ pub fn window_event(
WindowEvent::Moved(position) => {
let winit::dpi::LogicalPosition { x, y } = position.to_logical(scale_factor);

Some(Event::Window(window::Event::Moved { x, y }))
Some(Event::Window(window::Event::Moved(Point { x, y })))
}
WindowEvent::RedrawRequested => Some(Event::Window(window::Event::RedrawRequested(
iced_core::time::Instant::now(),
Expand Down
2 changes: 1 addition & 1 deletion neothesia/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl Neothesia {
self.game_scene.update(&mut self.context, delta);
self.context.text_renderer.update(
self.context.window_state.logical_size.into(),
&self.context.gpu,
&mut self.context.gpu,
);
}

Expand Down
2 changes: 1 addition & 1 deletion neothesia/src/scene/menu_scene/iced_menu/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Page for ExitPage {
.height(Length::Fixed(50.0));

let controls = col![output, select_row]
.align_items(Alignment::Center)
.align_x(Alignment::Center)
.width(Length::Fixed(650.0))
.spacing(30);

Expand Down
Loading

0 comments on commit 951e426

Please sign in to comment.