Skip to main content

Theme

Struct Theme 

Source
pub struct Theme {
Show 21 fields pub bg: Color, pub panel: Color, pub raised: Color, pub hover: Color, pub selected: Color, pub line: Color, pub line_strong: Color, pub text: Color, pub text_dim: Color, pub text_faint: Color, pub accent: Color, pub on_accent: Color, pub red: Color, pub amber: Color, pub green: Color, pub blue: Color, pub font: Font, pub small_font: Font, pub radius: f32, pub control_height: f32, pub gap: f32,
}
Expand description

The colours and sizes everything is drawn with: a plain value, to change any part of.

Fields§

§bg: Color

The window behind everything.

§panel: Color

Panels and cards.

§raised: Color

What rises above a panel: a button, a menu.

§hover: Color

What the pointer is over.

§selected: Color

What is selected.

§line: Color

Lines between things.

§line_strong: Color

Stronger lines.

§text: Color

Normal text.

§text_dim: Color

Quieter text.

§text_faint: Color

The quietest text: hints, disabled parts.

§accent: Color

The accent colour.

§on_accent: Color

Text on the accent.

§red: Color

Red: failure, removal.

§amber: Color

Amber: needs attention.

§green: Color

Green: success, addition.

§blue: Color

Blue: information.

§font: Font

Normal text. (Scale text with text_scaled, which keeps the heights holding it in step.)

§small_font: Font

Smaller text beside it.

§radius: f32

Corner radius.

§control_height: f32

The height of a button, a text box and every part holding a line of text: that line in the normal font, plus padding.

§gap: f32

The usual gap between things.

Implementations§

Source§

impl Theme

Source

pub fn dark() -> Self

Light text on a dark ground.

Examples found in repository?
examples/todo.rs (line 40)
39fn describe(app: &mut App, ui: &mut Ui) {
40    ui.theme = if ui.system_dark() { Theme::dark() } else { Theme::light() };
41    app.placement = ui.window_placement().or(app.placement);
42    let mut changed = adding(app, ui);
43    showing(app, ui);
44    changed |= list(app, ui);
45    changed |= renaming(app, ui);
46    if changed && app.save().is_err() {
47        ui.notice("The list could not be saved");
48    }
49}
More examples
Hide additional examples
examples/settings.rs (line 58)
56fn theme(app: &Settings, system_dark: bool) -> Theme {
57    let dark = [system_dark, false, true][app.look];
58    let base = if dark { Theme::dark() } else { Theme::light() };
59    let (control, gap) = if app.close { (24.0, 5.0) } else { (base.control_height, base.gap) };
60    let letters = app.letters.round();
61    Theme { accent: app.accent, font: Font::new(letters), small_font: Font::new(letters - 1.5), control_height: control, gap, ..base }
62}
examples/book.rs (line 606)
605    fn describe(app: &mut App, ui: &mut Ui) {
606        ui.theme = if ui.system_dark() { Theme::dark() } else { Theme::light() };
607        app.placement = ui.window_placement().or(app.placement);
608        let mut changed = adding(app, ui);
609        showing(app, ui);
610        changed |= list(app, ui);
611        changed |= renaming(app, ui);
612        if changed && app.save().is_err() {
613            ui.notice("The list could not be saved");
614        }
615    }
examples/gallery.rs (line 1235)
1230fn theme(app: &App, ui: &Ui) -> Theme {
1231    let theme = match (app.system, app.contrast, app.light) {
1232        (true, ..) => ui.system_theme(),
1233        (false, true, light) => Theme::high_contrast(if light { ContrastColors::LIGHT } else { ContrastColors::DARK }),
1234        (false, false, true) => Theme::light().accented(app.tint),
1235        (false, false, false) => Theme::dark().accented(app.tint),
1236    };
1237    [theme.dense(), theme, theme.roomy()][app.spacing]
1238}
1239
1240/// What the person asked the system for, said in a line.
1241fn system_preferences(ui: &Ui) -> String {
1242    let colour = ui.system_accent().map_or("no colour of its own".into(), |colour| format!("the colour {colour}"));
1243    let (contrast, motion) = (if ui.high_contrast() { "high contrast" } else { "no high contrast" }, if ui.reduced_motion() { "less movement" } else { "movement" });
1244    format!("The system asks for {} windows, {colour}, {contrast}, {motion}, text \u{d7}{}.", if ui.system_dark() { "dark" } else { "light" }, ui.text_scale())
1245}
1246
1247/// The app as it starts.
1248pub fn app() -> App {
1249    App {
1250        name: "Gallery".into(),
1251        presses: 0,
1252        page: 0,
1253        room: 0,
1254        filter: String::new(),
1255        notes: String::new(),
1256        renaming: None,
1257        light: false,
1258        contrast: false,
1259        system: false,
1260        spacing: 1,
1261        ticked: false,
1262        on: true,
1263        folded_open: true,
1264        second: false,
1265        level: 72.0,
1266        bold: false,
1267        starred: true,
1268        span: 1,
1269        busy: false,
1270        from: 20.0,
1271        to: 70.0,
1272        followed: 0,
1273        finding: false,
1274        colour: 6,
1275        wanted: String::new(),
1276        picture: None,
1277        photo: None,
1278        drawings: None,
1279        animation: None,
1280        playing: false,
1281        // `TAUT_FONT=some.ttf` writes the whole window with that font, in place of the system's.
1282        letters: std::env::var_os("TAUT_FONT").and_then(|file| std::fs::read(file).ok()).and_then(FontFile::read),
1283        place: String::new(),
1284        shape: None,
1285        selected_row: 1,
1286        tree_open: [true, true],
1287        amount: 4.0,
1288        off: true,
1289        count: 12,
1290        day: Date::today(),
1291        alarm: Time::new(7, 30, 0),
1292        meeting: (Date::today(), Time::new(14, 0, 0)),
1293        away: (Date::today(), Date::from_days(Date::today().days() + 6)),
1294        marked: 3.0,
1295        zoom: 100.0,
1296        within: 2.5,
1297        fruit: "pear",
1298        faint: true,
1299        hide: false,
1300        tint: Theme::dark().accent,
1301        drag_lists: [vec!["Apples", "Pears", "Plums"], vec!["Bread"]],
1302        table: Table { frozen: 1, ..Default::default() },
1303        selection: Selection::default(),
1304        files: (0..5000u32).map(|n| (format!("file {n:04}"), n * 7919 % 4096 + 1, ["text", "picture", "sound", "folder"][n as usize * 5 % 4])).collect(),
1305        tools: Panel { open: false, ..Panel::new(520.0, 150.0, 300.0, 220.0) },
1306        code: CodeEditor::new(include_str!("gallery.rs"), &Syntax::RUST),
1307        lamp: Lamp { name: "Desk".into(), power: 40.0, on: true, kind: LampKind::Spot, tint: Color::rgb(0xffcf7a), rooms: vec!["Study".into(), "Hall".into()] },
1308        inspector: Inspector::default(),
1309        beside: SecondWindow { open: false, ..SecondWindow::new(380.0, 240.0) },
1310        file_dialog: FileDialog::default(),
1311        dock: Dock::of(&["Files"]).beside(Dock::of(&["Editor", "Preview"]).above(Dock::of(&["Log"]), 0.7), 0.25),
1312        step: 2,
1313        results: 0,
1314        query: String::new(),
1315        topics: vec!["mountains".into(), "walks".into()],
1316        topic: String::new(),
1317        stars: 3.5,
1318        face: None,
1319        liked: [true, false],
1320        loading: true,
1321        banner: true,
1322        styles: [true, false, false],
1323        section: Some(0),
1324        slices: ChartView::default(),
1325        view: ChartView::default(),
1326        dots: [0, 1, 2, 3].map(|row| (0..80u32).map(|n| chance(n + 80 * row)).collect()),
1327        live: false,
1328        load: (0..600).map(|nth| 0.5 + (nth as f32 / 40.0).sin() * 0.2).collect(),
1329        fed: taut::platform::unix_time(),
1330        folders: TreeView::default(),
1331        writing: Markdown::parse(WRITING),
1332    }
1333}
examples/desktop.rs (line 49)
48fn describe(desk: &mut Desk, ui: &mut Ui) {
49    ui.theme = Theme { accent: Color::rgb(TINTS[desk.tint].1), ..if desk.light { Theme::light() } else { Theme::dark() } };
50    let t = ui.theme;
51    // The wall behind everything, in colours that go into each other. A right click on it
52    // opens a menu of the programs.
53    let far = if desk.light { Color::rgb(0xc9d3f2) } else { Color::rgb(0x1c2444) };
54    let wall = ui.el().grow().gradient_along(150.0, &[(0.0, t.bg), (1.0, far)]).sense().show();
55    if ui.context_menu(&wall) {
56        launcher(desk, ui);
57        ui.close();
58    }
59    // A window for each program that is open.
60    for (number, name) in PROGRAMS.iter().enumerate() {
61        if !ui.panel(&mut desk.windows[number], name) {
62            continue;
63        }
64        match number {
65            0 => files(desk, ui),
66            1 => notes(desk, ui),
67            2 => monitor(desk, ui),
68            _ => settings(desk, ui),
69        }
70        ui.close();
71    }
72    tasks(desk, ui);
73    if desk.own_pointer {
74        ui.show_pointer();
75    }
76}
Source

