Skip to content

Commit

Permalink
デフォルトフォントに戻せるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
mitoma committed Dec 21, 2024
1 parent 84bad13 commit 78fd934
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
4 changes: 4 additions & 0 deletions font_collector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ impl FontRepository {
}
}

pub fn clear_primary_font(&mut self) {
self.primary_font = None;
}

pub fn add_fallback_font_from_system(&mut self, font_name: &str) {
if let Some(font_data) = self.font_collector.load_font(font_name) {
self.fallback_fonts.push(font_data);
Expand Down
31 changes: 18 additions & 13 deletions ui_support/src/action/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,22 @@ impl ActionProcessor for SystemChangeFontUi {
context: &StateContext,
world: &mut dyn World,
) -> InputResult {
let options = context
.font_repository
.list_font_names()
.iter()
.map(|name| {
SelectOption::new(
name.clone(),
Action::new_command_with_argument("system", "change-font", name),
)
})
.collect::<Vec<SelectOption>>();
let mut options = vec![SelectOption::new(
"デフォルトフォント".to_string(),
Action::new_command("system", "change-font"),
)];
options.extend(
context
.font_repository
.list_font_names()
.iter()
.map(|name| {
SelectOption::new(
name.clone(),
Action::new_command_with_argument("system", "change-font", name),
)
}),
);

let model = SelectBox::new_without_action_name(
context,
Expand Down Expand Up @@ -351,9 +356,9 @@ impl ActionProcessor for SystemChangeFont {
_world: &mut dyn World,
) -> InputResult {
if let ActionArgument::String(font_name) = arg {
InputResult::ChangeFont(font_name.clone())
InputResult::ChangeFont(Some(font_name.clone()))
} else {
InputResult::Noop
InputResult::ChangeFont(None)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui_support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ pub enum InputResult {
ChangeBackgroundImage(Option<DynamicImage>),
ChangeGlobalDirection(Direction),
ChangeWindowSize(WindowSize),
ChangeFont(String),
ChangeFont(Option<String>),
SendExit,
Noop,
}
Expand Down
11 changes: 9 additions & 2 deletions ui_support/src/render_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,15 @@ impl RenderState {
self.simple_state_callback.shutdown();
}

pub(crate) fn change_font(&mut self, font_name: String) {
self.context.font_repository.set_primary_font(&font_name);
pub(crate) fn change_font(&mut self, font_name: Option<String>) {
match font_name {
Some(font_name) => {
self.context.font_repository.set_primary_font(&font_name);
}
None => {
self.context.font_repository.clear_primary_font();
}
}
let font_binaries = self.context.font_repository.get_fonts();
let font_binaries = Arc::new(font_binaries);
let char_width_calcurator = Arc::new(CharWidthCalculator::new(font_binaries.clone()));
Expand Down

0 comments on commit 78fd934

Please sign in to comment.