Skip to content

Commit

Permalink
Add opacity modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Sep 4, 2024
1 parent b0d3511 commit 206edb5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
enum ModifierNode: Codable, Hashable {
case padding(insets: Insets)
case position(position: Vec2<Double>)
case opacity(opacity: Double)
case frame(frame: Frame)
case fill(style: Style)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ struct ModifierNodeViewModifier: ViewModifier {
content.padding(EdgeInsets(insets))
case let .position(position: position):
content.position(CGPoint(position))
case let .opacity(opacity: opacity):
content.opacity(opacity)
case let .frame(frame: frame):
switch frame {
case let .constrained(minWidth: minWidth, idealWidth: idealWidth, maxWidth: maxWidth, minHeight: minHeight, idealHeight: idealHeight, maxHeight: maxHeight):
Expand Down
4 changes: 4 additions & 0 deletions nuit-core/src/compose/view/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ pub trait ViewExt: Sized {
self.modifier(ModifierNode::Position { position })
}

fn opacity(self, opacity: f64) -> Modified<Self> {
self.modifier(ModifierNode::Opacity { opacity })
}

fn frame(self, frame: impl Into<Frame>) -> Modified<Self> {
self.modifier(ModifierNode::Frame { frame: frame.into() })
}
Expand Down
1 change: 1 addition & 0 deletions nuit-core/src/node/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{Frame, Insets, Style, Vec2};
pub enum ModifierNode {
Padding { insets: Insets },
Position { position: Vec2<f64> },
Opacity { opacity: f64 },
Frame { frame: Frame },
Fill { style: Style },
}

0 comments on commit 206edb5

Please sign in to comment.