Skip to main content

OverlayOptions

Struct OverlayOptions 

Source
#[non_exhaustive]
pub struct OverlayOptions {
Show 13 fields pub width: Option<Dim>, pub min_width: Option<u16>, pub max_height: Option<Dim>, pub anchor: OverlayAnchor, pub offset_x: i16, pub offset_y: i16, pub row: Option<Dim>, pub col: Option<Dim>, pub margin: OverlayMargin, pub z: i16, pub min_viewport: Size, pub modal: bool, pub fill_height: bool,
}
Expand description

Declarative sizing, placement, and visibility options for an overlay.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§width: Option<Dim>

Requested width, resolved against the full viewport width.

§min_width: Option<u16>

Minimum width applied before fitting the overlay to its margins.

§max_height: Option<Dim>

Maximum height, resolved against the full viewport height.

§anchor: OverlayAnchor

Viewport position used when no explicit row or column is supplied.

§offset_x: i16

Horizontal displacement from the resolved position.

§offset_y: i16

Vertical displacement from the resolved position.

§row: Option<Dim>

Explicit absolute or percentage row position.

§col: Option<Dim>

Explicit absolute or percentage column position.

§margin: OverlayMargin

Insets from viewport edges.

§z: i16

Stacking height: higher layers composite above lower ones; ties stack by creation order.

§min_viewport: Size

Smallest viewport in which the overlay is visible.

§modal: bool

Whether the layer captures the keyboard while visible (the default).

A non-modal layer — a sidebar, a status rail — leaves keys and paste with the base tree unless explicitly focused through crate::Ui::focus_overlay, and never triggers the crate::App alternate-screen hold: the document keeps committing to native scrollback beneath it while the layer rides the live viewport.

§fill_height: bool

Stretches a retained overlay tree to the full available viewport height (after margin and max_height) instead of its content height, so grow/valign fill the band like a full-height rail.

Raw-frame Layer hosts control their frame height directly; the band there always follows the frame.

Implementations§

Source§

impl OverlayOptions

Source

pub const fn width(self, width: Dim) -> Self

Sets the requested width.

Examples found in repository?
examples/chat/sidebar.rs (line 59)
56	pub fn new(model: &str, ctx: &UiContext) -> Self {
57		let options = OverlayOptions::default()
58			.anchor(OverlayAnchor::Right)
59			.width(Dim::Cells(WIDTH))
60			.non_modal()
61			.min_viewport(MIN_VIEWPORT);
62		let mut ui = build(model, ctx);
63		// The rail starts without the keyboard: no focus chrome or frame
64		// cursor until `toggle` or a click hands it over.
65		ui.blur();
66		Self { ui, options, open: true, focused: false, elapsed_seconds: 0, height: 0 }
67	}
More examples
Hide additional examples
examples/chat/picker.rs (line 260)
257	pub fn open(current: usize, ctx: &UiContext) -> Self {
258		let options = OverlayOptions::default()
259			.anchor(OverlayAnchor::Bottom)
260			.width(Dim::Pct(100))
261			.z(10);
262		let mode = Mode::Models;
263		let tier = PerfTier::Full;
264		let ui = build(mode, tier, current, "", 5, 100, ctx);
265		let mut picker = Self {
266			ui,
267			mode,
268			tier,
269			current,
270			ctx: ctx.clone(),
271			options,
272			query: Str::default(),
273			rows: 5,
274		};
275		picker.show_detail(Some(current));
276		picker
277	}
examples/gallery/overlay.rs (line 51)
35pub(crate) fn show_picker(ui: &mut Ui) -> OverlayId {
36	ui.show_overlay(
37		dom! {
38			<box border=round title="Switch Model">
39				<col gap=1>
40					<text dim>{"Session-only switch — role models stay unchanged"}</text>
41					<select id=model>
42						for (value, label, stats) in MODELS {
43							<option value={value} desc={stats}>{label}</option>
44						}
45					</select>
46				</col>
47			</box>
48		},
49		OverlayOptions::default()
50			.anchor(OverlayAnchor::Center)
51			.width(Dim::Pct(70))
52			.min_width(48)
53			.max_height(Dim::Pct(60))
54			.min_viewport(Size::new(40, 8)),
55	)
56}
57
58/// Opens the keybinding help layer.
59pub(crate) fn show_help(ui: &mut Ui) -> OverlayId {
60	ui.show_overlay(
61		dom! {
62			<box border=round title="Help">
63				<col>
64					<text>{"Ctrl+K  switch model"}</text>
65					<text>{"Ctrl+G  toggle this help"}</text>
66					<text>{"Esc     close top layer"}</text>
67					<text>{"Ctrl+C  quit"}</text>
68				</col>
69			</box>
70		},
71		OverlayOptions::default()
72			.anchor(OverlayAnchor::BottomRight)
73			.width(Dim::Cells(30))
74			.margin(OverlayMargin::uniform(1)),
75	)
76}
examples/chat/commands.rs (line 121)
108	pub fn layer(&mut self, viewport: Size) -> Layer<'_> {
109		let width = (viewport.width * 3 / 5).max(48).min(viewport.width);
110		let rows = (viewport.height / 2).saturating_sub(FRAME_ROWS).max(5);
111		if rows != self.rows {
112			self.rows = rows;
113			// One query row plus the windowed list.
114			self
115				.ui
116				.set_prop("commands", Prop::H, rows.saturating_add(1));
117		}
118		if self.ui.frame().size().width != width {
119			self.ui = build(&self.query, self.rows, width, &self.ctx);
120		}
121		self.options = self.options.width(Dim::Cells(width));
122		Layer { frame: self.ui.frame(), options: &self.options, active: true }
123	}
Source

