Skip to content

Commit

Permalink
Multiple changes I had to make for Ebou (#89)
Browse files Browse the repository at this point in the history
* Add segmented control, icons, toolbar

* add to demos

* doc tests

* format code

* Additional SFSymbol definitions
  • Loading branch information
terhechte committed Aug 1, 2023
1 parent 1b57750 commit e6696ea
Show file tree
Hide file tree
Showing 17 changed files with 449 additions and 30 deletions.
2 changes: 1 addition & 1 deletion examples/calculator/content_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn button(text: &str, msg: Msg) -> Button {
button.set_bordered(false);
button.set_bezel_style(BezelStyle::SmallSquare);
button.set_focus_ring_type(FocusRingType::None);
button.set_action(move || dispatch(msg.clone()));
button.set_action(move |_| dispatch(msg.clone()));
button.set_key_equivalent(&*text.to_lowercase());

let font = Font::system(22.);
Expand Down
25 changes: 16 additions & 9 deletions examples/popover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
//! - Another Controller / View

use cacao::appkit::menu::{Menu, MenuItem};
use cacao::appkit::segmentedcontrol::SegmentedControl;
use cacao::appkit::window::{Window, WindowConfig, WindowController, WindowDelegate};
use cacao::appkit::{App, AppDelegate};
use cacao::button::Button;
use cacao::foundation::NSArray;
use cacao::geometry::{Edge, Rect};
use cacao::image::Image;
use cacao::layout::{Layout, LayoutConstraint};
use cacao::notification_center::Dispatcher;
use cacao::text::{Font, Label};
use cacao::view::{Popover, PopoverConfig, View, ViewController, ViewDelegate};

struct BasicApp {
Expand Down Expand Up @@ -124,7 +126,7 @@ impl ViewDelegate for PopoverExampleContentView {

fn did_load(&mut self, view: cacao::view::View) {
let mut button = Button::new("Show");
button.set_action(|| dispatch_ui(Msg::Click));
button.set_action(|_| dispatch_ui(Msg::Click));

let controller = PopoverExampleContentViewController::new();
let config = PopoverConfig {
Expand Down Expand Up @@ -164,23 +166,28 @@ impl Dispatcher for BasicApp {

#[derive(Debug)]
struct PopoverExampleContentViewController {
pub label: Label
pub control: SegmentedControl
}

impl PopoverExampleContentViewController {
fn new() -> Self {
let label = Label::new();
let font = Font::system(20.);
label.set_font(&font);
label.set_text("Hello");
Self { label }
let images = NSArray::from(vec![
&*Image::symbol(cacao::image::SFSymbol::AtSymbol, "Hello").0,
&*Image::symbol(cacao::image::SFSymbol::PaperPlane, "Hello").0,
&*Image::symbol(cacao::image::SFSymbol::PaperPlaneFilled, "Hello").0,
]);
let mut control = SegmentedControl::new(images, cacao::appkit::segmentedcontrol::TrackingMode::SelectOne);
control.set_action(|index| {
println!("Selected Index {index}");
});
Self { control }
}
}

impl ViewDelegate for PopoverExampleContentViewController {
const NAME: &'static str = "PopoverExampleContentViewController";

fn did_load(&mut self, view: View) {
view.add_subview(&self.label);
view.add_subview(&self.control);
}
}
2 changes: 1 addition & 1 deletion examples/todos_list/add/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl ViewDelegate for AddNewTodoContentView {

let mut button = Button::new("Add");
button.set_key_equivalent("\r");
button.set_action(|| dispatch_ui(Message::ProcessNewTodo));
button.set_action(|_| dispatch_ui(Message::ProcessNewTodo));

view.add_subview(&instructions);
view.add_subview(&input);
Expand Down
3 changes: 2 additions & 1 deletion examples/todos_list/preferences/toggle_option_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use cacao::layout::{Layout, LayoutConstraint};
use cacao::switch::Switch;
use cacao::text::Label;
use cacao::view::View;
use objc::runtime::Object;

/// A reusable widget for a toggle; this is effectively a standard checkbox/label combination for
/// toggling a boolean value.
Expand Down Expand Up @@ -55,7 +56,7 @@ impl ToggleOptionView {
/// can toggle your settings and such there.
pub fn configure<F>(&mut self, text: &str, subtitle: &str, state: bool, handler: F)
where
F: Fn() + Send + Sync + 'static
F: Fn(*const Object) + Send + Sync + 'static
{
self.title.set_text(text);
self.subtitle.set_text(subtitle);
Expand Down
4 changes: 2 additions & 2 deletions examples/todos_list/preferences/toolbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Default for PreferencesToolbar {
let icon = Image::toolbar_icon(MacSystemIcon::PreferencesGeneral, "General");
item.set_image(icon);

item.set_action(|| {
item.set_action(|_| {
dispatch_ui(Message::SwitchPreferencesToGeneralPane);
});

Expand All @@ -32,7 +32,7 @@ impl Default for PreferencesToolbar {
let icon = Image::toolbar_icon(MacSystemIcon::PreferencesAdvanced, "Advanced");
item.set_image(icon);

item.set_action(|| {
item.set_action(|_| {
dispatch_ui(Message::SwitchPreferencesToAdvancedPane);
});

Expand Down
3 changes: 2 additions & 1 deletion examples/todos_list/storage/defaults.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;

use cacao::defaults::{UserDefaults, Value};
use objc::runtime::Object;

const EXAMPLE: &str = "exampleSetting";

Expand All @@ -25,7 +26,7 @@ impl Defaults {
}

/// Toggles the example setting.
pub fn toggle_should_whatever() {
pub fn toggle_should_whatever(_object: *const Object) {
toggle_bool(EXAMPLE);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/todos_list/todos/toolbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Default for TodosToolbar {
item.set_title("Add Todo");
item.set_button(Button::new("+ New"));

item.set_action(|| {
item.set_action(|_| {
dispatch_ui(Message::OpenNewTodoSheet);
});

Expand Down
1 change: 1 addition & 0 deletions src/appkit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ pub mod toolbar;
pub mod window;

pub mod haptics;
pub mod segmentedcontrol;
Loading

0 comments on commit e6696ea

Please sign in to comment.