Skip to content

Commit

Permalink
desktop: Add tooltips for scale modes
Browse files Browse the repository at this point in the history
  • Loading branch information
kjarosh authored and Dinnerbone committed Jul 30, 2024
1 parent 43601aa commit c60ee94
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
18 changes: 18 additions & 0 deletions desktop/assets/texts/en-US/settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,28 @@ align-force = Force
scale-mode = Scale Mode
scale-mode-noscale = Unscaled (100%)
scale-mode-noscale-tooltip =
Displays the movie at its original size, without any zoom.
Corresponds to StageScaleMode.NO_SCALE
scale-mode-showall = Zoom to Fit
scale-mode-showall-tooltip =
Zooms the movie to fill the window as much as possible without cropping, maintaining aspect ratio.
Corresponds to StageScaleMode.SHOW_ALL
scale-mode-exactfit = Stretch to Fit
scale-mode-exactfit-tooltip =
Ensures the movie fills the entire window, disregarding aspect ratio.
Corresponds to StageScaleMode.EXACT_FIT
scale-mode-noborder = Crop to Fit
scale-mode-noborder-tooltip =
Fills the entire window while maintaining aspect ratio, cropping the movie if necessary.
Corresponds to StageScaleMode.NO_BORDER
scale-mode-force = Force
scale-mode-force-tooltip =
Prevents the movie from changing the scale mode, locking it to the selected setting.
player-version = Player Version
Expand Down
51 changes: 40 additions & 11 deletions desktop/src/gui/dialogs/open_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,28 @@ impl OpenDialog {
EnumDropdownField::new(
StageScaleMode::default(),
vec![
StageScaleMode::ExactFit,
StageScaleMode::NoBorder,
StageScaleMode::NoScale,
StageScaleMode::ShowAll,
StageScaleMode::ExactFit,
StageScaleMode::NoBorder,
],
Box::new(|value, locale| match value {
StageScaleMode::ExactFit => text(locale, "scale-mode-exactfit"),
StageScaleMode::NoBorder => text(locale, "scale-mode-noborder"),
StageScaleMode::NoScale => text(locale, "scale-mode-noscale"),
StageScaleMode::ShowAll => text(locale, "scale-mode-showall"),
StageScaleMode::ExactFit => text(locale, "scale-mode-exactfit"),
StageScaleMode::NoBorder => text(locale, "scale-mode-noborder"),
}),
),
)
.with_tooltips(Box::new(|value, locale| match value {
StageScaleMode::NoScale => Some(text(locale, "scale-mode-noscale-tooltip")),
StageScaleMode::ShowAll => Some(text(locale, "scale-mode-showall-tooltip")),
StageScaleMode::ExactFit => Some(text(locale, "scale-mode-exactfit-tooltip")),
StageScaleMode::NoBorder => Some(text(locale, "scale-mode-noborder-tooltip")),
})),
Box::new(|locale| text(locale, "scale-mode-force")),
false,
),
)
.with_checkbox_tooltip(Box::new(|locale| text(locale, "scale-mode-force-tooltip"))),
);
let load_behavior = OptionalField::new(
defaults.player.load_behavior,
Expand Down Expand Up @@ -720,12 +727,14 @@ impl<T: emath::Numeric> InnerField for NumberField<T> {
}

type ValueToTextFn<T> = dyn Fn(T, &LanguageIdentifier) -> Cow<'static, str>;
type CheckboxLabelFn = dyn Fn(&LanguageIdentifier) -> Cow<'static, str>;
type ValueToOptTextFn<T> = dyn Fn(T, &LanguageIdentifier) -> Option<Cow<'static, str>>;
type LabelFn = dyn Fn(&LanguageIdentifier) -> Cow<'static, str>;

struct EnumDropdownField<T: Copy> {
id: egui::Id,
default: T,
value_to_name: Box<ValueToTextFn<T>>,
value_to_tooltip: Box<ValueToOptTextFn<T>>,
possible_values: Vec<T>,
}

Expand All @@ -736,8 +745,14 @@ impl<T: Copy> EnumDropdownField<T> {
default,
value_to_name,
possible_values,
value_to_tooltip: Box::new(|_, _| None),
}
}

pub fn with_tooltips(mut self, value_to_tooltip: Box<ValueToOptTextFn<T>>) -> Self {
self.value_to_tooltip = value_to_tooltip;
self
}
}

impl<T: Copy + PartialEq> InnerField for EnumDropdownField<T> {
Expand All @@ -753,11 +768,15 @@ impl<T: Copy + PartialEq> InnerField for EnumDropdownField<T> {
.selected_text((self.value_to_name)(*value, locale))
.show_ui(ui, |ui| {
for possible_value in &self.possible_values {
ui.selectable_value(
let response = ui.selectable_value(
value,
*possible_value,
(self.value_to_name)(*possible_value, locale),
);

if let Some(tooltip) = (self.value_to_tooltip)(*possible_value, locale) {
response.on_hover_text_at_pointer(tooltip);
}
}
});
}
Expand Down Expand Up @@ -807,18 +826,25 @@ impl InnerField for BooleanDropdownField {

struct FieldWithCheckbox<T: InnerField> {
field: T,
checkbox_label: Box<CheckboxLabelFn>,
checkbox_label: Box<LabelFn>,
checkbox_default: bool,
tooltip_label: Option<Box<LabelFn>>,
}

impl<T: InnerField> FieldWithCheckbox<T> {
pub fn new(field: T, checkbox_label: Box<CheckboxLabelFn>, checkbox_default: bool) -> Self {
pub fn new(field: T, checkbox_label: Box<LabelFn>, checkbox_default: bool) -> Self {
Self {
field,
checkbox_label,
checkbox_default,
tooltip_label: None,
}
}

pub fn with_checkbox_tooltip(mut self, tooltip_label: Box<LabelFn>) -> Self {
self.tooltip_label = Some(tooltip_label);
self
}
}

impl<T: InnerField> InnerField for FieldWithCheckbox<T> {
Expand All @@ -831,7 +857,10 @@ impl<T: InnerField> InnerField for FieldWithCheckbox<T> {

fn ui(&self, ui: &mut Ui, value: &mut Self::Value, error: bool, locale: &LanguageIdentifier) {
self.field.ui(ui, &mut value.0, error, locale);
ui.checkbox(&mut value.1, (self.checkbox_label)(locale));
let response = ui.checkbox(&mut value.1, (self.checkbox_label)(locale));
if let Some(ref tooltip_label) = self.tooltip_label {
response.on_hover_text_at_pointer(tooltip_label(locale));
}
}

fn value_to_result(&self, value: &Self::Value) -> Result<Self::Result, ()> {
Expand Down

0 comments on commit c60ee94

Please sign in to comment.