add dialog
This commit is contained in:
@@ -8,6 +8,7 @@ use gpui_native_core::avatar::Avatar;
|
||||
use gpui_native_core::button::{Button, ButtonVariant};
|
||||
use gpui_native_core::checkbox::Checkbox;
|
||||
use gpui_native_core::common::{Sizable as _, h_flex, v_flex};
|
||||
use gpui_native_core::dialog::Dialog;
|
||||
use gpui_native_core::input::{Input, InputState};
|
||||
use gpui_native_core::link::Link;
|
||||
use gpui_native_core::menu::{Menu, MenuItem};
|
||||
@@ -33,6 +34,8 @@ struct Gallery {
|
||||
input_state: Entity<InputState>,
|
||||
popover_open: bool,
|
||||
menu_open: bool,
|
||||
dialog_open: bool,
|
||||
alert_open: bool,
|
||||
scroll: gpui::ScrollHandle,
|
||||
}
|
||||
|
||||
@@ -332,6 +335,42 @@ impl Render for Gallery {
|
||||
})
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_2()
|
||||
.child(section_label(
|
||||
"dialog · alert · native refs — NSAlert, WinUI ContentDialog, Adwaita MessageDialog",
|
||||
colors,
|
||||
))
|
||||
.child(
|
||||
div().flex().gap_2().children([
|
||||
{
|
||||
let gallery = gallery.clone();
|
||||
Button::new("gallery-dialog-open")
|
||||
.label("Delete file…")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click(move |_, _, cx| {
|
||||
gallery.update(cx, |gallery, cx| {
|
||||
gallery.dialog_open = true;
|
||||
cx.notify();
|
||||
});
|
||||
})
|
||||
},
|
||||
{
|
||||
let gallery = gallery.clone();
|
||||
Button::new("gallery-alert-open")
|
||||
.label("Sign out…")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click(move |_, _, cx| {
|
||||
gallery.update(cx, |gallery, cx| {
|
||||
gallery.alert_open = true;
|
||||
cx.notify();
|
||||
});
|
||||
})
|
||||
},
|
||||
]),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_2()
|
||||
@@ -640,11 +679,120 @@ impl Render for Gallery {
|
||||
);
|
||||
|
||||
// The whole gallery scrolls, demonstrating the scroll area at the
|
||||
// page level: the thumb floats over the window's content.
|
||||
ScrollArea::new("gallery-scroll")
|
||||
.handle(self.scroll.clone())
|
||||
// page level: the thumb floats over the window's content. The
|
||||
// dialogs render outside it, as the last children of the window, so
|
||||
// their overlay layer paints over everything.
|
||||
let dialog_gallery = gallery.clone();
|
||||
let dialog = Dialog::new("gallery-dialog")
|
||||
.open(self.dialog_open)
|
||||
.title("Delete file?")
|
||||
.on_change({
|
||||
let gallery = dialog_gallery.clone();
|
||||
move |open, _, cx| {
|
||||
gallery.update(cx, |gallery, cx| {
|
||||
gallery.dialog_open = open;
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
})
|
||||
.content(|_, _| {
|
||||
div()
|
||||
.child("\"report-final.pdf\" will be removed permanently.")
|
||||
.into_any_element()
|
||||
})
|
||||
.actions(move |_, _| {
|
||||
let gallery = dialog_gallery.clone();
|
||||
vec![
|
||||
Button::new("gallery-dialog-cancel")
|
||||
.label("Cancel")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click({
|
||||
let gallery = gallery.clone();
|
||||
move |_, _, cx| {
|
||||
gallery.update(cx, |gallery, cx| {
|
||||
gallery.dialog_open = false;
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
})
|
||||
.into_any_element(),
|
||||
Button::new("gallery-dialog-delete")
|
||||
.label("Delete")
|
||||
.variant(ButtonVariant::Destructive)
|
||||
.on_click({
|
||||
let gallery = gallery.clone();
|
||||
move |_, _, cx| {
|
||||
gallery.update(cx, |gallery, cx| {
|
||||
gallery.dialog_open = false;
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
})
|
||||
.into_any_element(),
|
||||
]
|
||||
});
|
||||
|
||||
let alert_gallery = gallery.clone();
|
||||
let alert = Dialog::new("gallery-alert")
|
||||
.open(self.alert_open)
|
||||
.alert(true)
|
||||
.title("Sign out of the workspace?")
|
||||
.on_change({
|
||||
let gallery = alert_gallery.clone();
|
||||
move |open, _, cx| {
|
||||
gallery.update(cx, |gallery, cx| {
|
||||
gallery.alert_open = open;
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
})
|
||||
.content(|_, _| {
|
||||
div()
|
||||
.child("Any running agents will keep working in the background.")
|
||||
.into_any_element()
|
||||
})
|
||||
.actions(move |_, _| {
|
||||
let gallery = alert_gallery.clone();
|
||||
vec![
|
||||
Button::new("gallery-alert-stay")
|
||||
.label("Stay")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click({
|
||||
let gallery = gallery.clone();
|
||||
move |_, _, cx| {
|
||||
gallery.update(cx, |gallery, cx| {
|
||||
gallery.alert_open = false;
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
})
|
||||
.into_any_element(),
|
||||
Button::new("gallery-alert-signout")
|
||||
.label("Sign out")
|
||||
.variant(ButtonVariant::Primary)
|
||||
.on_click({
|
||||
let gallery = gallery.clone();
|
||||
move |_, _, cx| {
|
||||
gallery.update(cx, |gallery, cx| {
|
||||
gallery.alert_open = false;
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
})
|
||||
.into_any_element(),
|
||||
]
|
||||
});
|
||||
|
||||
div()
|
||||
.size_full()
|
||||
.child(content)
|
||||
.child(
|
||||
ScrollArea::new("gallery-scroll")
|
||||
.handle(self.scroll.clone())
|
||||
.size_full()
|
||||
.child(content),
|
||||
)
|
||||
.child(dialog)
|
||||
.child(alert)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,6 +882,8 @@ fn main() {
|
||||
input_state,
|
||||
popover_open: false,
|
||||
menu_open: false,
|
||||
dialog_open: false,
|
||||
alert_open: false,
|
||||
scroll: gpui::ScrollHandle::new(),
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user