pub fn light() -> Self

Dark text on a light ground.

Examples found in repository?
examples/todo.rs (line 40)
39fn describe(app: &mut App, ui: &mut Ui) {
40    ui.theme = if ui.system_dark() { Theme::dark() } else { Theme::light() };
41    app.placement = ui.window_placement().or(app.placement);
42    let mut changed = adding(app, ui);
43    showing(app, ui);
44    changed |= list(app, ui);
45    changed |= renaming(app, ui);
46    if changed && app.save().is_err() {
47        ui.notice("The list could not be saved");
48    }
49}
More examples
Hide additional examples
examples/settings.rs (line 58)
56fn theme(app: &Settings, system_dark: bool) -> Theme {
57    let dark = [system_dark, false, true][app.look];
58    let base = if dark { Theme::dark() } else { Theme::light() };
59    let (control, gap) = if app.close { (24.0, 5.0) } else { (base.control_height, base.gap) };
60    let letters = app.letters.round();
61    Theme { accent: app.accent, font: Font::new(letters), small_font: Font::new(letters - 1.5), control_height: control, gap, ..base }
62}
examples/book.rs (line 606)
605    fn describe(app: &mut App, ui: &mut Ui) {
606        ui.theme = if ui.system_dark() { Theme::dark() } else { Theme::light() };
607        app.placement = ui.window_placement().or(app.placement);
608        let mut changed = adding(app, ui);
609        showing(app, ui);
610        changed |= list(app, ui);
611        changed |= renaming(app, ui);
612        if changed && app.save().is_err() {
613            ui.notice("The list could not be saved");
614        }
615    }
616
617    /// The box a new task is typed into, and the button that adds it. Says whether one was added.
618    fn adding(app: &mut App, ui: &mut Ui) -> bool {
619        ui.row().pad(12.0).gap(8.0).open();
620        let typed = ui.text_box(&mut app.draft, "Something to do");
621        let add = ui.primary_button("Add").clicked || typed.focused && ui.key(Key::Enter, Mods::NONE);
622        ui.close();
623        // When the keyboard is on nothing (as the app starts), it goes to this box.
624        if ui.focus() == 0 && app.renaming.is_none() {
625            ui.set_focus(typed.id);
626        }
627        if !add || app.draft.trim().is_empty() {
628            return false;
629        }
630        app.tasks.push(Task { id: app.next, text: app.draft.trim().into(), done: false });
631        app.next += 1;
632        app.draft.clear();
633        true
634    }
635
636    /// Which tasks show, and how many are left to do.
637    fn showing(app: &mut App, ui: &mut Ui) {
638        let left = app.tasks.iter().filter(|task| !task.done).count();
639        ui.row().pad((12.0, 0.0)).gap(8.0).open();
640        ui.segmented(&mut app.shown, &SHOWN);
641        ui.spacer();
642        ui.note(&format!("{left} left to do"));
643        ui.close();
644    }
645
646    /// The tasks that show, each with a tick box and buttons to rename it and to take it away.
647    /// Says whether one was ticked or taken away.
648    fn list(app: &mut App, ui: &mut Ui) -> bool {
649        let t = ui.theme;
650        let (mut changed, mut gone, mut none) = (false, None, true);
651        ui.column().grow().scroll().pad(12.0).gap(4.0).open();
652        for task in app.tasks.iter_mut().filter(|task| [true, !task.done, task.done][app.shown]) {
653            none = false;
654            ui.row().key(task.id).pad((10.0, 4.0)).gap(4.0).fill(t.panel).radius(6.0).open();
655            changed |= ui.checkbox(&mut task.done, &task.text).changed;
656            ui.spacer();
657            if ui.icon_button(PEN, "Rename").clicked {
658                app.renaming = Some((task.id, task.text.clone()));
659            }
660            if ui.icon_button(CROSS, "Take away").clicked {
661                gone = Some(task.id);
662            }
663            ui.close();
664        }
665        if none {
666            ui.note(["Nothing to do yet.", "Nothing left to do.", "Nothing done yet."][app.shown]);
667        }
668        ui.close();
669        app.tasks.retain(|task| Some(task.id) != gone);
670        changed || gone.is_some()
671    }
672
673    /// The dialog a task is renamed in, while one is. Says whether a task got a new name.
674    fn renaming(app: &mut App, ui: &mut Ui) -> bool {
675        let Some((id, name)) = &mut app.renaming else { return false };
676        let t = ui.theme;
677        let beside = ui.dialog();
678        ui.text("Rename the task", t.font.bold(), t.text);
679        let field = ui.text_box(name, "What is to be done");
680        // (As the dialog opens, the keyboard goes into its box, with the old name selected.)
681        if ui.focus() == 0 {
682            ui.set_focus(field.id);
683            ui.select_all();
684        }
685        ui.row().gap(8.0).align(Align::End, Align::Center).open();
686        let cancel = ui.button("Cancel").clicked || ui.key(Key::Escape, Mods::NONE) || beside.clicked;
687        let keep = ui.primary_button("Rename").clicked || ui.key(Key::Enter, Mods::NONE);
688        ui.close();
689        ui.close();
690        let renamed = keep && !name.trim().is_empty();
691        if let Some(task) = app.tasks.iter_mut().find(|task| task.id == *id).filter(|_| renamed) {
692            task.text = name.trim().into();
693        }
694        if keep || cancel {
695            app.renaming = None;
696        }
697        renamed
698    }
699
700    impl App {
701        /// The list as it was left in `file`, or an empty one the first time.
702        fn load(file: PathBuf) -> App {
703            let text = std::fs::read_to_string(&file).unwrap_or_default();
704            let mut lines = text.lines();
705            let placement = lines.next().and_then(|line| line.parse().ok());
706            let tasks: Vec<Task> = lines.enumerate().map(|(at, line)| Task { id: at as u64, done: line.starts_with("x "), text: line.get(2..).unwrap_or("").into() }).collect();
707            App { next: tasks.len() as u64, tasks, draft: String::new(), shown: 0, renaming: None, placement, file }
708        }
709
710        /// Writes the list into its file: where the window is on the first line, then a line for
711        /// each task, with `x` before one that is done and `-` before one that is not.
712        fn save(&self) -> std::io::Result<()> {
713            let mut text = self.placement.map_or(String::new(), |placement| placement.to_string());
714            for task in &self.tasks {
715                text += &format!("\n{} {}", if task.done { "x" } else { "-" }, task.text);
716            }
717            std::fs::write(&self.file, text)
718        }
719    }
720
721    /// When the window closes, the app goes with it, and the list is written once more: now with
722    /// where the window was left. (Nobody is left to tell if that fails.)
723    impl Drop for App {
724        fn drop(&mut self) {
725            let _ = self.save();
726        }
727    }
728
729    /// Where the list is kept: in the folder the system keeps the settings of programs in.
730    fn file() -> PathBuf {
731        let folder = std::env::var_os("APPDATA").or_else(|| std::env::var_os("XDG_CONFIG_HOME")).map(PathBuf::from);
732        let home = || std::env::var_os("HOME").map(|home| PathBuf::from(home).join(".config"));
733        folder.or_else(home).unwrap_or_default().join("taut-todo.txt")
734    }
735
736    fn main() {
737        let mut app = App::load(file());
738        let window = Window { title: "To do", width: 400.0, height: 480.0, min_width: 280.0, min_height: 220.0, ..Default::default() };
739        taut::run(window.with_placement(app.placement), move |ui| describe(&mut app, ui));
740    }
741
742    // The picture of it:
743    use super::Step::{Click, Type};
744
745    /// The app with a few tasks in it, kept in a file of the book's own.
746    fn sample() -> App {
747        let tasks = [("Buy bread", true), ("Write to Ada", false), ("Fix the gate", false), ("Book the train", true), ("Plan the garden", false)];
748        let tasks = tasks.iter().enumerate().map(|(id, (text, done))| Task { id: id as u64, text: text.to_string(), done: *done }).collect();
749        App { tasks, draft: String::new(), shown: 0, renaming: None, next: 5, placement: None, file: std::env::temp_dir().join("taut-book-todo.txt") }
750    }
751
752    pub(super) fn shots() -> Vec<super::Shot> {
753        let (mut first, mut second, mut third) = (sample(), sample(), sample());
754        vec![
755            super::Shot::new("04-the-app", [400.0, 480.0], move |ui| describe(&mut first, ui)).steps(&[Type("Water the plants")]),
756            super::Shot::new("04-to-do", [400.0, 480.0], move |ui| describe(&mut second, ui)).steps(&[Click("To do")]),
757            super::Shot::new("04-renaming", [400.0, 480.0], move |ui| (ui.set_preferences(taut::Preferences { dark: true, ..Default::default() }), describe(&mut third, ui)).1)
758                .steps(&[Click("Rename")]),
759        ]
760    }
761}
762
763// docs/05-larger-parts.md
764mod a_table {
765    use std::cmp::Ordering;
766    use taut::{Align, Column, Selection, Table, Ui};
767
768    const COLUMNS: [Column; 3] = [Column::new("Name"), Column::new("Size").px(90.0).align(Align::End), Column::new("Kind").px(80.0)];
769
770    struct File {
771        name: String,
772        size: u64,
773        kind: &'static str,
774    }
775
776    struct App {
777        files: Vec<File>,
778        table: Table,
779        selection: Selection,
780    }
781
782    fn describe(app: &mut App, ui: &mut Ui) {
783        if ui.table(&mut app.table, &COLUMNS).changed {
784            let by = app.table.sort.clone();
785            app.files.sort_by(|a, b| order(a, b, &by));
786            app.selection.clear();
787        }
788        for row in ui.rows(app.files.len(), 24.0) {
789            if ui.selectable_row(row, app.selection.contains(row)).clicked {
790                app.selection.click(row, ui.mods());
791            }
792            let file = &app.files[row];
793            ui.label(&file.name);
794            ui.label(&format!("{} KB", file.size));
795            ui.label(file.kind);
796            ui.close();
797        }
798        ui.close();
799        ui.close();
800    }
801
802    /// How two files compare in the order the headings ask for: by the column that counts
803    /// most, and where that is the same, by the next.
804    fn order(a: &File, b: &File, by: &[(usize, bool)]) -> Ordering {
805        for &(column, large_first) in by {
806            let (a, b) = if large_first { (b, a) } else { (a, b) };
807            let order = match column {
808                0 => a.name.cmp(&b.name),
809                1 => a.size.cmp(&b.size),
810                _ => a.kind.cmp(b.kind),
811            };
812            if order.is_ne() {
813                return order;
814            }
815        }
816        Ordering::Equal
817    }
818
819    // The picture of it:
820    use super::Step::{Click, ClickAt};
821    pub(super) fn shot() -> super::Shot {
822        let kinds = ["text", "picture", "sound", "folder"];
823        let files = (0..500u64).map(|n| File { name: format!("file {n:03}"), size: n * 7919 % 4096 + 1, kind: kinds[n as usize * 5 % 4] }).collect();
824        let mut app = App { files, table: Table::default(), selection: Selection::default() };
825        super::Shot::new("05-a-table", [420.0, 220.0], move |ui| describe(&mut app, ui)).steps(&[Click("Size"), Click("Size"), ClickAt(200.0, 116.0)])
826    }
827}
828
829// docs/05-larger-parts.md
830mod a_long_list {
831    use taut::Ui;
832
833    fn describe(ui: &mut Ui) {
834        for row in ui.list(100_000, 24.0) {
835            ui.row().pad((12.0, 0.0)).open();
836            ui.label(&format!("Row {} of 100000", row + 1));
837            ui.close();
838        }
839        ui.close();
840    }
841
842    // The picture of it:
843    use taut::{Key, Mods};
844    pub(super) fn shot() -> super::Shot {
845        super::Shot::new("05-a-long-list", [300.0, 130.0], describe).steps(&[super::Step::Press(Key::End, Mods::NONE)])
846    }
847}
848
849// docs/05-larger-parts.md
850mod a_tree {
851    use taut::{Length, Ui};
852
853    struct Folders {
854        open: [bool; 3],
855        selected: usize,
856    }
857
858    fn describe(app: &mut Folders, ui: &mut Ui) {
859        ui.column().w(Length::Px(260.0)).pad(12.0).gap(2.0).open();
860        ui.tree(&mut app.open[0], "Pictures");
861        if app.open[0] {
862            ui.tree(&mut app.open[1], "Holidays");
863            if app.open[1] {
864                leaf(app, ui, 0, "Beach.jpg");
865                leaf(app, ui, 1, "Hills.jpg");
866                ui.close();
867            }
868            ui.tree(&mut app.open[2], "Family");
869            if app.open[2] {
870                leaf(app, ui, 2, "Ada.png");
871                ui.close();
872            }
873            leaf(app, ui, 3, "Cat.png");
874            ui.close();
875        }
876        ui.close();
877    }
878
879    fn leaf(app: &mut Folders, ui: &mut Ui, number: usize, name: &str) {
880        if ui.selectable(app.selected == number, name).clicked {
881            app.selected = number;
882        }
883    }
884
885    // The picture of it:
886    pub(super) fn shot() -> super::Shot {
887        let mut app = Folders { open: [true, true, false], selected: 1 };
888        super::Shot::new("05-a-tree", [300.0, 210.0], move |ui| describe(&mut app, ui))
889    }
890}
891
892// docs/05-larger-parts.md
893mod menus {
894    use taut::Ui;
895
896    struct Editor {
897        wrap: bool,
898        status: String,
899    }
900
901    fn describe(app: &mut Editor, ui: &mut Ui) {
902        ui.menu_bar();
903        if ui.menu_button("File") {
904            if ui.menu_item("New\tCtrl+N").clicked {
905                app.status = "A new file".into();
906            }
907            if ui.submenu("Open again") {
908                for name in ["notes.txt", "plan.md"] {
909                    if ui.menu_item(name).clicked {
910                        app.status = format!("Opened {name}");
911                    }
912                }
913                ui.close();
914            }
915            ui.separator();
916            ui.menu_checkbox(&mut app.wrap, "Wrap long lines");
917            ui.separator();
918            if ui.menu_item("Quit\tCtrl+Q").clicked {
919                ui.quit();
920            }
921            ui.close();
922        }
923        if ui.menu_button("Help") {
924            ui.menu_item("About");
925            ui.close();
926        }
927        ui.close();
928        // The keys the menu shows are the app's to ask for.
929        if ui.keys("Ctrl+N") {
930            app.status = "A new file".into();
931        }
932        if ui.keys("Ctrl+Q") {
933            ui.quit();
934        }
935        ui.column().pad(12.0).open();
936        ui.label(&app.status);
937        ui.close();
938    }
939
940    // The picture of it:
941    use super::Step::{Click, Hover};
942    pub(super) fn shot() -> super::Shot {
943        let mut app = Editor { wrap: true, status: "Nothing yet".into() };
944        super::Shot::new("05-menus", [420.0, 220.0], move |ui| describe(&mut app, ui)).steps(&[Click("File"), Hover("Open again")])
945    }
946}
947
948// docs/05-larger-parts.md
949mod a_dock {
950    use taut::{Dock, Ui};
951
952    /// How the panels lie the first time: the files at the left, a quarter of the width; the
953    /// editor and the notes behind tabs, over the log.
954    fn first() -> Dock {
955        Dock::of(&["Files"]).beside(Dock::of(&["Editor", "Notes"]).above(Dock::of(&["Log"]), 0.7), 0.25)
956    }
957
958    fn describe(dock: &mut Dock, ui: &mut Ui) {
959        ui.dock(dock);
960        for name in ["Files", "Editor", "Notes", "Log"] {
961            if ui.docked(dock, name) {
962                ui.paragraph(&format!("What the {name} panel shows"));
963                ui.close();
964            }
965        }
966        ui.close();
967    }
968
969    // The picture of it:
970    pub(super) fn shot() -> super::Shot {
971        let mut dock = first();
972        super::Shot::new("05-a-dock", [560.0, 300.0], move |ui| describe(&mut dock, ui))
973    }
974}
975
976// docs/05-larger-parts.md
977mod a_chart {
978    use taut::{Chart, Series, Ui};
979
980    fn describe(ui: &mut Ui) {
981        let t = ui.theme;
982        let sold = [12.0, 18.0, 9.0, 22.0, 30.0, 26.0, 14.0];
983        let back = [2.0, 3.0, 1.0, 4.0, 6.0, 3.0, 2.0];
984        let rows = [Series::bars("Sold", &sold), Series::line("Brought back", &back).color(t.red)];
985        let days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
986        ui.column().pad(12.0).open();
987        ui.chart(&Chart::of(&rows).categories(&days), 420.0, 200.0);
988        ui.close();
989    }
990
991    // The picture of it:
992    use super::Step::Hover;
993    pub(super) fn shot() -> super::Shot {
994        super::Shot::new("05-a-chart", [444.0, 224.0], describe).steps(&[Hover("Sold, Brought back")])
995    }
996}
997
998// docs/05-larger-parts.md
999mod a_panel {
1000    use taut::{Panel, Ui};
1001
1002    struct App {
1003        tools: Panel,
1004        size: f32,
1005        grid: bool,
1006    }
1007
1008    fn describe(app: &mut App, ui: &mut Ui) {
1009        ui.column().grow().pad(12.0).open();
1010        ui.paragraph("The page, under the panel. The panel is moved by its title, stretched by its edges and corners, folded by its arrow and closed by its cross.");
1011        ui.close();
1012        if ui.panel(&mut app.tools, "Tools") {
1013            ui.label("Brush size");
1014            ui.slider(&mut app.size, 1.0..=10.0);
1015            ui.checkbox(&mut app.grid, "Show the grid");
1016            ui.close();
1017        }
1018    }
1019
1020    // The picture of it:
1021    pub(super) fn shot() -> super::Shot {
1022        let mut app = App { tools: Panel::new(150.0, 70.0, 240.0, 150.0), size: 4.0, grid: true };
1023        super::Shot::new("05-a-panel", [420.0, 240.0], move |ui| describe(&mut app, ui))
1024    }
1025}
1026
1027// docs/05-larger-parts.md
1028mod a_palette {
1029    use taut::Ui;
1030
1031    const COMMANDS: [&str; 6] = ["New file\tCtrl+N", "Open a file\tCtrl+O", "Save\tCtrl+S", "Save as\u{2026}", "Search the files\tCtrl+Shift+F", "Settings"];
1032
1033    struct App {
1034        finding: bool,
1035        status: String,
1036    }
1037
1038    fn describe(app: &mut App, ui: &mut Ui) {
1039        app.finding |= ui.keys("Ctrl+K");
1040        if let Some(command) = ui.command_palette(&mut app.finding, &COMMANDS) {
1041            app.status = format!("Picked: {}", COMMANDS[command].split('\t').next().unwrap_or(""));
1042        }
1043        ui.column().pad(12.0).open();
1044        ui.label(&app.status);
1045        ui.close();
1046    }
1047
1048    // The picture of it:
1049    use super::Step::Type;
1050    pub(super) fn shot() -> super::Shot {
1051        let mut app = App { finding: true, status: "Ctrl+K finds a command".into() };
1052        super::Shot::new("05-a-palette", [460.0, 260.0], move |ui| describe(&mut app, ui)).steps(&[Type("sa")])
1053    }
1054}
1055
1056// docs/05-larger-parts.md
1057mod a_notice {
1058    use taut::Ui;
1059
1060    fn describe(ui: &mut Ui) {
1061        ui.row().pad(12.0).open();
1062        if ui.button("Save").clicked {
1063            ui.notice("Saved");
1064        }
1065        ui.close();
1066    }
1067
1068    // The picture of it:
1069    use super::Step::Click;
1070    pub(super) fn shot() -> super::Shot {
1071        super::Shot::new("05-a-notice", [320.0, 130.0], describe).steps(&[Click("Save")])
1072    }
1073}
1074
1075// docs/06-text-and-pictures.md
1076mod kinds_of_text {
1077    use taut::{Font, Length, Ui};
1078
1079    fn describe(ui: &mut Ui) {
1080        let t = ui.theme;
1081        ui.column().pad(12.0).gap(6.0).open();
1082        ui.label("A label: one line, in the theme's font and colour");
1083        ui.note("A note: smaller and quieter");
1084        ui.text("Bold, in the colour that stands out", t.font.bold(), t.accent);
1085        ui.text("Letters of one width, for code: let x = 1;", t.font.mono(), t.text);
1086        ui.text("Struck through: no longer so", t.font.strikethrough(), t.text_dim);
1087        ui.text("Larger", Font::new(20.0), t.text);
1088        ui.paragraph("A paragraph breaks into as many lines as the width it is given needs, between its words.");
1089        ui.el().w(Length::Px(220.0)).clip().text("Text that is too long for its box ends in dots", t.font, t.text).show();
1090        ui.wrapping_row().open();
1091        ui.words("Words of ", t.font, t.text);
1092        ui.words("several kinds", t.font.bold(), t.text);
1093        ui.words(" in one paragraph, with a ", t.font, t.text);
1094        ui.link("link");
1095        ui.words(" among them.", t.font, t.text);
1096        ui.close();
1097        ui.close();
1098    }
1099
1100    // The picture of it:
1101    pub(super) fn shot() -> super::Shot {
1102        super::Shot::new("06-kinds-of-text", [420.0, 270.0], describe)
1103    }
1104}
1105
1106// docs/06-text-and-pictures.md
1107mod emoji {
1108    use taut::Ui;
1109
1110    fn describe(note: &mut String, ui: &mut Ui) {
1111        ui.column().pad(12.0).gap(8.0).open();
1112        ui.label("In colour, at the size of the letters: 🙂 👍🏽 👩‍🚀 ❤️ 🇳🇴");
1113        ui.button("🎉 Done");
1114        ui.text_box(note, "Typed into a box, too");
1115        ui.close();
1116    }
1117
1118    // The picture of it:
1119    pub(super) fn shot() -> super::Shot {
1120        let mut note = "Pizza 🍕 on Friday".to_string();
1121        super::Shot::new("06-emoji", [420.0, 124.0], move |ui| describe(&mut note, ui))
1122    }
1123}
1124
1125// docs/06-text-and-pictures.md
1126mod pictures {
1127    use taut::{Drawing, Picture, Ui};
1128
1129    /// A sun, as an SVG file says it: its rays take the colour they are shown in.
1130    const SUN: &str = r##"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
1131      <circle cx="12" cy="12" r="5" fill="#f5b400"/>
1132      <path d="M12 1.5v3M12 19.5v3M1.5 12h3M19.5 12h3M4.6 4.6l2.1 2.1M17.3 17.3l2.1 2.1M4.6 19.4l2.1-2.1M17.3 6.7l2.1-2.1"
1133        stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
1134    </svg>"##;
1135
1136    struct App {
1137        pixels: Option<Picture>,
1138        sun: Option<Drawing>,
1139    }
1140
1141    fn describe(app: &mut App, ui: &mut Ui) {
1142        let t = ui.theme;
1143        // Handed over once, kept by the library from then on.
1144        if app.pixels.is_none() {
1145            // Sixteen by sixteen pixels: red grows to the right, green downwards.
1146            let pixels = (0..256u32).map(|i| 0xff00_0080 | (i % 16 * 17) << 16 | (i / 16 * 17) << 8).collect();
1147            app.pixels = Some(ui.add_picture(16, pixels));
1148            app.sun = ui.add_drawing(SUN);
1149        }
1150        ui.row().pad(12.0).gap(16.0).open();
1151        if let Some(pixels) = app.pixels {
1152            ui.picture(pixels);
1153            ui.el().picture(pixels).size(96.0, 96.0).show();
1154        }
1155        if let Some(sun) = app.sun {
1156            ui.el().drawing(sun, t.text).size(24.0, 24.0).show();
1157            ui.el().drawing(sun, t.accent).size(96.0, 96.0).show();
1158        }
1159        ui.close();
1160    }
1161
1162    // The picture of it:
1163    pub(super) fn shot() -> super::Shot {
1164        let mut app = App { pixels: None, sun: None };
1165        super::Shot::new("06-pictures", [300.0, 120.0], move |ui| describe(&mut app, ui))
1166    }
1167}
1168
1169// docs/06-text-and-pictures.md
1170mod drawing {
1171    use taut::{Flow, Icon, Path, Ui};
1172
1173    const STAR: Icon = Icon::line("M8 1.8 9.4 6.6 14.2 8 9.4 9.4 8 14.2 6.6 9.4 1.8 8 6.6 6.6z");
1174
1175    fn describe(ui: &mut Ui) {
1176        let t = ui.theme;
1177        // A wave, as a line and as the area under it.
1178        let (wide, high) = (300.0, 90.0);
1179        let (mut line, mut area) = (Path::new(), Path::new());
1180        area.move_to(0.0, high);
1181        for step in 0..=60 {
1182            let (x, y) = (step as f32 * wide / 60.0, high / 2.0 - (step as f32 / 6.0).sin() * 28.0);
1183            area.line_to(x, y);
1184            match step {
1185                0 => line.move_to(x, y),
1186                _ => line.line_to(x, y),
1187            };
1188        }
1189        area.line_to(wide, high).close();
1190        ui.column().pad(12.0).gap(12.0).open();
1191        ui.el().flow(Flow::Stack).size(wide, high).fill(t.panel).radius(6.0).clip().open();
1192        ui.el().size(wide, high).shape(&area, t.accent.with_alpha(0.25)).show();
1193        ui.el().size(wide, high).outline(&line, 2.0, t.accent).show();
1194        ui.close();
1195        // Fills that go from colour to colour, and icons drawn from SVG path data.
1196        ui.row().gap(12.0).open();
1197        ui.el().size(90.0, 36.0).radius(8.0).gradient_across(t.accent, t.green).show();
1198        ui.el().size(90.0, 36.0).radius(8.0).gradient_along(60.0, &[(0.0, t.red), (0.5, t.amber), (1.0, t.green)]).show();
1199        ui.el().size(36.0, 36.0).radius(18.0).gradient_around(&[(0.0, t.text), (0.6, t.accent), (1.0, t.accent.with_alpha(0.0))]).show();
1200        ui.icon(STAR);
1201        ui.el().icon(STAR, 32.0, t.amber).show();
1202        ui.close();
1203        ui.close();
1204    }
1205
1206    // The picture of it:
1207    pub(super) fn shot() -> super::Shot {
1208        super::Shot::new("06-drawing", [324.0, 172.0], describe)
1209    }
1210}
1211
1212// docs/06-text-and-pictures.md
1213mod a_scene {
1214    use taut::{Camera, Mesh, Ui};
1215
1216    /// A body with four sides and a square floor: five points, and four triangles, each
1217    /// given by the numbers of its three corners.
1218    fn pyramid(ui: &mut Ui) -> Mesh {
1219        let points = vec![[-5.0, 0.0, -5.0], [5.0, 0.0, -5.0], [5.0, 0.0, 5.0], [-5.0, 0.0, 5.0], [0.0, 6.0, 0.0]];
1220        ui.add_mesh(points, vec![[0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4]])
1221    }
1222
1223    fn describe(body: &mut Option<Mesh>, ui: &mut Ui) {
1224        let t = ui.theme;
1225        let pyramid = *body.get_or_insert_with(|| pyramid(ui));
1226        let view = Camera::look_at([13.0, 9.0, 17.0], [0.0, 2.0, 0.0]);
1227        ui.row().pad(12.0).open();
1228        ui.el().size(300.0, 160.0).fill(t.panel).radius(6.0).scene(&view, &[pyramid.filled(t.accent).outlined(t.text)]).show();
1229        ui.close();
1230    }
1231
1232    // The picture of it:
1233    pub(super) fn shot() -> super::Shot {
1234        let mut body = None;
1235        super::Shot::new("06-a-scene", [324.0, 184.0], move |ui| describe(&mut body, ui))
1236    }
1237}
1238
1239// docs/07-everyone-can-use-it.md
1240mod a_form {
1241    use taut::{Align, Ui};
1242
1243    struct Form {
1244        name: String,
1245        letters: bool,
1246    }
1247
1248    fn describe(form: &mut Form, ui: &mut Ui) {
1249        ui.column().pad(12.0).gap(10.0).open();
1250        ui.text_box(&mut form.name, "Your name");
1251        ui.checkbox(&mut form.letters, "Send me letters");
1252        ui.row().gap(8.0).align(Align::End, Align::Center).open();
1253        ui.button("Cancel");
1254        ui.primary_button("Save");
1255        ui.close();
1256        ui.close();
1257    }
1258
1259    // The picture of it:
1260    use super::Step::{Press, Type};
1261    use taut::{Key, Mods, Theme};
1262    pub(super) fn shots() -> Vec<super::Shot> {
1263        let mut first = Form { name: String::new(), letters: false };
1264        let mut second = Form { name: String::new(), letters: true };
1265        let tab = Press(Key::Tab, Mods::NONE);
1266        vec![
1267            super::Shot::new("07-by-the-keyboard", [360.0, 130.0], move |ui| describe(&mut first, ui)).steps(&[tab, Type("Ada"), tab, Press(Key::Space, Mods::NONE), tab]),
1268            super::Shot::new("07-light-and-larger", [360.0, 130.0], move |ui| (ui.theme = Theme::light(), describe(&mut second, ui)).1).scale(1.5),
1269        ]
1270    }
examples/gallery.rs (line 1234)
1230fn theme(app: &App, ui: &Ui) -> Theme {
1231    let theme = match (app.system, app.contrast, app.light) {
1232        (true, ..) => ui.system_theme(),
1233        (false, true, light) => Theme::high_contrast(if light { ContrastColors::LIGHT } else { ContrastColors::DARK }),
1234        (false, false, true) => Theme::light().accented(app.tint),
1235        (false, false, false) => Theme::dark().accented(app.tint),
1236    };
1237    [theme.dense(), theme, theme.roomy()][app.spacing]
1238}
examples/desktop.rs (line 49)
48fn describe(desk: &mut Desk, ui: &mut Ui) {
49    ui.theme = Theme { accent: Color::rgb(TINTS[desk.tint].1), ..if desk.light { Theme::light() } else { Theme::dark() } };
50    let t = ui.theme;
51    // The wall behind everything, in colours that go into each other. A right click on it
52    // opens a menu of the programs.
53    let far = if desk.light { Color::rgb(0xc9d3f2) } else { Color::rgb(0x1c2444) };
54    let wall = ui.el().grow().gradient_along(150.0, &[(0.0, t.bg), (1.0, far)]).sense().show();
55    if ui.context_menu(&wall) {
56        launcher(desk, ui);
57        ui.close();
58    }
59    // A window for each program that is open.
60    for (number, name) in PROGRAMS.iter().enumerate() {
61        if !ui.panel(&mut desk.windows[number], name) {
62            continue;
63        }
64        match number {
65            0 => files(desk, ui),
66            1 => notes(desk, ui),
67            2 => monitor(desk, ui),
68            _ => settings(desk, ui),
69        }
70        ui.close();
71    }
72    tasks(desk, ui);
73    if desk.own_pointer {
74        ui.show_pointer();
75    }
76}
Source

pub fn high_contrast(colors: ContrastColors) -> Self

High contrast in these colours: ContrastColors::DARK, ContrastColors::LIGHT, or the person’s system colours. Text is never dimmed; selected or hovered parts are the background moved toward the selection colour, never so far that text on it drops below 7:1; that colour is the accent, with its text; lines are strong.

Examples found in repository?
examples/gallery.rs (line 1233)
1230fn theme(app: &App, ui: &Ui) -> Theme {
1231    let theme = match (app.system, app.contrast, app.light) {
1232        (true, ..) => ui.system_theme(),
1233        (false, true, light) => Theme::high_contrast(if light { ContrastColors::LIGHT } else { ContrastColors::DARK }),
1234        (false, false, true) => Theme::light().accented(app.tint),
1235        (false, false, false) => Theme::dark().accented(app.tint),
1236    };
1237    [theme.dense(), theme, theme.roomy()][app.spacing]
1238}
Source

pub fn accented(self, color: Color) -> Self

The same around color, which becomes the accent (lightened or darkened as needed to read as text on the background), with white or near black on it, whichever reads better; selected and hovered parts lean toward it.

Examples found in repository?
examples/gallery.rs (line 1234)
1230fn theme(app: &App, ui: &Ui) -> Theme {
1231    let theme = match (app.system, app.contrast, app.light) {
1232        (true, ..) => ui.system_theme(),
1233        (false, true, light) => Theme::high_contrast(if light { ContrastColors::LIGHT } else { ContrastColors::DARK }),
1234        (false, false, true) => Theme::light().accented(app.tint),
1235        (false, false, false) => Theme::dark().accented(app.tint),
1236    };
1237    [theme.dense(), theme, theme.roomy()][app.spacing]
1238}
Source

pub fn dense(self) -> Self

The same, tighter: smaller buttons and boxes, smaller gaps, less rounded corners.

Examples found in repository?
examples/gallery.rs (line 1237)
1230fn theme(app: &App, ui: &Ui) -> Theme {
1231    let theme = match (app.system, app.contrast, app.light) {
1232        (true, ..) => ui.system_theme(),
1233        (false, true, light) => Theme::high_contrast(if light { ContrastColors::LIGHT } else { ContrastColors::DARK }),
1234        (false, false, true) => Theme::light().accented(app.tint),
1235        (false, false, false) => Theme::dark().accented(app.tint),
1236    };
1237    [theme.dense(), theme, theme.roomy()][app.spacing]
1238}
Source

pub fn roomy(self) -> Self

The same, looser: larger buttons and boxes, larger gaps, rounder corners.

Examples found in repository?
examples/gallery.rs (line 1237)
1230fn theme(app: &App, ui: &Ui) -> Theme {
1231    let theme = match (app.system, app.contrast, app.light) {
1232        (true, ..) => ui.system_theme(),
1233        (false, true, light) => Theme::high_contrast(if light { ContrastColors::LIGHT } else { ContrastColors::DARK }),
1234        (false, false, true) => Theme::light().accented(app.tint),
1235        (false, false, false) => Theme::dark().accented(app.tint),
1236    };
1237    [theme.dense(), theme, theme.roomy()][app.spacing]
1238}
Source

pub fn text_scaled(self, by: f32) -> Self

The same with text by times as large (1: unchanged), and buttons and boxes taller as the text needs. Gaps and corners stay.

Source

pub fn following(preferences: &Preferences) -> Self

The theme following all the person asked their system for: high contrast in their colours if asked; else dark or light, around their accent if any, with text as large as asked. (High contrast keeps its own colours: the accent is left out there.)

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Self

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 Theme

Source§

impl Debug for Theme

Source§

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

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

impl PartialEq for Theme

Source§

fn eq(&self, other: &Self) -> 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 Theme

Auto Trait Implementations§

§

impl Forget for Theme

§

impl Freeze for Theme

§

impl Move for Theme

§

impl RefUnwindSafe for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

§

impl UnwindSafe for Theme

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> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.