浏览代码

Sync. Add work to CppGTK.

Cixo Develop 5 月之前
父节点
当前提交
f212210aeb

+ 8 - 0
cppGTK/LICENSE

@@ -0,0 +1,8 @@
+MIT License
+Copyright (c) <year> <copyright holders>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 3 - 0
cppGTK/README.md

@@ -0,0 +1,3 @@
+# cx-light-app
+
+That is app for controlling cx-light devices.

+ 17 - 0
cppGTK/source/buttons.cpp

@@ -0,0 +1,17 @@
+#include <gtkmm.h>
+#include <iostream>
+
+#include "strings.hpp"
+#include "buttons.hpp"
+
+namespace cx_light {
+
+add_light_button::add_light_button() {
+    this->set_label(__(ADD_LIGHT));
+}
+
+void add_light_button::on_clicked() {
+    std::cout << "Add light clicked\n";
+}
+
+}

+ 16 - 0
cppGTK/source/buttons.hpp

@@ -0,0 +1,16 @@
+#ifndef BUTTONS_HPP_INCLUDED
+#define BUTTONS_HPP_INCLUDED
+
+#include <gtkmm.h>
+
+namespace cx_light {
+
+class add_light_button : public Gtk::Button {
+    public:
+        add_light_button();
+        void on_clicked();
+};
+
+}
+
+#endif

+ 6 - 0
cppGTK/source/config.hpp

@@ -0,0 +1,6 @@
+#ifndef CONFIG_HPP_INCLUDED
+#define CONFIG_HPP_INCLUDED
+
+#define DEFAULT_MARGIN 10
+
+#endif

+ 13 - 0
cppGTK/source/core.cpp

@@ -0,0 +1,13 @@
+#include <gtkmm.h>
+
+#include "strings.hpp"
+#include "core_window.hpp"
+
+int main(int argc, char *argv[]) {
+    Gtk::Main kit(argc, argv);
+
+    cx_light::core_window window;
+    Gtk::Main::run(window);
+
+    return 0;
+}

+ 68 - 0
cppGTK/source/core_window.cpp

@@ -0,0 +1,68 @@
+#include <gtkmm.h>
+#include <iostream>
+
+#include "strings.hpp"
+#include "config.hpp"
+#include "core_window.hpp"
+#include "buttons.hpp"
+
+namespace cx_light {
+
+core_window::core_window() {
+    this->set_title(__(WINDOW_TITLE));
+    this->set_default_size(400, 200);
+
+    this->init_default();
+    this->show_all();
+}
+
+core_window::~core_window() {
+    delete this->add_light;
+    delete this->lights_list;
+    delete this->lights_list_frame;
+    delete this->content;
+}
+
+void core_window::init_default() {
+    this->create_lights_list();
+
+    this->content = new Gtk::Grid();
+    this->content->attach(*this->lights_list_frame, 0, 0);
+
+    this->add(*this->content);
+}
+
+void core_window::create_lights_list() {
+    this->add_light = new add_light_button();
+
+    this->lights_list_frame = new Gtk::Frame();
+    this->lights_list_frame->set_label(__(LIGHTS_LIST));
+    this->set_margin(this->lights_list_frame, DEFAULT_MARGIN);
+
+    this->lights_list = new Gtk::ListBox();
+    this->set_margin(this->lights_list, DEFAULT_MARGIN);
+
+    this->lights_list_frame->add(*this->lights_list);
+    this->lights_list->append(*this->add_light);
+}
+
+
+void core_window::set_margin(Gtk::Widget *target, unsigned int margin) {
+    target->set_margin_top(margin);
+    target->set_margin_left(margin);
+    target->set_margin_right(margin);
+    target->set_margin_bottom(margin);
+}
+
+void core_window::set_margin(
+    Gtk::Widget *target, 
+    unsigned int margin_top, 
+    unsigned int margin_side
+) {
+    target->set_margin_top(margin_top);
+    target->set_margin_left(margin_side);
+    target->set_margin_right(margin_side);
+    target->set_margin_bottom(margin_top);
+}
+
+}

+ 33 - 0
cppGTK/source/core_window.hpp