pub const fn min_width(self, min_width: u16) -> Self

Sets the minimum width in cells.

Examples found in repository?
examples/gallery/overlay.rs (line 52)
35pub(crate) fn show_picker(ui: &mut Ui) -> OverlayId {
36	ui.show_overlay(
37		dom! {
38			<box border=round title="Switch Model">
39				<col gap=1>
40					<text dim>{"Session-only switch — role models stay unchanged"}</text>
41					<select id=model>
42						for (value, label, stats) in MODELS {
43							<option value={value} desc={stats}>{label}</option>
44						}
45					</select>
46				</col>
47			</box>
48		},
49		OverlayOptions::default()
50			.anchor(OverlayAnchor::Center)
51			.width(Dim::Pct(70))
52			.min_width(48)
53			.max_height(Dim::Pct(60))
54			.min_viewport(Size::new(40, 8)),
55	)
56}
Source

pub const fn max_height(self, max_height: Dim) -> Self

Sets the maximum height.

Examples found in repository?
examples/gallery/overlay.rs (line 53)
35pub(crate) fn show_picker(ui: &mut Ui) -> OverlayId {
36	ui.show_overlay(
37		dom! {
38			<box border=round title="Switch Model">
39				<col gap=1>
40					<text dim>{"Session-only switch — role models stay unchanged"}</text>
41					<select id=model>
42						for (value, label, stats) in MODELS {
43							<option value={value} desc={stats}>{label}</option>
44						}
45					</select>
46				</col>
47			</box>
48		},
49		OverlayOptions::default()
50			.anchor(OverlayAnchor::Center)
51			.width(Dim::Pct(70))
52			.min_width(48)
53			.max_height(Dim::Pct(60))
54			.min_viewport(Size::new(40, 8)),
55	)
56}
Source

pub const fn z(self, z: i16) -> Self

Sets the stacking height.

Examples found in repository?
examples/chat/commands.rs (line 77)
73	pub fn open(ctx: &UiContext) -> Self {
74		let options = OverlayOptions::default()
75			.anchor(OverlayAnchor::Top)
76			.offset_y(1)
77			.z(10);
78		Self { ui: build("", 8, 100, ctx), ctx: ctx.clone(), options, query: Str::default(), rows: 8 }
79	}
More examples
Hide additional examples
examples/chat/picker.rs (line 261)
257	pub fn open(current: usize, ctx: &UiContext) -> Self {
258		let options = OverlayOptions::default()
259			.anchor(OverlayAnchor::Bottom)
260			.width(Dim::Pct(100))
261			.z(10);
262		let mode = Mode::Models;
263		let tier = PerfTier::Full;
264		let ui = build(mode, tier, current, "", 5, 100, ctx);
265		let mut picker = Self {
266			ui,
267			mode,
268			tier,
269			current,
270			ctx: ctx.clone(),
271			options,
272			query: Str::default(),
273			rows: 5,
274		};
275		picker.show_detail(Some(current));
276		picker
277	}
Source

