Window

Struct Window 

Source
pub struct Window { /* private fields */ }
Available on crate feature winio only.
Expand description

A simple window.

Implementations§

Source§

impl Window

Source

pub fn text(&self) -> String

The title.

Source

pub fn set_text(&mut self, s: impl AsRef<str>)

Set the title.

Examples found in repository?
examples/test/widgets.rs (line 70)
67    fn init(mut init: Self::Init<'_>, sender: &ComponentSender<Self>) -> Self {
68        // let mut window = Child::<Window>::init(init);
69        let mut window = init.window(sender);
70        window.set_text("Widgets example");
71        window.set_size(Size::new(800.0, 600.0));
72        init! {
73            canvas: Canvas = (&window),
74            ulabel: Label = (&window) => {
75                text: "Username:",
76                halign: HAlign::Right,
77            },
78            plabel: Label = (&window) => {
79                text: "Password:",
80                halign: HAlign::Right,
81            },
82            uentry: Edit = (&window) => {
83                text: "AAA",
84            },
85            pentry: Edit = (&window) => {
86                text: "123456",
87                password: true,
88            },
89            pcheck: CheckBox = (&window) => {
90                text: "Show",
91                checked: false,
92            },
93            combo: ComboBox = (&window),
94            list: ObservableVec<String> = (()) => {
95                // https://www.zhihu.com/question/23600507/answer/140640887
96                items: [
97                    "烫烫烫",
98                    "昍昍昍",
99                    "フフフフフフ",
100                    "쳌쳌쳌"
101                ],
102            },
103            r1: RadioButton = (&window) => {
104                text: "屯屯屯",
105                checked: true,
106            },
107            r2: RadioButton = (&window) => {
108                text: "锟斤拷",
109            },
110            r3: RadioButton = (&window) => {
111                text: "╠╠╠"
112            },
113            push_button: Button = (&window) => {
114                text: "Push",
115            },
116            pop_button: Button = (&window) => {
117                text: "Pop",
118            },
119            show_button: Button = (&window) => {
120                text: "Show",
121            },
122            progress: Progress = (&window) => {
123                indeterminate: true,
124            },
125            mltext: TextBox = (&window) => {
126            },
127        }
128        HANDLER.with_app(|a| mltext.set_text(&a.config().s));
129
130        window.show();
131
132        Self {
133            window,
134            ulabel,
135            plabel,
136            uentry,
137            pentry,
138            pcheck,
139            canvas,
140            combo,
141            list,
142            index: None,
143            r1,
144            r2,
145            r3,
146            rindex: 0,
147            push_button,
148            pop_button,
149            show_button,
150            progress,
151            mltext,
152        }
153    }
Source

pub fn client_size(&self) -> Size2D<f64, LogicalSpace>

The inner client size.

