From 50ee6e6b776e1bdf22e17ca1605edfdde290e7fc Mon Sep 17 00:00:00 2001 From: Tsuki Date: Tue, 19 Nov 2024 21:23:01 +0800 Subject: [PATCH] sync --- mp/resources/ai/ai_markup.txt | 61 ++++++++++ mp/resources/icons/Icon_Search.svg | 10 ++ mp/resources/icons/icon_add.svg | 1 + mp/resources/icons/icon_auto.svg | 1 + mp/resources/icons/icon_copy.svg | 1 + mp/resources/icons/icon_del.svg | 1 + mp/resources/icons/icon_designer.svg | 1 + mp/resources/icons/icon_editor.svg | 1 + mp/resources/icons/icon_file.svg | 1 + .../icons/icon_filetree_file_create.svg | 1 + .../icons/icon_filetree_folder_create.svg | 1 + mp/resources/icons/icon_history_ff.svg | 1 + mp/resources/icons/icon_history_rew.svg | 1 + mp/resources/icons/icon_log.svg | 1 + mp/resources/icons/icon_log_bullet.svg | 1 + mp/resources/icons/icon_outliner.svg | 1 + mp/resources/icons/icon_profiler.svg | 1 + mp/resources/icons/icon_profiler_clear.svg | 1 + mp/resources/icons/icon_run.svg | 1 + .../icons/icon_search_case_sensitive.svg | 1 + mp/resources/icons/icon_search_full_word.svg | 1 + mp/resources/icons/icon_search_regex.svg | 1 + mp/resources/icons/icon_tab_app.svg | 1 + mp/resources/icons/icon_times.svg | 1 + mp/resources/logo_makepad.svg | 29 +++++ mp/src/app_ui.rs | 5 + mp/src/widgets/selector_modal.rs | 105 ++++++++++++++++++ 27 files changed, 232 insertions(+) create mode 100644 mp/resources/ai/ai_markup.txt create mode 100644 mp/resources/icons/Icon_Search.svg create mode 100644 mp/resources/icons/icon_add.svg create mode 100644 mp/resources/icons/icon_auto.svg create mode 100644 mp/resources/icons/icon_copy.svg create mode 100644 mp/resources/icons/icon_del.svg create mode 100644 mp/resources/icons/icon_designer.svg create mode 100644 mp/resources/icons/icon_editor.svg create mode 100644 mp/resources/icons/icon_file.svg create mode 100644 mp/resources/icons/icon_filetree_file_create.svg create mode 100644 mp/resources/icons/icon_filetree_folder_create.svg create mode 100644 mp/resources/icons/icon_history_ff.svg create mode 100644 mp/resources/icons/icon_history_rew.svg create mode 100644 mp/resources/icons/icon_log.svg create mode 100644 mp/resources/icons/icon_log_bullet.svg create mode 100644 mp/resources/icons/icon_outliner.svg create mode 100644 mp/resources/icons/icon_profiler.svg create mode 100644 mp/resources/icons/icon_profiler_clear.svg create mode 100644 mp/resources/icons/icon_run.svg create mode 100644 mp/resources/icons/icon_search_case_sensitive.svg create mode 100644 mp/resources/icons/icon_search_full_word.svg create mode 100644 mp/resources/icons/icon_search_regex.svg create mode 100644 mp/resources/icons/icon_tab_app.svg create mode 100644 mp/resources/icons/icon_times.svg create mode 100644 mp/resources/logo_makepad.svg diff --git a/mp/resources/ai/ai_markup.txt b/mp/resources/ai/ai_markup.txt new file mode 100644 index 0000000..a197e33 --- /dev/null +++ b/mp/resources/ai/ai_markup.txt @@ -0,0 +1,61 @@ + +You are a helpful assistant. + + + + + +You are a Rust programming assistant. Please answer with code examples only and very no explanations + + + +You are a Rust programming assistant for writing Makepad applications. +You have been given components and example code as context, plus the users project. + + + +Generate the whole file including the Rust logic. + + + +You are a Rust programming assistant for writing Makepad applications. +You have been given components and example code as context, plus the users project. + + + +Only rewrite the live_design block and only output that code not the rest of the file. + + + +Please answer with code only and don't give explanations. +Don't invent new function signatures, only use what is given in the example. +Remove all comments from the generated code. + +Shader code is GLSL syntax, not Rust so only use GLSL functions and not rust postfix methods. +Don't use ```iTime``` but use ```self.time```. +Types in shader code are inferenced, and written as ```let variable = value``` +Make sure that the ```pixel()``` function has an explicit ```return``` call +Makepad shader values are mut by default and should be declard as ```let``` and not ```let mut``` +Makepad shaders use ```for i in 0..10{ }``` as their loop construct. +You cannot use ```while``` as this is potentially unbounded +Remember that return types for the shaders are written rust style: ```fn pixel(self)->vec4{}``` +Please write background shaders as ```draw_bg:{fn pixel(self)->vec4{return #5}}``` +Do not write ```mut Cx2dShader``` this does not exist. +Instead of ```self.time()``` it is ```self.time``` +Instead of ```event.action``` write ```action``` +Local function for the shader cannot be placed inside the ```pixel``` function but need to be inside the draw_bg scope and before the pixel function. Please remember to write the function type signature in the declaration rust-style ```fn thing(a:vec3, b:vec4)->vec4``` +Please remember to give functions an explicit ```return``` call, it is like GLSL and not like Rust with an automatic return value. +If you use ```self.time``` make sure the first function argument is called ```self``` and the function is called as ```self.functionname()``` +Shader code does not support the ```f32``` type but needs to use ```float``` instead +You cannot cast an int to a float with ```i as float``` but you have to write it as ```float(i)``` +Constant definitions can only be inside functions and not at the root ```draw_bg``` block +Make sure that when you call a method ```self.methodname``` that the first argument in the declaration is ```fn methodname(self)``` +If you call a method on self call ```fncall``` make sure the first argument on the function declaration is ```(self)``` +When asked to write code in Rust, remember to put the code in the ```clicked``` if of the Rust block, do not put it in the shader code ```draw_bg``` area +You cannot set event handlers like ```onclick``` in the ```live_design{}``` block, only in the Rust code +you have to set ```show_bg: true``` on a View if you want the background shader to be visible +In makepad DSL code the system is id = {}. You do not set the ids on it via an id attribute +Dont pass cx as argument to clicked +Don't make the background color ```#f00``` by default, use ```#333``` + + diff --git a/mp/resources/icons/Icon_Search.svg b/mp/resources/icons/Icon_Search.svg new file mode 100644 index 0000000..187714d --- /dev/null +++ b/mp/resources/icons/Icon_Search.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/mp/resources/icons/icon_add.svg b/mp/resources/icons/icon_add.svg new file mode 100644 index 0000000..2a672b3 --- /dev/null +++ b/mp/resources/icons/icon_add.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_auto.svg b/mp/resources/icons/icon_auto.svg new file mode 100644 index 0000000..e659ee7 --- /dev/null +++ b/mp/resources/icons/icon_auto.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_copy.svg b/mp/resources/icons/icon_copy.svg new file mode 100644 index 0000000..f2e030d --- /dev/null +++ b/mp/resources/icons/icon_copy.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_del.svg b/mp/resources/icons/icon_del.svg new file mode 100644 index 0000000..38182e3 --- /dev/null +++ b/mp/resources/icons/icon_del.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_designer.svg b/mp/resources/icons/icon_designer.svg new file mode 100644 index 0000000..0847053 --- /dev/null +++ b/mp/resources/icons/icon_designer.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_editor.svg b/mp/resources/icons/icon_editor.svg new file mode 100644 index 0000000..e63b709 --- /dev/null +++ b/mp/resources/icons/icon_editor.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_file.svg b/mp/resources/icons/icon_file.svg new file mode 100644 index 0000000..394dc43 --- /dev/null +++ b/mp/resources/icons/icon_file.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_filetree_file_create.svg b/mp/resources/icons/icon_filetree_file_create.svg new file mode 100644 index 0000000..b191826 --- /dev/null +++ b/mp/resources/icons/icon_filetree_file_create.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_filetree_folder_create.svg b/mp/resources/icons/icon_filetree_folder_create.svg new file mode 100644 index 0000000..6cc35d0 --- /dev/null +++ b/mp/resources/icons/icon_filetree_folder_create.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_history_ff.svg b/mp/resources/icons/icon_history_ff.svg new file mode 100644 index 0000000..8bf78af --- /dev/null +++ b/mp/resources/icons/icon_history_ff.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_history_rew.svg b/mp/resources/icons/icon_history_rew.svg new file mode 100644 index 0000000..827cb42 --- /dev/null +++ b/mp/resources/icons/icon_history_rew.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_log.svg b/mp/resources/icons/icon_log.svg new file mode 100644 index 0000000..e97c543 --- /dev/null +++ b/mp/resources/icons/icon_log.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_log_bullet.svg b/mp/resources/icons/icon_log_bullet.svg new file mode 100644 index 0000000..e7b45e0 --- /dev/null +++ b/mp/resources/icons/icon_log_bullet.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_outliner.svg b/mp/resources/icons/icon_outliner.svg new file mode 100644 index 0000000..fe8d946 --- /dev/null +++ b/mp/resources/icons/icon_outliner.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_profiler.svg b/mp/resources/icons/icon_profiler.svg new file mode 100644 index 0000000..1540658 --- /dev/null +++ b/mp/resources/icons/icon_profiler.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_profiler_clear.svg b/mp/resources/icons/icon_profiler_clear.svg new file mode 100644 index 0000000..51e82c9 --- /dev/null +++ b/mp/resources/icons/icon_profiler_clear.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_run.svg b/mp/resources/icons/icon_run.svg new file mode 100644 index 0000000..8bf78af --- /dev/null +++ b/mp/resources/icons/icon_run.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_search_case_sensitive.svg b/mp/resources/icons/icon_search_case_sensitive.svg new file mode 100644 index 0000000..539b319 --- /dev/null +++ b/mp/resources/icons/icon_search_case_sensitive.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_search_full_word.svg b/mp/resources/icons/icon_search_full_word.svg new file mode 100644 index 0000000..ebd5216 --- /dev/null +++ b/mp/resources/icons/icon_search_full_word.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_search_regex.svg b/mp/resources/icons/icon_search_regex.svg new file mode 100644 index 0000000..c61e179 --- /dev/null +++ b/mp/resources/icons/icon_search_regex.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_tab_app.svg b/mp/resources/icons/icon_tab_app.svg new file mode 100644 index 0000000..ba53b92 --- /dev/null +++ b/mp/resources/icons/icon_tab_app.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/icons/icon_times.svg b/mp/resources/icons/icon_times.svg new file mode 100644 index 0000000..a513269 --- /dev/null +++ b/mp/resources/icons/icon_times.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mp/resources/logo_makepad.svg b/mp/resources/logo_makepad.svg new file mode 100644 index 0000000..0797331 --- /dev/null +++ b/mp/resources/logo_makepad.svg @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mp/src/app_ui.rs b/mp/src/app_ui.rs index d8ccb82..37eb816 100644 --- a/mp/src/app_ui.rs +++ b/mp/src/app_ui.rs @@ -6,6 +6,7 @@ live_design! { import crate::widgets::renderer::IRenderer; import makepad_draw::shader::std::*; + import crate::widgets::selector_modal::SelectorItem; HELLO = "Hello, World!"; @@ -127,6 +128,10 @@ live_design! {

{ text: "Input"} + { + text: "Selector Item" + } + { { diff --git a/mp/src/widgets/selector_modal.rs b/mp/src/widgets/selector_modal.rs index 191e83f..217b7c7 100644 --- a/mp/src/widgets/selector_modal.rs +++ b/mp/src/widgets/selector_modal.rs @@ -1,9 +1,12 @@ use makepad_widgets::*; live_design! { + import makepad_draw::shader::std::*; import makepad_widgets::base::*; import makepad_widgets::theme_desktop_dark::*; + ICO_SEARCH = dep("crate://self/resources/icons/Icon_Search.svg") + SelectorModal = { content: { height: 600, @@ -41,4 +44,106 @@ live_design! { } } + + SelectorItem = {{SelectorItem}} { + height: Fit + width: Fit + draw_bg: { + + fn pixel(self) -> vec4 { + return mix(#7,#4,self.pos.y); + } + } + draw_label: { + color: #f0f0f0 + text_style: { + font_size: 8 + } + } + draw_icon: { + // svg_file: ICO_SEARCH, + svg_file: dep("crate://self/resources/logo_makepad.svg") + fn get_color(self) -> vec4 { + return (THEME_COLOR_D_1) + } + } + icon_walk: {width: 250.0, height: Fit} + } } + +#[derive(Live, Widget)] +pub struct SelectorModal { + #[deref] + view: View, +} + +impl Widget for SelectorModal { + fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep { + DrawStep::done() + } +} + +impl LiveHook for SelectorModal {} + +#[derive(Clone, Debug, DefaultNone)] +pub enum SelectorItemAction { + Select(usize), + Unselect(usize), + None, +} + +#[derive(Live, Widget)] +pub struct SelectorItem { + #[redraw] + #[live] + draw_bg: DrawQuad, + #[live] + draw_label: DrawText, + #[live] + draw_icon: DrawIcon, + #[walk] + walk: Walk, + + #[live] + icon_walk: Walk, + + #[rust] + selected: bool, + #[rust] + id: usize, + #[live] + pub text: ArcStringMut, +} + +impl Widget for SelectorItem { + fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) { + let uid = self.widget_uid(); + match event.hits(cx, self.draw_bg.area()) { + Hit::FingerDown(_) => { + if self.selected { + cx.widget_action(uid, &scope.path, SelectorItemAction::Unselect(self.id)); + self.selected = false; + self.draw_bg + .draw_vars + .set_var_instance(cx, id!(bg_color), &[]); + } else { + cx.widget_action(uid, &scope.path, SelectorItemAction::Select(self.id)); + self.selected = true; + } + } + _ => {} + } + } + fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep { + self.draw_bg.begin(cx, walk, Layout::default()); + self.draw_icon.draw_walk(cx, self.icon_walk); + self.draw_label + .draw_walk(cx, walk, Align::default(), self.text.as_ref()); + self.draw_bg.end(cx); + DrawStep::done() + } +} + +impl SelectorItem {} + +impl LiveHook for SelectorItem {}