iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm

Home Page:https://iced.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

lethargy123 opened this issue · comments

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

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();
}

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...

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