Examples found in repository?
examples/options/options.rs (line 136)
133    fn render(&mut self, _sender: &ComponentSender<Self>) {
134        self.window.render();
135
136        let csize = self.window.client_size();
137
138        let m = Margin::new(5., 0., 5., 0.);
139        let m_l = Margin::new(0., 5., 0., 0.);
140
141        let mut form = layout! {
142            Grid::from_str("auto,1*", "auto,auto").unwrap(),
143            self.e_label => { column: 0, row: 0, margin: m_l, valign: VAlign::Center },
144            self.e => { column: 1, row: 0, margin: m },
145            self.s_label => { column: 0, row: 1, margin: m_l, valign: VAlign::Center },
146            self.s => { column: 1, row: 1, margin: m },
147        };
148
149        let mut grid = layout! {
150            Grid::from_str("auto,1*", "auto,auto,auto,1*").unwrap(),
151            self.enabled => { column: 0, row: 0, margin: m },
152            self.b => { column: 0, row: 1, margin: m },
153            form => { column: 0, row: 2, margin: m },
154        };
155        grid.set_size(csize);
156    }
More examples
Hide additional examples
examples/test/widgets.rs (line 258)
257    fn render(&mut self, _sender: &ComponentSender<Self>) {
258        let csize = self.window.client_size();
259        {
260            let mut cred_panel = layout! {
261                Grid::from_str("auto,1*,auto", "1*,auto,auto,1*").unwrap(),
262                self.ulabel => { column: 0, row: 1, valign: VAlign::Center },
263                self.uentry => { column: 1, row: 1, margin: Margin::new_all_same(4.0) },
264                self.plabel => { column: 0, row: 2, valign: VAlign::Center },
265                self.pentry => { column: 1, row: 2, margin: Margin::new_all_same(4.0) },
266                self.pcheck => { column: 2, row: 2 },
267            };
268
269            let mut rgroup_panel = layout! {
270                Grid::from_str("auto", "1*,auto,auto,auto,1*").unwrap(),
271                self.r1 => { row: 1 },
272                self.r2 => { row: 2 },
273                self.r3 => { row: 3 },
274            };
275
276            let mut buttons_panel = layout! {
277                StackPanel::new(Orient::Vertical),
278                self.push_button => { margin: Margin::new_all_same(4.0) },
279                self.pop_button  => { margin: Margin::new_all_same(4.0) },
280                self.show_button => { margin: Margin::new_all_same(4.0) },
281            };
282
283            let mut root_panel = layout! {
284                Grid::from_str("1*,1*,1*", "1*,auto,1*").unwrap(),
285                cred_panel    => { column: 1, row: 0 },
286                rgroup_panel  => { column: 2, row: 0, halign: HAlign::Center },
287                self.canvas   => { column: 0, row: 1, row_span: 2 },
288                self.combo    => { column: 1, row: 1, halign: HAlign::Center },
289                self.progress => { column: 2, row: 1 },
290                self.mltext   => { column: 1, row: 2, margin: Margin::new_all_same(8.0) },
291                buttons_panel => { column: 2, row: 2 },
292            };
293
294            root_panel.set_size(csize);
295        }
296
297        let size = self.canvas.size();
298        let is_dark = ColorTheme::current() == ColorTheme::Dark;
299        let back_color = if is_dark {
300            Color::new(255, 255, 255, 255)
301        } else {
302            Color::new(0, 0, 0, 255)
303        };
304        let brush = SolidColorBrush::new(back_color);
305        let pen = BrushPen::new(&brush, 1.0);
306        let mut ctx = self.canvas.context();
307        let cx = size.width / 2.0;
308        let cy = size.height / 2.0;
309        let r = cx.min(cy) - 2.0;
310        ctx.draw_pie(
311            &pen,
312            Rect::new(Point::new(cx - r, cy - r), Size::new(r * 2.0, r * 2.0)),
313            std::f64::consts::PI,
314            std::f64::consts::PI * 2.0,
315        );
316
317        let brush2 = LinearGradientBrush::new(
318            [
319                GradientStop::new(Color::new(0x87, 0xCE, 0xEB, 0xFF), 0.0),
320                GradientStop::new(back_color, 1.0),
321            ],
322            RelativePoint::zero(),
323            RelativePoint::new(0.0, 1.0),
324        );
325        let pen2 = BrushPen::new(&brush2, 1.0);
326        ctx.draw_round_rect(
327            &pen2,
328            Rect::new(
329                Point::new(cx - r - 1.0, cy - r - 1.0),
330                Size::new(r * 2.0 + 2.0, r * 1.618 + 2.0),
331            ),
332            Size::new(r / 10.0, r / 10.0),
333        );
334        let mut path = ctx.create_path_builder(Point::new(cx + r + 1.0 - r / 10.0, cy));
335        path.add_arc(
336            Point::new(cx, cy + r * 0.618 + 1.0),
337            Size::new(r + 1.0 - r / 10.0, r * 0.382 / 2.0),
338            0.0,
339            std::f64::consts::PI,
340            true,
341        );
342        path.add_line(Point::new(cx - r - 1.0 + r / 10.0, cy));
343        let path = path.build(false);
344        ctx.draw_path(&pen, &path);
345        let brush3 = RadialGradientBrush::new(
346            [
347                GradientStop::new(Color::new(0xF5, 0xF5, 0xF5, 0xFF), 0.0),
348                GradientStop::new(
349                    Color::accent().unwrap_or(Color::new(0xFF, 0xC0, 0xCB, 0xFF)),
350                    1.0,
351                ),
352            ],
353            RelativePoint::new(0.5, 0.5),
354            RelativePoint::new(0.2, 0.5),
355            RelativeSize::new(0.5, 0.5),
356        );
357        let font = DrawingFontBuilder::new()
358            .family("Arial")
359            .size(r / 5.0)
360            .halign(HAlign::Center)
361            .valign(VAlign::Bottom)
362            .build();
363        ctx.draw_str(&brush3, font, Point::new(cx, cy), "Hello world!");
364    }
Source

