diff --git a/Cargo.toml b/Cargo.toml index 6662e4d..7efba77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,11 +25,15 @@ os_info = "3.0.1" uuid = { version = "0.8", features = ["v4"], optional = true } url = "2.1.1" +[dev-dependencies] +eval = "0.4" + [features] default = ["macos"] cloudkit = [] ios = [] macos = [] +color_fallbacks = [] quicklook = [] user-notifications = ["uuid"] webview = [] diff --git a/examples/autolayout.rs b/examples/autolayout.rs index 0bdc947..889cfa6 100644 --- a/examples/autolayout.rs +++ b/examples/autolayout.rs @@ -1,7 +1,7 @@ -//! This example showcases setting up a basic application and window, and setting up some views to -//! work with autolayout. +//! This example showcases setting up a basic application and window, setting up some views to +//! work with autolayout, and some basic ways to handle colors. -use cacao::color::rgb; +use cacao::color::{Color, Theme}; use cacao::layout::{Layout, LayoutConstraint}; use cacao::view::View; @@ -24,8 +24,7 @@ struct AppWindow { content: View, blue: View, red: View, - green: View, - window: Window + green: View } impl WindowDelegate for AppWindow { @@ -35,13 +34,18 @@ impl WindowDelegate for AppWindow { window.set_title("AutoLayout Example"); window.set_minimum_content_size(300., 300.); - self.blue.set_background_color(rgb(105, 162, 176)); + let dynamic = Color::dynamic(|style| match (style.theme, style.contrast) { + (Theme::Dark, _) => Color::SystemGreen, + _ => Color::SystemRed + }); + + self.blue.set_background_color(Color::SystemBlue); self.content.add_subview(&self.blue); - self.red.set_background_color(rgb(224, 82, 99)); + self.red.set_background_color(Color::SystemRed); self.content.add_subview(&self.red); - self.green.set_background_color(rgb(161, 192, 132)); + self.green.set_background_color(dynamic); self.content.add_subview(&self.green); window.set_content_view(&self.content); diff --git a/examples/calculator/button_row.rs b/examples/calculator/button_row.rs new file mode 100644 index 0000000..04166fb --- /dev/null +++ b/examples/calculator/button_row.rs @@ -0,0 +1,82 @@ +use cacao::layout::{LayoutConstraint, Layout}; +use cacao::button::Button; +use cacao::color::Color; +use cacao::view::View; + +use crate::calculator::Msg; +use crate::content_view::{button, BUTTON_WIDTH, BUTTON_HEIGHT}; + +pub struct ButtonRow { + pub view: View, + pub buttons: Vec