Skip to content

Commit

Permalink
[libgui] Update clients for Label API change
Browse files Browse the repository at this point in the history
  • Loading branch information
codyd51 committed Feb 7, 2024
1 parent 520fc3a commit 0d9677f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
13 changes: 7 additions & 6 deletions rust_programs/dock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ impl TaskView {
// We'll draw the border ourselves, so the inner View shouldn't
view.set_border_enabled(false);

// TODO(PT): Sizer for labels?
// TODO(PT): Sizer
let title_label = Rc::new(Label::new(
Rect::from_parts(
Point::new(insets.left + 4, insets.top + 4),
Size::new(300, 30),
),
&title,
Color::new(30, 30, 30),
move |label, superview_size| {
Rect::from_parts(Point::new(insets.left + 4, insets.top), Size::new(300, 30))
},
));
let title_label_clone = Rc::clone(&title_label);
// TODO(PT): Set font size as attribute?
Expand All @@ -82,12 +81,13 @@ impl TaskView {
}

fn text_width(self: &Rc<Self>) -> usize {
8 * self.title.borrow().len()
20 * self.title.borrow().len()
}

fn resize_title_label(self: &Rc<Self>, superview_size: Size) {
// TODO(PT): This is a hack until labels have sizers
// TODO(PT): Expose font size of labels
//let font_size = Size::new(20, 20);
let font_size = Size::new(8, 10);
let insets = Self::border_insets();
let usable_frame = Rect::from_parts(Point::zero(), superview_size).inset_by_insets(insets);
Expand All @@ -97,6 +97,7 @@ impl TaskView {
Point::new(
usable_frame.mid_x() - (text_width / 2),
usable_frame.mid_y() - (font_size.height / 2),
//usable_frame.min_y(),
),
Size::new(text_width, font_size.height),
);
Expand Down
2 changes: 1 addition & 1 deletion rust_programs/example_program/src/main_axle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ impl WindowState {
Rc::clone(&window).add_component(Rc::clone(&content_view) as Rc<dyn UIElement>);

let label = Rc::new(Label::new(
Rect::from_parts(Point::new(4, 4), Size::new(300, 30)),
"Hello from Rust!!",
Color::black(),
|label, superview_size| Rect::from_parts(Point::new(4, 4), Size::new(300, 30)),
));
Rc::clone(&content_view).add_component(Rc::clone(&label) as Rc<dyn UIElement>);

Expand Down
2 changes: 1 addition & 1 deletion rust_programs/file_browser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ impl CurrentPathView {

let initial_path = "/";
let current_path_label = Rc::new(Label::new(
Rect::new(10, 10, 400, 16),
&format!("Current path: {}", initial_path),
Color::new(30, 30, 30),
|_, _| Rect::new(10, 10, 400, 16),
));
let current_path_label_clone = Rc::clone(&current_path_label);
Rc::clone(&view).add_component(current_path_label_clone);
Expand Down
8 changes: 3 additions & 5 deletions rust_programs/ide/src/output_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ impl OutputView {
);

println!("Create title label");
let title_label = Rc::new(Label::new(
Rect::new(8, 8, 200, 16),
"Title",
Color::black(),
));
let title_label = Rc::new(Label::new("Title", Color::black(), |_, _| {
Rect::new(8, 8, 200, 16)
}));
println!("Add title label");
//Rc::clone(&view.view).add_component(Rc::clone(&title_label) as Rc<dyn UIElement>);
println!("Done adding title label");
Expand Down
4 changes: 3 additions & 1 deletion rust_programs/ide/src/status_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ impl StatusView {
}));
Rc::clone(&view).add_component(Rc::clone(&run_button) as Rc<dyn UIElement>);

let status_label = Rc::new(Label::new(Rect::new(10, 10, 400, 16), "", Color::black()));
let status_label = Rc::new(Label::new("", Color::black(), |_, _| {
Rect::new(10, 10, 400, 16)
}));
Rc::clone(&view).add_component(Rc::clone(&status_label) as Rc<dyn UIElement>);

let ret = Rc::new(Self {
Expand Down

0 comments on commit 0d9677f

Please sign in to comment.