Skip to content

Commit

Permalink
优化图标组件加载
Browse files Browse the repository at this point in the history
修正组件布局
  • Loading branch information
Steve-xmh committed Nov 3, 2023
1 parent d4c3464 commit 09c570a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 11 additions & 1 deletion scl-gui-widgets/src/widgets/icon_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use druid::{
widget::{prelude::*, Click, ControllerHost},
Affine, Data,
};
use tracing::warn;

use crate::theme::{color as theme, icons::IconKeyPair};

Expand Down Expand Up @@ -89,7 +90,16 @@ impl<T: Data> IconButton<T> {
}

fn reload_icon(&mut self, env: &Env) {
self.icon_path = BezPath::from_svg(env.get(&self.icon_key.0).as_str()).unwrap_or_default();
let key = env.get(&self.icon_key.0);
let svg_path = key.as_str();
match BezPath::from_svg(svg_path) {
Ok(path) => {
self.icon_path = path;
}
Err(err) => {
warn!("无法读取 SVG 填充路径字符串 {svg_path:?}: {err:?}");
}
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions scl-gui-widgets/src/widgets/on_notify.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use druid::{widget::prelude::*, Selector, WidgetPod};
use druid::{widget::prelude::*, Selector, WidgetPod, Point};

type OnNotifyHandler<CT, WT> = Box<dyn Fn(&mut EventCtx, &CT, &mut WT)>;

Expand Down Expand Up @@ -47,7 +47,9 @@ impl<WT: Data, CT: 'static> Widget<WT> for OnNotify<CT, WT> {
}

fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints, data: &WT, env: &Env) -> Size {
self.inner.layout(ctx, bc, data, env)
let size = self.inner.layout(ctx, bc, data, env);
self.inner.set_origin(ctx, Point::ZERO);
size
}

fn paint(&mut self, ctx: &mut PaintCtx, data: &WT, env: &Env) {
Expand Down

0 comments on commit 09c570a

Please sign in to comment.