Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is hoped that it can normally use non-English languages such as Chinese #2542

Open
4 tasks done
lethargy123 opened this issue Aug 7, 2024 · 3 comments
Open
4 tasks done
Labels
bug Something isn't working

Comments

@lethargy123
Copy link

Is your issue REALLY a bug?

  • My issue is indeed a bug!
  • I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

I know that widgets like Button can use .shaping(text::Shaping::Advanced) for shaping text. However, if the entire project is in Chinese, it's inconvenient to use .shaping(text::Shaping::Advanced) in various widgets or wrap it in a function. Additionally, widgets like Checkbox cannot use .shaping(text::Shaping::Advanced). I hope this issue can be fixed (I suggest making .shaping(text::Shaping::Advanced) the default for text).

What is the expected behavior?

It can normally use Chinese and other non-English languages

Version

master

Operating System

Windows

Do you have any log output?

No response

@lethargy123 lethargy123 added the bug Something isn't working label Aug 7, 2024
@alex-ds13
Copy link
Contributor

Checkboxes have a .text_shaping() method exactly for this. And you can make your own helpers to not have to do that every time, like this:

mod widget_helpers {
  /// Creates a new [`Checkbox`].
  ///
  /// [`Checkbox`]: crate::Checkbox
  pub fn checkbox<'a, Message, Theme, Renderer>(
      label: impl Into<String>,
      is_checked: bool,
  ) -> Checkbox<'a, Message, Theme, Renderer>
  where
      Theme: checkbox::Catalog + 'a,
      Renderer: core::text::Renderer,
  {
      Checkbox::new(label, is_checked).text_shaping(text::Shaping::Advanced)
  }

  pub fn button<'a>(text: impl Into<Text<'a>>) -> Button<'a, Message> {
      button(text.into().shaping(text::Shaping::Advanced))
  }

  /// Creates a new [`Text`] widget with the provided content.
  pub fn text<'a, Theme, Renderer>(
      text: impl text::IntoFragment<'a>,
  ) -> Text<'a, Theme, Renderer>
  where
      Theme: text::Catalog + 'a,
      Renderer: core::text::Renderer,
  {
      Text::new(text).shaping(text::Shaping::Advanced)
  }
}

Then instead of importing the normal checkbox, button, text from iced::widget you import them from this widget_helpers (name is just an example) and use them normally like this:

use widget_helpers::*;

pub fn view(&self) -> Element<Message> {
  checkbox("Whatever you want", true).into();
}

@alex-ds13
Copy link
Contributor

Other widgets like the radio, toggler, pick_list also have the same method for text shaping. Text inputs I believe use advanced shaping by default and that's why they don't have it...

@teknalb
Copy link

teknalb commented Aug 20, 2024

That's weird if some widgets use advanced text shaping and others don't!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants