Skip to content

Commit

Permalink
Fix spacing between groups & Make header scrollable
Browse files Browse the repository at this point in the history
  • Loading branch information
KonaeAkira committed Dec 22, 2024
1 parent 99f0bda commit 27f0665
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 82 deletions.
129 changes: 66 additions & 63 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl MacroSolverApp {
style.visuals.interact_cursor = Some(CursorIcon::PointingHand);
style.url_in_tooltip = true;
style.always_scroll_the_only_direction = true;
style.spacing.item_spacing = egui::vec2(8.0, 8.0);
});

Self::load_fonts(&cc.egui_ctx);
Expand Down Expand Up @@ -172,77 +173,81 @@ impl eframe::App for MacroSolverApp {
}

egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
egui::menu::bar(ui, |ui| {
ui.label(egui::RichText::new("Raphael | FFXIV Crafting Solver").strong());
ui.label(format!("v{}", env!("CARGO_PKG_VERSION")));

egui::ComboBox::from_id_salt("LOCALE")
.selected_text(format!("{}", self.locale))
.show_ui(ui, |ui| {
ui.selectable_value(
&mut self.locale,
Locale::EN,
format!("{}", Locale::EN),
egui::ScrollArea::horizontal()
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden)
.show(ui, |ui| {
egui::menu::bar(ui, |ui| {
ui.label(egui::RichText::new("Raphael | FFXIV Crafting Solver").strong());
ui.label(format!("v{}", env!("CARGO_PKG_VERSION")));

egui::ComboBox::from_id_salt("LOCALE")
.selected_text(format!("{}", self.locale))
.show_ui(ui, |ui| {
ui.selectable_value(
&mut self.locale,
Locale::EN,
format!("{}", Locale::EN),
);
ui.selectable_value(
&mut self.locale,
Locale::DE,
format!("{}", Locale::DE),
);
ui.selectable_value(
&mut self.locale,
Locale::FR,
format!("{}", Locale::FR),
);
ui.selectable_value(
&mut self.locale,
Locale::JP,
format!("{}", Locale::JP),
);
});

let mut visuals = ctx.style().visuals.clone();
ui.selectable_value(&mut visuals, Visuals::light(), t!("header.light"));
ui.selectable_value(&mut visuals, Visuals::dark(), t!("header.dark"));
ctx.data_mut(|data| {
*data.get_persisted_mut_or_default(Id::new("DARK_MODE")) =
visuals.dark_mode;
});
ctx.set_visuals(visuals);

ui.add(
egui::Hyperlink::from_label_and_url(
t!("header.github"),
"https://github.com/KonaeAkira/raphael-rs",
)
.open_in_new_tab(true),
);
ui.selectable_value(
&mut self.locale,
Locale::DE,
format!("{}", Locale::DE),
ui.label("/");
ui.add(
egui::Hyperlink::from_label_and_url(
t!("header.discord"),
"https://discord.com/invite/m2aCy3y8he",
)
.open_in_new_tab(true),
);
ui.selectable_value(
&mut self.locale,
Locale::FR,
format!("{}", Locale::FR),
ui.label("/");
ui.add(
egui::Hyperlink::from_label_and_url(
t!("header.ko_fi"),
"https://ko-fi.com/konaeakira",
)
.open_in_new_tab(true),
);
ui.selectable_value(
&mut self.locale,
Locale::JP,
format!("{}", Locale::JP),
ui.with_layout(
Layout::right_to_left(Align::Center),
egui::warn_if_debug_build,
);
});

let mut visuals = ctx.style().visuals.clone();
ui.selectable_value(&mut visuals, Visuals::light(), t!("header.light"));
ui.selectable_value(&mut visuals, Visuals::dark(), t!("header.dark"));
ctx.data_mut(|data| {
*data.get_persisted_mut_or_default(Id::new("DARK_MODE")) = visuals.dark_mode;
});
ctx.set_visuals(visuals);

ui.add(
egui::Hyperlink::from_label_and_url(
t!("header.github"),
"https://github.com/KonaeAkira/raphael-rs",
)
.open_in_new_tab(true),
);
ui.label("/");
ui.add(
egui::Hyperlink::from_label_and_url(
t!("header.discord"),
"https://discord.com/invite/m2aCy3y8he",
)
.open_in_new_tab(true),
);
ui.label("/");
ui.add(
egui::Hyperlink::from_label_and_url(
t!("header.ko_fi"),
"https://ko-fi.com/konaeakira",
)
.open_in_new_tab(true),
);
ui.with_layout(
Layout::right_to_left(Align::Center),
egui::warn_if_debug_build,
);
});
});

egui::CentralPanel::default().show(ctx, |ui| {
egui::ScrollArea::both().show(ui, |ui| {
self.draw_simulator_widget(ui);
ui.add_space(5.5);
ui.with_layout(
Layout::left_to_right(Align::TOP).with_main_wrap(true),
|ui| {
Expand Down Expand Up @@ -396,7 +401,6 @@ impl MacroSolverApp {
),
);
});
ui.add_space(5.5);
ui.push_id("FOOD_SELECT", |ui| {
ui.set_max_height(172.0);
ui.add_enabled(
Expand All @@ -409,7 +413,6 @@ impl MacroSolverApp {
),
);
});
ui.add_space(5.5);
ui.push_id("POTION_SELECT", |ui| {
ui.set_max_height(172.0);
ui.add_enabled(
Expand All @@ -427,12 +430,12 @@ impl MacroSolverApp {

fn draw_config_and_results_widget(&mut self, ui: &mut egui::Ui) {
ui.group(|ui| {
ui.style_mut().spacing.item_spacing = egui::vec2(8.0, 3.0);
ui.set_height(560.0);
ui.vertical(|ui| {
ui.add_enabled_ui(!self.solver_pending, |ui| {
self.draw_configuration_widget(ui);
});
ui.add_space(5.5);
self.draw_results_widget(ui);
});
});
Expand Down
14 changes: 8 additions & 6 deletions src/widgets/food_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl<'a> FoodSelect<'a> {
impl<'a> Widget for FoodSelect<'a> {
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
ui.group(|ui| {
ui.style_mut().spacing.item_spacing = egui::vec2(8.0, 3.0);
ui.vertical(|ui| {
ui.horizontal(|ui| {
ui.label(egui::RichText::new(t!("label.food")).strong());
Expand Down Expand Up @@ -75,12 +76,13 @@ impl<'a> Widget for FoodSelect<'a> {
}
});

ui.horizontal(|ui| {
ui.label(format!("{}:", t!("label.search")));
if ui.text_edit_singleline(&mut search_text).changed() {
search_text = search_text.replace("\0", "");
}
});
if egui::TextEdit::singleline(&mut search_text)
.desired_width(f32::INFINITY)
.ui(ui)
.changed()
{
search_text = search_text.replace("\0", "");
};
ui.separator();

let mut search_result = Vec::new();
Expand Down
1 change: 1 addition & 0 deletions src/widgets/macro_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl<'a> MacroView<'a> {
impl<'a> Widget for MacroView<'a> {
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
ui.group(|ui| {
ui.style_mut().spacing.item_spacing = egui::vec2(8.0, 3.0);
ui.vertical(|ui| {
ui.horizontal(|ui| {
ui.label(egui::RichText::new(t!("label.macro")).strong());
Expand Down
14 changes: 8 additions & 6 deletions src/widgets/potion_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl<'a> PotionSelect<'a> {
impl<'a> Widget for PotionSelect<'a> {
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
ui.group(|ui| {
ui.style_mut().spacing.item_spacing = egui::vec2(8.0, 3.0);
ui.vertical(|ui| {
ui.horizontal(|ui| {
ui.label(egui::RichText::new(t!("label.potion")).strong());
Expand Down Expand Up @@ -75,12 +76,13 @@ impl<'a> Widget for PotionSelect<'a> {
}
});

ui.horizontal(|ui| {
ui.label(format!("{}:", t!("label.search")));
if ui.text_edit_singleline(&mut search_text).changed() {
search_text = search_text.replace("\0", "");
}
});
if egui::TextEdit::singleline(&mut search_text)
.desired_width(f32::INFINITY)
.ui(ui)
.changed()
{
search_text = search_text.replace("\0", "");
};
ui.separator();

let mut search_result = Vec::new();
Expand Down
14 changes: 8 additions & 6 deletions src/widgets/recipe_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ impl<'a> RecipeSelect<'a> {
}
});

ui.horizontal(|ui| {
ui.label(format!("{}:", t!("label.search")));
if ui.text_edit_singleline(&mut search_text).changed() {
search_text = search_text.replace("\0", "");
}
});
if egui::TextEdit::singleline(&mut search_text)
.desired_width(f32::INFINITY)
.ui(ui)
.changed()
{
search_text = search_text.replace("\0", "");
};
ui.separator();

let mut search_result = Vec::new();
Expand Down Expand Up @@ -199,6 +200,7 @@ impl<'a> RecipeSelect<'a> {
impl<'a> Widget for RecipeSelect<'a> {
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
ui.group(|ui| {
ui.style_mut().spacing.item_spacing = egui::vec2(8.0, 3.0);
ui.vertical(|ui| {
let mut custom_recipe = false;
ui.ctx().data_mut(|data| {
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl<'a> Widget for Simulator<'a> {

ui.vertical(|ui| {
ui.group(|ui| {
ui.style_mut().spacing.item_spacing = egui::vec2(8.0, 3.0);
ui.vertical(|ui| {
ui.horizontal(|ui| {
ui.label(egui::RichText::new(t!("label.simulation")).strong());
Expand Down Expand Up @@ -189,8 +190,8 @@ impl<'a> Widget for Simulator<'a> {
});
});
});
ui.add_space(5.5);
ui.group(|ui| {
ui.style_mut().spacing.item_spacing = egui::vec2(8.0, 3.0);
egui::ScrollArea::horizontal().show(ui, |ui| {
ui.set_height(30.0);
ui.set_width(ui.available_width());
Expand Down

0 comments on commit 27f0665

Please sign in to comment.