Skip to content

Commit

Permalink
Add offset modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Sep 4, 2024
1 parent 94a8012 commit 0970163
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 offset(delta: Vec2<Double>)
case opacity(opacity: Double)
case frame(frame: Frame)
case fill(style: Style)
Expand Down
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 .offset(delta: delta):
content.offset(x: delta.x, y: delta.y)
case let .opacity(opacity: opacity):
content.opacity(opacity)
case let .frame(frame: frame):
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 offset(self, delta: Vec2<f64>) -> Modified<Self> {
self.modifier(ModifierNode::Offset { delta })
}

fn opacity(self, opacity: impl Into<f64>) -> Modified<Self> {
self.modifier(ModifierNode::Opacity { opacity: opacity.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> },
Offset { delta: Vec2<f64> },
Opacity { opacity: f64 },
Frame { frame: Frame },
Fill { style: Style },
Expand Down

0 comments on commit 0970163

Please sign in to comment.