Skip to main content

DisplayValue

Struct DisplayValue 

Source
pub struct DisplayValue<T: PartialEq> { /* private fields */ }

Implementations§

Source§

impl<T: PartialEq> DisplayValue<T>

Source

pub fn new<S: ToString>(value: T, display: S) -> Self

Examples found in repository?
examples/stackpanel.rs (line 62)
52	fn default() -> Self {
53		let label = WindowFactory::create::<Label>();
54		label
55			.borrow_mut()
56			.set_text("Please enter a valid number (x ∈ ℕ):");
57		let button = WindowFactory::create::<Button>();
58		button.borrow_mut().set_text("Press to increment:");
59		button.borrow_mut().set_border(BorderKind::Solid.into());
60		let mut cb: Combobox<u8> = Combobox::default();
61		for v in [1, 2, 4] {
62			cb.add_item(DisplayValue::new(v, format!("Increment by {}", v)));
63		}
64		let cb = Rc::new(RefCell::new(cb));
65		let combobox = cb.clone();
66		let numeric = WindowFactory::create::<Numeric>();
67		numeric.borrow_mut().set_base(Radix::Hexadecimal);
68		numeric.borrow_mut().set_min_range(8);
69		numeric.borrow_mut().set_max_range(64);
70		numeric.borrow_mut().set_focus_color(Some(Color::Cyan));
71		let nc = numeric.clone();
72		combobox
73			.borrow_mut()
74			.set_selection_changed_callback(move |cb| {
75				let mut brw = nc.borrow_mut();
76				brw.set_stepcount(*cb.get_value().unwrap().value())
77			});
78
79		let stackpanel = WindowFactory::create::<Stackpanel>();
80		stackpanel.borrow_mut().set_border(BorderKind::Solid.into());
81		stackpanel.borrow_mut().add_item(label);
82		stackpanel.borrow_mut().add_item(numeric);
83		stackpanel.borrow_mut().add_item(cb);
84
85		Self {
86			uid: WindowUID::new(),
87			stackpanel,
88			running: true,
89		}
90	}
Source

pub fn from(value: T, display: String) -> Self

Source

pub fn value(&self) -> &T

Examples found in repository?
examples/stackpanel.rs (line 76)
52	fn default() -> Self {
53		let label = WindowFactory::create::<Label>();
54		label
55			.borrow_mut()
56			.set_text("Please enter a valid number (x ∈ ℕ):");
57		let button = WindowFactory::create::<Button>();
58		button.borrow_mut().set_text("Press to increment:");
59		button.borrow_mut().set_border(BorderKind::Solid.into());
60		let mut cb: Combobox<u8> = Combobox::default();
61		for v in [1, 2, 4] {
62			cb.add_item(DisplayValue::new(v, format!("Increment by {}", v)));
63		}
64		let cb = Rc::new(RefCell::new(cb));
65		let combobox = cb.clone();
66		let numeric = WindowFactory::create::<Numeric>();
67		numeric.borrow_mut().set_base(Radix::Hexadecimal);
68		numeric.borrow_mut().set_min_range(8);
69		numeric.borrow_mut().set_max_range(64);
70		numeric.borrow_mut().set_focus_color(Some(Color::Cyan));
71		let nc = numeric.clone();
72		combobox
73			.borrow_mut()
74			.set_selection_changed_callback(move |cb| {
75				let mut brw = nc.borrow_mut();
76				brw.set_stepcount(*cb.get_value().unwrap().value())
77			});
78
79		let stackpanel = WindowFactory::create::<Stackpanel>();
80		stackpanel.borrow_mut().set_border(BorderKind::Solid.into());
81		stackpanel.borrow_mut().add_item(label);
82		stackpanel.borrow_mut().add_item(numeric);
83		stackpanel.borrow_mut().add_item(cb);
84
85		Self {
86			uid: WindowUID::new(),
87			stackpanel,
88			running: true,
89		}
90	}
Source

pub fn display(&self) -> &str

Trait Implementations§

Source§

impl<T> Default for DisplayValue<T>
where T: Default + PartialEq,

Source§

fn default() -> Self

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

impl<T: PartialEq> ItemCollection<DisplayValue<T>> for Combobox<T>

Source§

type Index = usize

Type used to index the underlying collection
Source§

fn add_item(&mut self, item: DisplayValue<T>)

Adds an item to the underlying collection
Source§

fn remove_item(&mut self, item: &DisplayValue<T>)

Removes an item from the underlying collection
Source§

fn remove_at(&mut self, index: Self::Index) -> DisplayValue<T>

Removes an item at the given index from the underlying collection Might panic if index is invalid
Source§

fn get_item(&mut self, index: Self::Index) -> Option<&DisplayValue<T>>

Returns an item from the collection by its index
Source§

fn clear_items(&mut self)

Clears all items in the underlying collection
Source§

fn items(&self) -> Self::Index

Returns the number of items in the underlying collection

Auto Trait Implementations§

§

impl<T> Freeze for DisplayValue<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for DisplayValue<T>
where T: RefUnwindSafe,

§

impl<T> Send for DisplayValue<T>
where T: Send,

§

impl<T> Sync for DisplayValue<T>
where T: Sync,

§

impl<T> Unpin for DisplayValue<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for DisplayValue<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for DisplayValue<T>
where T: UnwindSafe,

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> AsAny for T
where T: Any,

Source§

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

Source§

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

Source§

fn type_name(&self) -> &'static str

Gets the type name of self
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> Downcast for T
where T: AsAny + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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, 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.