-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
text_height
attribute to control the height behavior of text (#…
…976) * feat: `text_height` attribute to control the height behavior of text * update mocked apis * clean up
- Loading branch information
Showing
11 changed files
with
112 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Specify the text height behavior. | ||
|
||
Accepted values: | ||
|
||
- `disable-all` (default) | ||
- `all` | ||
- `disable-first-ascent` | ||
- `disable-least-ascent` | ||
|
||
### Example | ||
|
||
```rust, no_run | ||
# use freya::prelude::*; | ||
fn app() -> Element { | ||
rsx!( | ||
label { | ||
text_height: "disable-all", | ||
"Hello, World!" | ||
} | ||
) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use freya_engine::prelude::*; | ||
|
||
use crate::{ | ||
Parse, | ||
ParseError, | ||
}; | ||
|
||
impl Parse for TextHeightBehavior { | ||
fn parse(value: &str) -> Result<Self, ParseError> { | ||
match value { | ||
"all" => Ok(TextHeightBehavior::All), | ||
"disable-first-ascent" => Ok(TextHeightBehavior::DisableFirstAscent), | ||
"disable-least-ascent" => Ok(TextHeightBehavior::DisableLastDescent), | ||
"disable-all" => Ok(TextHeightBehavior::DisableAll), | ||
_ => Err(ParseError), | ||
} | ||
} | ||
} | ||
|
||
pub trait TextHeight { | ||
fn needs_custom_height(&self) -> bool; | ||
} | ||
|
||
impl TextHeight for TextHeightBehavior { | ||
fn needs_custom_height(&self) -> bool { | ||
matches!( | ||
self, | ||
Self::All | Self::DisableFirstAscent | Self::DisableLastDescent | ||
) | ||
} | ||
} |