pub const fn anchor(self, anchor: OverlayAnchor) -> Self

Sets the fallback anchor position.

Examples found in repository?
examples/chat/commands.rs (line 75)
73	pub fn open(ctx: &UiContext) -> Self {
74		let options = OverlayOptions::default()
75			.anchor(OverlayAnchor::Top)
76			.offset_y(1)
77			.z(10);
78		Self { ui: build("", 8, 100, ctx), ctx: ctx.clone(), options, query: Str::default(), rows: 8 }
79	}
More examples
Hide additional examples
examples/chat/sidebar.rs (line 58)
56	pub fn new(model: &str, ctx: &UiContext) -> Self {
57		let options = OverlayOptions::default()
58			.anchor(OverlayAnchor::Right)
59			.width(Dim::Cells(WIDTH))
60			.non_modal()
61			.min_viewport(MIN_VIEWPORT);
62		let mut ui = build(model, ctx);
63		// The rail starts without the keyboard: no focus chrome or frame
64		// cursor until `toggle` or a click hands it over.
65		ui.blur();
66		Self { ui, options, open: true, focused: false, elapsed_seconds: 0, height: 0 }
67	}
examples/chat/picker.rs (line 259)
257	pub fn open(current: usize, ctx: &UiContext) -> Self {
258		let options = OverlayOptions::default()
259			.anchor(OverlayAnchor::Bottom)
260			.width(Dim::Pct(100))
261			.z(10);
262		let mode = Mode::Models;
263		let tier = PerfTier::Full;
264		let ui = build(mode, tier, current, "", 5, 100, ctx);
265		let mut picker = Self {
266			ui,
267			mode,
268			tier,
269			current,
270			ctx: ctx.clone(),
271			options,
272			query: Str::default(),
273			rows: 5,
274		};
275		picker.show_detail(Some(current));
276		picker
277	}
examples/gallery/overlay.rs (line 50)
35pub(crate) fn show_picker(ui: &mut Ui) -> OverlayId {
36	ui.show_overlay(
37		dom! {
38			<box border=round title="Switch Model">
39				<col gap=1>
40					<text dim>{"Session-only switch — role models stay unchanged"}</text>
41					<select id=model>
42						for (value, label, stats) in MODELS {
43							<option value={value} desc={stats}>{label}</option>
44						}
45					</select>
46				</col>
47			</box>
48		},
49		OverlayOptions::default()
50			.anchor(OverlayAnchor::Center)
51			.width(Dim::Pct(70))
52			.min_width(48)
53			.max_height(Dim::Pct(60))
54			.min_viewport(Size::new(40, 8)),
55	)
56}
57
58/// Opens the keybinding help layer.
59pub(crate) fn show_help(ui: &mut Ui) -> OverlayId {
60	ui.show_overlay(
61		dom! {
62			<box border=round title="Help">
63				<col>
64					<text>{"Ctrl+K  switch model"}</text>
65					<text>{"Ctrl+G  toggle this help"}</text>
66					<text>{"Esc     close top layer"}</text>
67					<text>{"Ctrl+C  quit"}</text>
68				</col>
69			</box>
70		},
71		OverlayOptions::default()
72			.anchor(OverlayAnchor::BottomRight)
73			.width(Dim::Cells(30))
74			.margin(OverlayMargin::uniform(1)),
75	)
76}
Source

pub const fn offset_x(self, offset_x: i16) -> Self

Sets the horizontal offset in cells.

Source

pub const fn offset_y(self, offset_y: i16) -> Self

Sets the vertical offset in cells.

Examples found in repository?
examples/chat/commands.rs (line 76)
73	pub fn open(ctx: &UiContext) -> Self {
74		let options = OverlayOptions::default()
75			.anchor(OverlayAnchor::Top)
76			.offset_y(1)
77			.z(10);
78		Self { ui: build("", 8, 100, ctx), ctx: ctx.clone(), options, query: Str::default(), rows: 8 }
79	}
Source

