Skip to main content

Module window

Module window 

Source
Expand description

A general app window with a glass look, and the widgets in it.

A Window has a background Material, a tree of widgets, and a queue of WindowEvents. It follows the light or dark mode, the accent color, the display scale of its monitor, and the settings for transparency and high contrast, also while it shows.

use glasskit::Ui;
use glasskit::events::{Event, EventLoop};
use glasskit::widget::{Button, Column, Insets, Row, Spacer, Text, TextStyle};
use glasskit::window::{Window, WindowEvent};

fn main() -> glasskit::Result<()> {
    let ui = Ui::new()?;
    let mut events: EventLoop<()> = EventLoop::new(&ui)?;
    let mut window = Window::new(&ui, "Hello", 420.0, 220.0)?;
    let title = window.add(Text::new("Hello, glass").style(TextStyle::Title));
    let spacer = window.add(Spacer::fill());
    let ok = window.add(Button::new("OK").accent());
    let buttons = window.add(Row::new().child(spacer).child(ok));
    let root = window.add(
        Column::new()
            .padding(Insets::all(24.0))
            .gap(16.0)
            .child(title)
            .child(buttons),
    );
    window.set_root(root);
    window.show();
    loop {
        if let Event::Window(id) = events.next(None)?
            && id == window.id()
        {
            while let Some(event) = window.next_event() {
                match event {
                    WindowEvent::Clicked(button) if button == ok => return Ok(()),
                    WindowEvent::CloseRequested => return Ok(()),
                    _ => {}
                }
            }
        }
    }
}

Structs§

Key
A key on the keyboard, as its Windows virtual-key code.
KeyEvent
A key press that no widget used. A text box uses the keys that type and edit text.
Window
A top-level window with a glass look and a tree of widgets.

Enums§

Material
The background of a window.
WindowEvent
Something that the user did in a window.