Skip to content

Commit

Permalink
fix: ui_item_stack: image shrink, count text shrink, layout wrap main…
Browse files Browse the repository at this point in the history
…, spacing eq.
  • Loading branch information
Dreamtowards committed Apr 20, 2024
1 parent 34b4592 commit e1c9184
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
15 changes: 8 additions & 7 deletions src/client/ui/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,14 @@ pub fn hud_hotbar(mut ctx: EguiContexts, cli: Res<ClientInfo>, cfg: Res<ClientSe
// bar fg
let rect_fg = rect.with_max_x(rect.min.x + health_bar_size.x * (cli.health as f32 / cli.health_max as f32));
ui.painter().rect_filled(rect_fg, rounding, Color32::WHITE);
ui.painter().text(
rect.left_center(),
Align2::LEFT_CENTER,
format!(" {} / {}", cli.health, cli.health_max),
FontId::proportional(10.),
Color32::GRAY,
);

// ui.painter().text(
// rect.left_center(),
// Align2::LEFT_CENTER,
// format!(" {} / {}", cli.health, cli.health_max),
// FontId::proportional(10.),
// Color32::BLACK,
// );

ui.add_space(health_bar_size.y + 8.);
}
Expand Down
23 changes: 12 additions & 11 deletions src/client/ui/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ pub fn ui_item_stack(ui: &mut egui::Ui, stack: &ItemStack, reg: &crate::item::It

unsafe {
let uv_siz = 1. / crate::item::_NUM_ITEMS as f32;
ui.painter().image(crate::item::_UI_ITEMS_ATLAS, resp.rect,
ui.painter().image(crate::item::_UI_ITEMS_ATLAS, resp.rect.shrink(3.),
Rect::from_min_size(pos2(uv_siz * stack.item_id as f32, 0.), vec2(uv_siz, 1.)), Color32::WHITE);
}
ui.painter().text(resp.rect.max - vec2(6., 6.), Align2::RIGHT_BOTTOM,
ui.painter().text(resp.rect.max - vec2(4., 2.), Align2::RIGHT_BOTTOM,
stack.count.to_string(), egui::FontId::proportional(12.), Color32::from_gray(190));

if resp.clicked() {
crate::util::as_mut(stack).count = 0;
}
}

pub fn ui_main_menu(
Expand All @@ -46,16 +50,13 @@ pub fn ui_main_menu(

egui::Window::new("Inventory").show(ctx.ctx_mut(), |ui| {

// ui.painter().image(crate::item::_UI_ITEMS_ATLAS, ui.min_rect(),
// Rect::from_min_size(pos2(0.5, 0.), vec2(0.5, 1.)), Color32::WHITE);
ui.with_layout(egui::Layout::left_to_right(egui::Align::Min).with_main_wrap(true), |ui| {
ui.style_mut().spacing.item_spacing = vec2(4., 4.);

for i in 0..5 {
ui.horizontal(|ui| {
for j in 0..8 {
ui_item_stack(ui, &ItemStack::new(i*j, i+j), &*items);
}
});
}
for i in 0..30 {
ui_item_stack(ui, &ItemStack::new(i, i), &*items);
}
});
});

// if *rendered_texture_id == egui::TextureId::default() {
Expand Down

0 comments on commit e1c9184

Please sign in to comment.