pub const fn row(self, row: Dim) -> Self

Sets an explicit absolute or percentage row.

Source

pub const fn col(self, col: Dim) -> Self

Sets an explicit absolute or percentage column.

Source

pub const fn margin(self, margin: OverlayMargin) -> Self

Sets the viewport-edge insets.

Examples found in repository?
examples/gallery/overlay.rs (line 74)
59pub(crate) fn show_help(ui: &mut Ui) -> OverlayId {
60	ui.show_overlay(
61		dom! {
62			<box border=round title="Help">
63				<col>
64					<text>{"Ctrl+K  switch model"}</text>
65					<text>{"Ctrl+G  toggle this help"}</text>
66					<text>{"Esc     close top layer"}</text>
67					<text>{"Ctrl+C  quit"}</text>
68				</col>
69			</box>
70		},
71		OverlayOptions::default()
72			.anchor(OverlayAnchor::BottomRight)
73			.width(Dim::Cells(30))
74			.margin(OverlayMargin::uniform(1)),
75	)
76}
Source

pub const fn min_viewport(self, min_viewport: Size) -> Self

Sets the minimum viewport required for visibility.

Examples found in repository?
examples/chat/sidebar.rs (line 61)
56	pub fn new(model: &str, ctx: &UiContext) -> Self {
57		let options = OverlayOptions::default()
58			.anchor(OverlayAnchor::Right)
59			.width(Dim::Cells(WIDTH))
60			.non_modal()
61			.min_viewport(MIN_VIEWPORT);
62		let mut ui = build(model, ctx);
63		// The rail starts without the keyboard: no focus chrome or frame
64		// cursor until `toggle` or a click hands it over.
65		ui.blur();
66		Self { ui, options, open: true, focused: false, elapsed_seconds: 0, height: 0 }
67	}
More examples
Hide additional examples
examples/gallery/overlay.rs (line 54)
35pub(crate) fn show_picker(ui: &mut Ui) -> OverlayId {
36	ui.show_overlay(
37		dom! {
38			<box border=round title="Switch Model">
39				<col gap=1>
40					<text dim>{"Session-only switch — role models stay unchanged"}</text>
41					<select id=model>
42						for (value, label, stats) in MODELS {
43							<option value={value} desc={stats}>{label}</option>
44						}
45					</select>
46				</col>
47			</box>
48		},
49		OverlayOptions::default()
50			.anchor(OverlayAnchor::Center)
51			.width(Dim::Pct(70))
52			.min_width(48)
53			.max_height(Dim::Pct(60))
54			.min_viewport(Size::new(40, 8)),
55	)
56}
Source

pub const fn non_modal(self) -> Self

Leaves keys and paste with the base tree while the layer is visible.

crate::Ui::focus_overlay hands the keyboard to the layer on demand; a click inside its band does the same, and a click outside (or an unconsumed Esc) returns it.

Examples found in repository?
examples/chat/sidebar.rs (line 60)
56	pub fn new(model: &str, ctx: &UiContext) -> Self {
57		let options = OverlayOptions::default()
58			.anchor(OverlayAnchor::Right)
59			.width(Dim::Cells(WIDTH))
60			.non_modal()
61			.min_viewport(MIN_VIEWPORT);
62		let mut ui = build(model, ctx);
63		// The rail starts without the keyboard: no focus chrome or frame
64		// cursor until `toggle` or a click hands it over.
65		ui.blur();
66		Self { ui, options, open: true, focused: false, elapsed_seconds: 0, height: 0 }
67	}
Source

pub const fn fill_height(self) -> Self

Stretches a retained overlay tree to the full available viewport height.

Trait Implementations§

Source§

impl Clone for OverlayOptions

Source§

fn clone(&self) -> OverlayOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for OverlayOptions

Source§

impl Debug for OverlayOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OverlayOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for OverlayOptions

Source§

impl PartialEq for OverlayOptions

Source§

fn eq(&self, other: &OverlayOptions) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for OverlayOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.