pub fn set_icon_by_id(&mut self, id: u16)

Set window icon by resource ID.

Source

pub fn style(&self) -> u32

Get window style.

Source

pub fn set_style(&mut self, s: u32)

Set window style.

Source

pub fn ex_style(&self) -> u32

Get window extended style.

Source

pub fn set_ex_style(&mut self, s: u32)

Set window extended style.

Trait Implementations§

Source§

impl AsRawWindow for Window

Source§

fn as_raw_window(&self) -> RawWindow

Get the raw window handle.
Source§

impl AsWindow for Window

Source§

fn as_window(&self) -> BorrowedWindow<'_>

Get the window handle.
Source§

impl Component for Window

Source§

type Event = WindowEvent

The output event type to the parent.
Source§

type Init<'a> = MaybeBorrowedWindow<'a>

Initial parameter type.
Source§

type Message = ()

The input message type to update.
Source§

fn init( init: <Window as Component>::Init<'_>, _sender: &ComponentSender<Window>, ) -> Window

Create the initial component.
Source§

async fn start(&mut self, sender: &ComponentSender<Window>) -> !

Start the event listening.
Source§

async fn update( &mut self, _message: <Window as Component>::Message, _sender: &ComponentSender<Window>, ) -> bool

Respond to the message.
Source§

fn render(&mut self, _sender: &ComponentSender<Window>)

Render the widgets.
Source§

impl Debug for Window

Source§

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

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

impl Layoutable for Window

Source§

fn loc(&self) -> Point2D<f64, LogicalSpace>

The left top location.
Source§

fn set_loc(&mut self, p: Point2D<f64, LogicalSpace>)

Move the location.
Source§

fn size(&self) -> Size2D<f64, LogicalSpace>

The size.
Source§

fn set_size(&mut self, v: Size2D<f64, LogicalSpace>)

Resize.
Source§

fn rect(&self) -> Rect<f64, LogicalSpace>

The bounding rectangle.
Source§

fn set_rect(&mut self, r: Rect<f64, LogicalSpace>)

Set the location and size.
Source§

fn preferred_size(&self) -> Size2D<f64, LogicalSpace>

The preferred size.
Source§

fn min_size(&self) -> Size2D<f64, LogicalSpace>

Min acceptable size.
Source§

impl Visible for Window

Source§

fn is_visible(&self) -> bool

If the widget is visible.
Source§

fn set_visible(&mut self, v: bool)

Set the visibility.
Source§

fn show(&mut self)

Show the widget.
Source§

fn hide(&mut self)

Hide the widget.

Auto Trait Implementations§

§

impl Freeze for Window

§

impl RefUnwindSafe for Window

§

impl !Send for Window

§

impl !Sync for Window

§

impl Unpin for Window

§

impl UnwindSafe for Window

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more