-
Notifications
You must be signed in to change notification settings - Fork 203
Text rotation #424
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
Text rotation #424
Changes from 10 commits
13e424b
2d08b1b
4f3f2f1
ccf644f
272f4c9
44a20ab
19363b3
fda56d8
b194bf7
fcc6f99
cc6e2c7
96d6f11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "rust-analyzer.linkedProjects": [ | ||
| ".\\examples\\rotation\\Cargo.toml" | ||
| ], | ||
| "rust-analyzer.showUnlinkedFileNotification": false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [package] | ||
| name = "rotation" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
| im.workspace = true | ||
| floem = { path = "../.." } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| use floem::{ | ||
| event::{Event, EventListener}, | ||
| keyboard::{Key, NamedKey}, | ||
| peniko::Color, | ||
| reactive::create_signal, | ||
| style::{Background, BorderColor, Outline, OutlineColor, Style, TextColor, Transition}, | ||
| style_class, | ||
| view::View, | ||
| views::{label, stack, text, Decorators}, | ||
| }; | ||
|
|
||
| style_class!(pub Button); | ||
| style_class!(pub Label); | ||
| style_class!(pub Frame); | ||
|
|
||
| fn app_view() -> impl View { | ||
| let blue_button = Style::new() | ||
| .background(Color::rgb8(137, 145, 160)) | ||
| .color(Color::WHITE) | ||
| .border(1.0) | ||
| .border_color(Color::rgb8(109, 121, 135)) | ||
| .hover(|s| s.background(Color::rgb8(170, 175, 187))) | ||
| .transition(TextColor, Transition::linear(0.06)) | ||
| .transition(BorderColor, Transition::linear(0.06)) | ||
| .transition(Background, Transition::linear(0.06)) | ||
| .transition(Outline, Transition::linear(0.1)) | ||
| .focus_visible(|s| { | ||
| s.outline(2.0) | ||
| .outline_color(Color::WHITE.with_alpha_factor(0.7)) | ||
| }) | ||
| .disabled(|s| { | ||
| s.background(Color::DARK_GRAY.with_alpha_factor(0.1)) | ||
| .border_color(Color::BLACK.with_alpha_factor(0.2)) | ||
| }) | ||
| .active(|s| s.background(Color::BLACK.with_alpha_factor(0.4))) | ||
| .padding(5.0) | ||
| .margin(3.0) | ||
| .border_radius(5.0); | ||
| let blue_theme = Style::new() | ||
| .background(Color::rgb8(95, 102, 118)) | ||
| .transition(Background, Transition::linear(0.1)) | ||
| .transition(TextColor, Transition::linear(0.1)) | ||
| .color(Color::WHITE) | ||
| .class(Button, move |_| blue_button) | ||
| .class(Label, |s| { | ||
| s.margin(4.0).transition(TextColor, Transition::linear(0.1)) | ||
| }) | ||
| .font_size(12.0); | ||
|
|
||
| let green_button = Style::new() | ||
| .background(Color::rgb8(180, 188, 175)) | ||
| .disabled(|s| { | ||
| s.background(Color::rgb8(180, 188, 175).with_alpha_factor(0.3)) | ||
| .border_color(Color::rgb8(131, 145, 123).with_alpha_factor(0.3)) | ||
| .color(Color::GRAY) | ||
| }) | ||
| .active(|s| s.background(Color::rgb8(95, 105, 88)).color(Color::WHITE)) | ||
| .color(Color::BLACK.with_alpha_factor(0.7)) | ||
| .border(2.0) | ||
| .transition(TextColor, Transition::linear(0.3)) | ||
| .transition(BorderColor, Transition::linear(0.3)) | ||
| .transition(Background, Transition::linear(0.3)) | ||
| .transition(Outline, Transition::linear(0.2)) | ||
| .transition(OutlineColor, Transition::linear(0.2)) | ||
| .outline_color(Color::rgba8(131, 145, 123, 0)) | ||
| .focus_visible(|s| { | ||
| s.outline(10.0) | ||
| .outline_color(Color::rgb8(131, 145, 123).with_alpha_factor(0.3)) | ||
| }) | ||
| .border_color(Color::rgb8(131, 145, 123)) | ||
| .hover(|s| s.background(Color::rgb8(204, 209, 201))) | ||
| .padding(8.0) | ||
| .border_radius(8.0) | ||
| .margin(6.0); | ||
| let green_theme = Style::new() | ||
| .background(Color::rgb8(227, 231, 226)) | ||
| .transition(Background, Transition::linear(0.5)) | ||
| .class(Button, move |_| green_button) | ||
| .class(Label, |s| { | ||
| s.margin(4.0).transition(TextColor, Transition::linear(0.5)) | ||
| }) | ||
| .class(Frame, |s| { | ||
| s.border(2.0) | ||
| .border_color(Color::rgb8(131, 145, 123).with_alpha_factor(0.2)) | ||
| .border_radius(8.0) | ||
| .background(Color::WHITE.with_alpha_factor(0.1)) | ||
| .padding(12.0) | ||
| }) | ||
| .color(Color::BLACK.with_alpha_factor(0.5)) | ||
| .font_size(16.0); | ||
|
|
||
| let (counter, set_counter) = create_signal(0); | ||
| let (theme, set_theme) = create_signal(false); | ||
| let view = stack((stack(( | ||
| text("Toggle Theme") | ||
| .class(Button) | ||
| .on_click_stop({ | ||
| move |_| { | ||
| set_theme.update(|theme| *theme = !*theme); | ||
| } | ||
| }) | ||
| .style(|s| s.rotation_90()) | ||
| .keyboard_navigatable(), | ||
| stack(( | ||
| label(move || format!("Value: {}", counter.get())).class(Label), | ||
| text("Increment") | ||
| .class(Button) | ||
| .on_click_stop({ | ||
| move |_| { | ||
| set_counter.update(|value| *value += 1); | ||
| } | ||
| }) | ||
| .style(|s| s.rotation_90()) | ||
| .keyboard_navigatable(), | ||
| text("Decrement") | ||
| .class(Button) | ||
| .on_click_stop({ | ||
| move |_| { | ||
| set_counter.update(|value| *value -= 1); | ||
| } | ||
| }) | ||
| .style(|s| s.rotation_180()) | ||
| .keyboard_navigatable(), | ||
| text("Reset to 0") | ||
| .class(Button) | ||
| .on_click_stop(move |_| { | ||
| println!("Reset counter pressed"); // will not fire if button is disabled | ||
| set_counter.update(|value| *value = 0); | ||
| }) | ||
| .disabled(move || counter.get() == 0) | ||
| .style(|s| s.rotation_270()) | ||
| .keyboard_navigatable(), | ||
| )) | ||
| .class(Frame) | ||
| .style(|s| s.items_center()), | ||
| )) | ||
| .style(|s| s.items_center()),)) | ||
| .style(move |_| { | ||
| if theme.get() { | ||
| blue_theme.clone() | ||
| } else { | ||
| green_theme.clone() | ||
| } | ||
| .width_full() | ||
| .height_full() | ||
| .flex_col() | ||
| .items_center() | ||
| .justify_center() | ||
| }) | ||
| .window_title(|| "Themes Example".to_string()); | ||
| let id = view.id(); | ||
| view.on_event_stop(EventListener::KeyUp, move |e| { | ||
| if let Event::KeyUp(e) = e { | ||
| if e.key.logical_key == Key::Named(NamedKey::F11) { | ||
| id.inspect(); | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| fn main() { | ||
| floem::launch(app_view); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -72,6 +72,7 @@ impl StylePropValue for cosmic_text::Style {} | |||||||||||||||||||||||||||||
| impl StylePropValue for TextOverflow {} | ||||||||||||||||||||||||||||||
| impl StylePropValue for LineHeightValue {} | ||||||||||||||||||||||||||||||
| impl StylePropValue for Size<LengthPercentage> {} | ||||||||||||||||||||||||||||||
| impl StylePropValue for Rotation {} | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| impl<T: StylePropValue> StylePropValue for Option<T> { | ||||||||||||||||||||||||||||||
| fn debug_view(&self) -> Option<AnyView> { | ||||||||||||||||||||||||||||||
|
|
@@ -1020,6 +1021,14 @@ pub enum TextOverflow { | |||||||||||||||||||||||||||||
| Ellipsis, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||||||||||||||||||||||||||||||
| pub enum Rotation { | ||||||||||||||||||||||||||||||
| Rotation0, | ||||||||||||||||||||||||||||||
| Rotation90, | ||||||||||||||||||||||||||||||
| Rotation180, | ||||||||||||||||||||||||||||||
| Rotation270, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Comment on lines
+1024
to
+1031
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should have better naming like:
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. although I don't feel like
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preferably it should somehow comply with how CSS defines this attributes
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, thanks for your advice. I will revise it right away |
||||||||||||||||||||||||||||||
| #[derive(Debug, Clone, Copy, PartialEq)] | ||||||||||||||||||||||||||||||
| pub enum CursorStyle { | ||||||||||||||||||||||||||||||
| Default, | ||||||||||||||||||||||||||||||
|
|
@@ -1117,6 +1126,16 @@ impl<T> From<T> for StyleValue<T> { | |||||||||||||||||||||||||||||
| Self::Val(x) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| impl Rotation { | ||||||||||||||||||||||||||||||
| pub fn angle(self) -> f64 { | ||||||||||||||||||||||||||||||
| match self { | ||||||||||||||||||||||||||||||
| Rotation::Rotation0 => 0.0, | ||||||||||||||||||||||||||||||
| Rotation::Rotation90 => 90.0, | ||||||||||||||||||||||||||||||
| Rotation::Rotation180 => 180.0, | ||||||||||||||||||||||||||||||
| Rotation::Rotation270 => 270.0, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| macro_rules! define_builtin_props { | ||||||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||||||
|
|
@@ -1213,6 +1232,7 @@ define_builtin_props!( | |||||||||||||||||||||||||||||
| LineHeight line_height nocb: Option<LineHeightValue> { inherited } = None, | ||||||||||||||||||||||||||||||
| AspectRatio aspect_ratio: Option<f32> {} = None, | ||||||||||||||||||||||||||||||
| Gap gap nocb: Size<LengthPercentage> {} = Size::zero(), | ||||||||||||||||||||||||||||||
| RotationProp rotation: Rotation {} = Rotation::Rotation0, | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| prop_extractor! { | ||||||||||||||||||||||||||||||
|
|
@@ -1716,6 +1736,19 @@ impl Style { | |||||||||||||||||||||||||||||
| self.set(ZIndex, Some(z_index)) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| pub fn rotation_0(self) -> Self { | ||||||||||||||||||||||||||||||
| self.rotation(Rotation::Rotation0) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| pub fn rotation_90(self) -> Self { | ||||||||||||||||||||||||||||||
| self.rotation(Rotation::Rotation90) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| pub fn rotation_180(self) -> Self { | ||||||||||||||||||||||||||||||
| self.rotation(Rotation::Rotation180) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| pub fn rotation_270(self) -> Self { | ||||||||||||||||||||||||||||||
| self.rotation(Rotation::Rotation270) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||||||||||||||||||||||||||||||
| /// Allow the application of a function if the option exists. | ||||||||||||||||||||||||||||||
| /// This is useful for chaining together a bunch of optional style changes. | ||||||||||||||||||||||||||||||
| /// ```rust | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete that file