@@ -0,0 +1,33 @@
+#ifndef CORE_WINDOW_H_INCLUDED
+#define CORE_WINDOW_H_INCLUDED
+
+#include <gtkmm.h>
+
+#include "strings.hpp"
+#include "buttons.hpp"
+
+namespace cx_light {
+
+class core_window: public Gtk::Window {
+    public:
+        core_window();
+        ~core_window();
+
+    private:
+        Gtk::Grid *content;
+        
+        Gtk::Frame *lights_list_frame;
+        Gtk::ListBox *lights_list;
+        
+        add_light_button *add_light;
+
+        void init_default();
+        void create_lights_list();
+
+        void set_margin(Gtk::Widget *, unsigned int);
+        void set_margin(Gtk::Widget *, unsigned int, unsigned int);
+};
+
+}
+
+#endif

+ 20 - 0
cppGTK/source/strings.cpp

@@ -0,0 +1,20 @@
+#include <cstddef>
+
+#include "strings.hpp"
+
+namespace cx_light {
+
+const char* strings::all_texts[] = {
+    "cx-light",
+    "Your lights",
+    "Add light"
+};
+
+const char* strings::get(unsigned int target) {
+    size_t list_size = sizeof(strings::all_texts) / sizeof(char *);
+    target = target % list_size;
+
+    return strings::all_texts[target];
+}
+
+}

+ 26 - 0
cppGTK/source/strings.hpp

@@ -0,0 +1,26 @@
+#ifndef STRINGS_H_INCLUDED
+#define STRINGS_H_INCLUDED
+
+namespace cx_light {
+
+class strings {
+    public:
+        enum selector {
+            WINDOW_TITLE,
+            LIGHTS_LIST,
+            ADD_LIGHT
+        };
+    
+        const char* get(unsigned int);
+
+    private:
+        static const char* all_texts[];
+};
+
+#ifndef __
+#define __(X) (strings().get(strings::selector::X))
+#endif
+
+}
+
+#endif

+ 5 - 39
reactJS/src/App.css

@@ -1,42 +1,8 @@
-#root {
-  max-width: 1280px;
-  margin: 0 auto;
-  padding: 2rem;
-  text-align: center;
-}
-
-.logo {
-  height: 6em;
-  padding: 1.5em;
-  will-change: filter;
-  transition: filter 300ms;
-}
-.logo:hover {
-  filter: drop-shadow(0 0 2em #646cffaa);
-}
-.logo.react:hover {
-  filter: drop-shadow(0 0 2em #61dafbaa);
-}
-
-@keyframes logo-spin {
-  from {
-    transform: rotate(0deg);
-  }
-  to {
-    transform: rotate(360deg);
-  }
-}
-
-@media (prefers-reduced-motion: no-preference) {
-  a:nth-of-type(2) .logo {
-    animation: logo-spin infinite 20s linear;
-  }
+body {
+    margin: 0;
+    padding: 0;
 }
 
-.card {
-  padding: 2em;
-}
-
-.read-the-docs {
-  color: #888;
+#root {
+    width: 100%;
 }

+ 1 - 0
reactJS/src/App.jsx

@@ -11,6 +11,7 @@ const image = (src, name) => {
 function App() {
   return (
     <>
+
     </>
   );
 }

+ 0 - 68
reactJS/src/index.css

@@ -1,68 +0,0 @@
-:root {
-  font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
-  line-height: 1.5;
-  font-weight: 400;
-
-  color-scheme: light dark;
-  color: rgba(255, 255, 255, 0.87);
-  background-color: #242424;
-
-  font-synthesis: none;
-  text-rendering: optimizeLegibility;
-  -webkit-font-smoothing: antialiased;
-  -moz-osx-font-smoothing: grayscale;
-}
-
-a {
-  font-weight: 500;
-  color: #646cff;
-  text-decoration: inherit;
-}
-a:hover {
-  color: #535bf2;
-}
-
-body {
-  margin: 0;
-  display: flex;
-  place-items: center;
-  min-width: 320px;
-  min-height: 100vh;
-}
-
-h1 {
-  font-size: 3.2em;
-  line-height: 1.1;
-}
-
-button {
-  border-radius: 8px;
-  border: 1px solid transparent;
-  padding: 0.6em 1.2em;
-  font-size: 1em;
-  font-weight: 500;
-  font-family: inherit;
-  background-color: #1a1a1a;
-  cursor: pointer;
-  transition: border-color 0.25s;
-}
-button:hover {
-  border-color: #646cff;
-}
-button:focus,
-button:focus-visible {
-  outline: 4px auto -webkit-focus-ring-color;
-}
-
-@media (prefers-color-scheme: light) {
-  :root {
-    color: #213547;
-    background-color: #ffffff;
-  }
-  a:hover {
-    color: #747bff;
-  }
-  button {
-    background-color: #f9f9f9;
-  }
-}