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 cd57d10 commit d4c3464
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
20 changes: 7 additions & 13 deletions scl-gui-widgets/src/widgets/download_module_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ impl<D: Data> DownloadModuleItem<D> {
.with_text_size(14.)
.with_text_color(base::MEDIUM)
.with_font(BODY)
.with_line_break_mode(druid::widget::LineBreaking::Clip)
.align_vertical(druid::UnitPoint::LEFT),
)),
desc: WidgetPod::new(Box::new(
label::dynamic(desc)
.with_text_color(base::MEDIUM)
.with_font(CAPTION_ALT)
.with_line_break_mode(druid::widget::LineBreaking::Clip)
.align_vertical(druid::UnitPoint::RIGHT),
)),
}
Expand Down Expand Up @@ -145,19 +143,15 @@ impl<D: Data> Widget<D> for DownloadModuleItem<D> {
data: &D,
env: &druid::Env,
) -> druid::Size {
bc.debug_check("LoginMethodItem");
let min_height = 40.;
let min_bc = BoxConstraints::new(
(bc.min().width, min_height).into(),
(bc.max().width, min_height).into(),
);
let text_bc = min_bc.shrink((40., 0.));
let desc_bc = min_bc.shrink((50., 0.));
let _text_size = self.text.layout(ctx, &text_bc, data, env);
let _desc_size = self.desc.layout(ctx, &desc_bc, data, env);
bc.debug_check("DownloadModuleItem");
let bc = bc.shrink_max_height_to(40.);
let text_bc = bc.shrink((40., 0.));
let desc_bc = bc.shrink((50., 0.));
let text_size = self.text.layout(ctx, &text_bc, data, env);
let desc_size = self.desc.layout(ctx, &desc_bc, data, env);
self.text.set_origin(ctx, (40., 0.).into());
self.desc.set_origin(ctx, (40., 0.).into());
min_bc.constrain((0., min_height))
bc.constrain((text_size.width.max(desc_size.width) + 40., 40.))
}

fn paint(&mut self, ctx: &mut druid::PaintCtx, data: &D, env: &druid::Env) {
Expand Down
18 changes: 9 additions & 9 deletions scl-gui-widgets/src/widgets/large_list_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ impl<D: Data> Widget<D> for LargeListItem<D> {
data: &D,
env: &druid::Env,
) -> druid::Size {
bc.debug_check("LoginMethodItem");
let text_bc =
BoxConstraints::new(Size::ZERO, Size::new(bc.max().width - 60., bc.max().height));
bc.debug_check("LargeListItem");
let text_bc = bc
.shrink_max_width_to(bc.max().width - 60.)
.shrink_max_height_to(bc.max().height / 2.)
.loosen();
let text_size = self.text.layout(ctx, &text_bc, data, env);
let desc_size = self.desc.layout(ctx, &text_bc, data, env);
let text_height = text_size.height;
let desc_height = desc_size.height;
let height = (desc_height + text_height + 27.).max(60.);
let start_pos = (height - text_height - desc_height) / 2.;
let height = text_size.height + desc_size.height + 27.;
let start_pos = (height - text_size.height - desc_size.height) / 2. - 2.;
self.text.set_origin(ctx, Point::new(60., start_pos));
self.desc
.set_origin(ctx, Point::new(60., start_pos + text_height));
bc.constrain((0., height))
.set_origin(ctx, Point::new(60., start_pos + text_size.height + 2.));
bc.constrain((text_size.width.max(desc_size.width) + 60., height))
}

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

0 comments on commit d4c3464

Please sign in to comment.