From: Olaf Wintermann Date: Fri, 10 Apr 2026 19:11:50 +0000 (+0200) Subject: add tabview X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=ba5e8ba94e24a8034092c4b14902f0b2e3aba64c;p=note.git add tabview --- diff --git a/application/src/main.rs b/application/src/main.rs index 775af6f..a1b0279 100644 --- a/application/src/main.rs +++ b/application/src/main.rs @@ -12,21 +12,21 @@ struct App; impl ui::Application for App { fn on_startup(&self) { let mut obj = ui::window("note"); - obj.button(|b| { - b.label("Hello"); - }); - obj.hbox_builder().create(|obj| { - obj.button(|b|{ - b.label("HButton 1"); - }); - obj.button(|b|{ - b.label("HButton 2"); + obj.tabview(|a| { + a.fill(true); + }, + |t| { + t.tab("Tab 1", |obj| { + obj.textarea(|t| { + t.fill(true); + }); }); - obj.button(|b|{ - b.label("HButton 3"); + t.tab("Tab 2", |obj| { + obj.textarea(|t| { + t.fill(true); + }); }); }); - obj.show(); } } diff --git a/ui-rs/src/ui/container.rs b/ui-rs/src/ui/container.rs index 1b7cc6f..96b3bac 100644 --- a/ui-rs/src/ui/container.rs +++ b/ui-rs/src/ui/container.rs @@ -845,6 +845,212 @@ impl<'a> Drop for SidebarBuilder<'a> { } } + + +/* -------------------------------- Tabview Container -------------------------------- */ + +pub struct TabViewBuilder<'a> { + args: *mut UiTabViewArgs, + obj: &'a mut toolkit::UiObject +} + +pub struct TabBuilder<'a> { + obj: &'a mut toolkit::UiObject +} + +impl<'a> TabBuilder<'a> { + pub fn tab(&mut self, title: &str, create_ui: F) + where + F: FnOnce(&mut toolkit::UiObject) + { + unsafe { + let title = CString::new(title).unwrap(); + ui_tab_create(self.obj.ptr, title.as_ptr()); + } + create_ui(self.obj); + unsafe { + ui_container_begin_close(self.obj.ptr); + ui_container_finish(self.obj.ptr); + } + } +} + +impl toolkit::UiObject { + pub fn tabview(&mut self, build: F, ui: U) + where + F: Fn(&mut TabViewBuilder), + U: FnOnce(&mut TabBuilder) { + let mut builder = self.tabview_builder(); + build(&mut builder); + builder.create(ui); + } + + pub fn tabview_builder(&mut self) -> TabViewBuilder<'_> + { + unsafe { + let args = ui_tabview_args_new(); + TabViewBuilder { + args, + obj: self + } + } + } +} + +impl<'a> TabViewBuilder<'a> { + pub fn create(&mut self, create_ui: F) + where F: FnOnce(&mut TabBuilder) { + unsafe { + ui_tabview_create(self.obj.ptr, self.args); + } + let mut tabbuilder = TabBuilder { + obj: self.obj + }; + create_ui(&mut tabbuilder); + unsafe { + ui_container_begin_close(self.obj.ptr); + ui_container_finish(self.obj.ptr); + } + } + + pub fn fill(&mut self, fill: bool) -> &mut Self { + unsafe { + ui_tabview_args_set_fill(self.args, if fill { 1 } else { 0 }); + } + self + } + + pub fn hexpand(&mut self, value: bool) -> &mut Self { + unsafe { + ui_tabview_args_set_hexpand(self.args, if value { 1 } else { 0 }); + } + self + } + + pub fn vexpand(&mut self, value: bool) -> &mut Self { + unsafe { + ui_tabview_args_set_vexpand(self.args, if value { 1 } else { 0 }); + } + self + } + + pub fn hfill(&mut self, value: bool) -> &mut Self { + unsafe { + ui_tabview_args_set_hfill(self.args, if value { 1 } else { 0 }); + } + self + } + + pub fn vfill(&mut self, value: bool) -> &mut Self { + unsafe { + ui_tabview_args_set_vfill(self.args, if value { 1 } else { 0 }); + } + self + } + + pub fn override_defaults(&mut self, value: bool) -> &mut Self { + unsafe { + ui_tabview_args_set_override_defaults(self.args, if value { 1 } else { 0 }); + } + self + } + + pub fn margin(&mut self, value: i32) -> &mut Self { + unsafe { + ui_tabview_args_set_margin(self.args, value); + } + self + } + + pub fn margin_left(&mut self, value: i32) -> &mut Self { + unsafe { + ui_tabview_args_set_margin_left(self.args, value); + } + self + } + + pub fn margin_right(&mut self, value: i32) -> &mut Self { + unsafe { + ui_tabview_args_set_margin_right(self.args, value); + } + self + } + + pub fn margin_top(&mut self, value: i32) -> &mut Self { + unsafe { + ui_tabview_args_set_margin_top(self.args, value); + } + self + } + + pub fn margin_bottom(&mut self, value: i32) -> &mut Self { + unsafe { + ui_tabview_args_set_margin_bottom(self.args, value); + } + self + } + + pub fn colspan(&mut self, value: i32) -> &mut Self { + unsafe { + ui_tabview_args_set_colspan(self.args, value); + } + self + } + + pub fn rowspan(&mut self, value: i32) -> &mut Self { + unsafe { + ui_tabview_args_set_rowspan(self.args, value); + } + self + } + + pub fn name(&mut self, value: &str) -> &mut Self { + let cstr = CString::new(value).unwrap(); + unsafe { + ui_tabview_args_set_name(self.args, cstr.as_ptr()); + } + self + } + + pub fn style_class(&mut self, value: &str) -> &mut Self { + let cstr = CString::new(value).unwrap(); + unsafe { + ui_tabview_args_set_style_class(self.args, cstr.as_ptr()); + } + self + } + + pub fn spacing(&mut self, value: i32) -> &mut Self { + unsafe { + ui_tabview_args_set_spacing(self.args, value); + } + self + } + + pub fn columnspacing(&mut self, value: i32) -> &mut Self { + unsafe { + ui_tabview_args_set_columnspacing(self.args, value); + } + self + } + + pub fn rowspacing(&mut self, value: i32) -> &mut Self { + unsafe { + ui_tabview_args_set_rowspacing(self.args, value); + } + self + } + + // TODO + + pub fn subcontainer_type(&mut self, subtype: SubContainer) -> &mut Self { + unsafe { + ui_tabview_args_set_subcontainer(self.args, subtype as c_int); + } + self + } +} + /* -------------------------------- C functions -------------------------------- */ extern "C" { @@ -862,6 +1068,8 @@ extern "C" { fn ui_sidebar_create(obj: *mut UiObject, args: *const UiSidebarArgs) -> *mut c_void; fn ui_left_panel_create(obj: *mut UiObject, args: *const UiSidebarArgs) -> *mut c_void; fn ui_right_panel_create(obj: *mut UiObject, args: *const UiSidebarArgs) -> *mut c_void; + fn ui_tabview_create(obj: *mut UiObject, args: *const UiTabViewArgs) -> *mut c_void; + fn ui_tab_create(obj: *mut UiObject, label: *const c_char) -> *mut c_void; fn ui_newline(obj: *mut UiObject); @@ -947,4 +1155,32 @@ extern "C" { fn ui_sidebar_args_set_style_class(args: *mut UiSidebarArgs, classname: *const c_char); fn ui_sidebar_args_set_spacing(args: *mut UiSidebarArgs, spacing: c_int); fn ui_sidebar_args_free(args: *mut UiSidebarArgs); + + fn ui_tabview_args_new() -> *mut UiTabViewArgs; + fn ui_tabview_args_set_fill(args: *mut UiTabViewArgs, fill: c_int); + fn ui_tabview_args_set_hexpand(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_vexpand(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_hfill(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_vfill(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_override_defaults(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_margin(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_margin_left(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_margin_right(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_margin_top(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_margin_bottom(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_colspan(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_rowspan(args: *mut UiTabViewArgs, value: c_int); + fn ui_tabview_args_set_name(args: *mut UiTabViewArgs, name: *const c_char); + fn ui_tabview_args_set_style_class(args: *mut UiTabViewArgs, classname: *const c_char); + fn ui_tabview_args_set_spacing(args: *mut UiTabViewArgs, spacing: c_int); + fn ui_tabview_args_set_columnspacing(args: *mut UiTabViewArgs, spacing: c_int); + fn ui_tabview_args_set_rowspacing(args: *mut UiTabViewArgs, spacing: c_int); + fn ui_tabview_args_set_type(args: *mut UiTabViewArgs, tabview: c_int); + fn ui_tabview_args_set_onchange(args: *mut UiTabViewArgs, callback: UiCallback); + fn ui_tabview_args_set_onchangedata(args: *mut UiTabViewArgs, data: *mut c_void); + fn ui_tabview_args_set_varname(args: *mut UiTabViewArgs, varname: *const c_char); + fn ui_tabview_args_set_subcontainer(args: *mut UiTabViewArgs, subcontainer: c_int); + fn ui_tabview_args_set_value(args: *mut UiTabViewArgs, ivalue: *mut UiInteger); + fn ui_tabview_args_set_visibility_states(args: *mut UiTabViewArgs, states: *const c_int, numstates: c_int); + fn ui_tabview_args_free(args: *mut UiTabViewArgs); }