Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 86d0a2e

Browse files
authored
nuon: Card widget (#279)
1 parent 37ade28 commit 86d0a2e

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

nuon/src/lib.rs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,14 @@ impl Layer {
324324
}
325325

326326
pub fn build(&self, ui: &mut Ui, build: impl FnOnce(&mut Ui)) {
327-
let rect = Rect::new(
328-
ui.translation_stack.translate(self.rect.origin),
329-
self.rect.size,
330-
);
327+
let rect = if self.rect == Rect::zero() {
328+
Rect::zero()
329+
} else {
330+
Rect::new(
331+
ui.translation_stack.translate(self.rect.origin),
332+
self.rect.size,
333+
)
334+
};
331335

332336
ui.layers.push();
333337
ui.layers.current_mut().scissor_rect = rect;
@@ -405,6 +409,38 @@ pub fn scroll() -> Scroll {
405409
Scroll::new()
406410
}
407411

412+
pub struct Card {}
413+
414+
impl Default for Card {
415+
fn default() -> Self {
416+
Self::new()
417+
}
418+
}
419+
420+
impl Card {
421+
pub fn new() -> Self {
422+
Self {}
423+
}
424+
425+
pub fn build(&self, ui: &mut Ui, build: impl FnOnce(&mut Ui)) -> Point {
426+
let last = self::translate().build(ui, |ui| {
427+
self::layer().build(ui, build);
428+
});
429+
430+
self::quad()
431+
.size(last.x, last.y)
432+
.color([42; 3])
433+
.border_radius([5.0; 4])
434+
.build(ui);
435+
436+
last
437+
}
438+
}
439+
440+
pub fn card() -> Card {
441+
Card::new()
442+
}
443+
408444
#[derive(Debug, Clone)]
409445
pub struct Quad {
410446
rect: Rect,

0 commit comments

Comments
 (0)