i18n: make localization context non-global
- Simplify Localization{Context,Manager} to just Localization
- Fixed a bunch of lifetime issueo
- Removed all Arcs and Locks
- Removed globals
* widgets now need access to &mut Localization for i18n
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::{app_style::deck_icon_font_sized, deck_state::DeckState};
|
||||
use egui::{vec2, Button, Color32, Label, RichText, Stroke, Ui, Widget};
|
||||
use notedeck::tr;
|
||||
use notedeck::{tr, Localization};
|
||||
use notedeck::{NamedFontFamily, NotedeckTextStyle};
|
||||
use notedeck_ui::{
|
||||
anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE},
|
||||
@@ -11,6 +11,7 @@ use notedeck_ui::{
|
||||
pub struct ConfigureDeckView<'a> {
|
||||
state: &'a mut DeckState,
|
||||
create_button_text: String,
|
||||
pub i18n: &'a mut Localization,
|
||||
}
|
||||
|
||||
pub struct ConfigureDeckResponse {
|
||||
@@ -19,10 +20,11 @@ pub struct ConfigureDeckResponse {
|
||||
}
|
||||
|
||||
impl<'a> ConfigureDeckView<'a> {
|
||||
pub fn new(state: &'a mut DeckState) -> Self {
|
||||
pub fn new(state: &'a mut DeckState, i18n: &'a mut Localization) -> Self {
|
||||
Self {
|
||||
state,
|
||||
create_button_text: tr!("Create Deck", "Button label to create a new deck"),
|
||||
create_button_text: tr!(i18n, "Create Deck", "Button label to create a new deck"),
|
||||
i18n,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,14 +40,19 @@ impl<'a> ConfigureDeckView<'a> {
|
||||
);
|
||||
padding(16.0, ui, |ui| {
|
||||
ui.add(Label::new(
|
||||
RichText::new(tr!("Deck name", "Label for deck name input field"))
|
||||
.font(title_font.clone()),
|
||||
RichText::new(tr!(
|
||||
self.i18n,
|
||||
"Deck name",
|
||||
"Label for deck name input field"
|
||||
))
|
||||
.font(title_font.clone()),
|
||||
));
|
||||
ui.add_space(8.0);
|
||||
ui.text_edit_singleline(&mut self.state.deck_name);
|
||||
ui.add_space(8.0);
|
||||
ui.add(Label::new(
|
||||
RichText::new(tr!(
|
||||
self.i18n,
|
||||
"We recommend short names",
|
||||
"Hint for deck name input field"
|
||||
))
|
||||
@@ -58,7 +65,8 @@ impl<'a> ConfigureDeckView<'a> {
|
||||
|
||||
ui.add_space(32.0);
|
||||
ui.add(Label::new(
|
||||
RichText::new(tr!("Icon", "Label for deck icon selection")).font(title_font),
|
||||
RichText::new(tr!(self.i18n, "Icon", "Label for deck icon selection"))
|
||||
.font(title_font),
|
||||
));
|
||||
|
||||
if ui
|
||||
@@ -97,7 +105,12 @@ impl<'a> ConfigureDeckView<'a> {
|
||||
self.state.warn_no_title = false;
|
||||
}
|
||||
|
||||
show_warnings(ui, self.state.warn_no_icon, self.state.warn_no_title);
|
||||
show_warnings(
|
||||
ui,
|
||||
self.i18n,
|
||||
self.state.warn_no_icon,
|
||||
self.state.warn_no_title,
|
||||
);
|
||||
|
||||
let mut resp = None;
|
||||
if ui
|
||||
@@ -125,19 +138,22 @@ impl<'a> ConfigureDeckView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn show_warnings(ui: &mut Ui, warn_no_icon: bool, warn_no_title: bool) {
|
||||
fn show_warnings(ui: &mut Ui, i18n: &mut Localization, warn_no_icon: bool, warn_no_title: bool) {
|
||||
let warning = if warn_no_title && warn_no_icon {
|
||||
tr!(
|
||||
i18n,
|
||||
"Please create a name for the deck and select an icon.",
|
||||
"Error message for missing deck name and icon"
|
||||
)
|
||||
} else if warn_no_title {
|
||||
tr!(
|
||||
i18n,
|
||||
"Please create a name for the deck.",
|
||||
"Error message for missing deck name"
|
||||
)
|
||||
} else if warn_no_icon {
|
||||
tr!(
|
||||
i18n,
|
||||
"Please select an icon.",
|
||||
"Error message for missing deck icon"
|
||||
)
|
||||
@@ -320,12 +336,8 @@ mod preview {
|
||||
}
|
||||
|
||||
impl App for ConfigureDeckPreview {
|
||||
fn update(
|
||||
&mut self,
|
||||
_app_ctx: &mut AppContext<'_>,
|
||||
ui: &mut egui::Ui,
|
||||
) -> Option<AppAction> {
|
||||
ConfigureDeckView::new(&mut self.state).ui(ui);
|
||||
fn update(&mut self, ctx: &mut AppContext<'_>, ui: &mut egui::Ui) -> Option<AppAction> {
|
||||
ConfigureDeckView::new(&mut self.state, ctx.i18n).ui(ui);
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user