Practical library series : Anchor (A tiny GUI framework)

Under construction

Wait a moment please.

/media/uploads/shintamainjp/_scaled_dsc02830.jpg

The background

Sometime I need a beautiful user interface in my small embedded system.

But I can't spent much time to it.

So I decided to design and implement a tiny GUI framework for it.

The Basic Concepts

  • Simple
  • Small footprint
  • Easy to use, add, modify
  • Beautiful outputs
  • Powerful features (A little bit!)
  • C++ based.

Screenshots

Here is the outputs on 96x64 dots display.

/media/uploads/shintamainjp/anchor_demo_large.png

There are few components in the framework.

/media/uploads/shintamainjp/anchor_component_examples_large.png

FAQ

How do I use it?

You should implement a class for display to your display.

And then you can create an application with few classes for screens on the application.

Please see the example codes.

The application has 2 screens.

The codes in main.cpp are really simple.

&lt;<code title="main.cpp">&gt;

  1. include "mbed.h"
  2. include "Anchor.h"
  3. include "MyDesktopDefines.h"
  4. include "MyDisplayOLED.h"
  5. include "MyDesktop1.h"
  6. include "MyDesktop2.h"
  7. include "MyInputRotaryEncoder.h"
  8. include "MyOutputLED.h"

MyDisplayOLED display(p5, p6, p7, p21, p22, p23); AApplication app(&amp;display); MyInputRotaryEncoder input_re("Encoder", p17, p18); MyOutputLED output_led("LED");

MyDesktop1 desktop1(DESKTOP_1, "Desktop No.1", 96, 64); MyDesktop2 desktop2(DESKTOP_2, "Desktop No.2", 96, 64);

int main() { app.addInput(&amp;input_re); app.addOutput(&amp;output_led); app.addDesktop(&amp;desktop1); app.addDesktop(&amp;desktop2); app.loop(); } &lt;</code>&gt;

MyDesktop, MyDisplayOLED, MyDesktop1, MyDesktop2, MyInputRotaryEncoder, MyOutputLED has a parent class.

The most important class is 'ADesktop'.

The class provide base features for all widgets.

You can add components to your 'ADesktopXXX' class for design your application screen.

How can I implement a 'ADesktopXXX' class?

'ADesktop' is parent of your 'ADesktopXXX' class.

Please see a example below.

&lt;<code title="MyDesktop1.h">&gt;

  1. ifndef MY_DESKTOP1_H
  2. define MY_DESKTOP1_H
  1. include "Anchor.h"
  2. include &lt;mbed.h&gt;

class MyDesktop1 : public ADesktop { public: MyDesktop1(const char *name, char *text, int width = 0, int height = 0); virtual MyDesktop1(); virtual void tick(AContext *context); private: MyDesktop1(); LocalFileSystem fs; AImageBmpFile bmpimg; };

  1. endif &lt;</code>&gt;

And the implementation is here.

&lt;<code title="MyDesktop1.cpp">&gt;

  1. include "MyDesktop1.h"
  2. include "MyDesktopDefines.h"

MyDesktop1::MyDesktop1(const char *name, char *text, int width, int height) : ADesktop(name, text, width, height), fs("local"), bmpimg("AImageBmpFile.1", "/local/test.bmp", 96, 64) { add(&amp;bmpimg, 0, 0); }

MyDesktop1::MyDesktop1() { }

void MyDesktop1::tick(AContext *context) { static int cnt = 0; switch (cnt) { case 0: /*

  • To update the display.
  • / break; case 1: /*
  • Block the application control.
  • Page translation.
  • / wait(5); context-&gt;select(DESKTOP_2); break; } cnt++;

/*

  • Give the tick to the child.
  • / tickChild(context); } &lt;</code>&gt;

Added your 'ADesktopXXX' class to Application using addDesktop function in main.cpp.

You can change to another desktop with select function in the context class.

How do I get a key input?

How do I create a event for output?

The Structures

The Objects for The Basic Structure

AObject

  • AObject is the parent of all Anchor objects except special objects.
  • The object can not create its instance directly.

&lt;here is="" the="" draw=""&gt;

ADisplay

  • ADisplay is the parent of a display for outputs the GUI.
  • The object can not create its instance directly.
  • You can design a display object for your display device.

&lt;here is="" the="" draw=""&gt;

AFrameBuffer

  • ADisplay is the parent of a buffer for a display output.
  • The object can not create its instance directly.
  • You can design a buffer object for your display device.

&lt;here is="" the="" draw=""&gt;

The Widgets!

The widgets creates the GUI world.

AWidget

  • AWidget is the parent of all widgets.
  • The object can not create its instance directly.
  • You can design a widget object for your GUI application.

ACheckBox

ADeskTop

AImage

ALabel

AProgressBar

AWindow

for creation of your application

ADesktopManager

AApplication

AInputDevice

AOutputDevice

AInputDeviceManager

AOutputDeviceManager

License

If you use this on mbed

  • The library code license is MIT license.
  • You can use, add, modify the library freely.

If you use this on any other platforms (without mbed)

  • The library code license is MIT license.
  • Please report following information to me. It's just my interesting. :)
    • Country name.
    • Company name if you can. :)
    • Product name if you can. :)
  • You can use, add, modify the library freely.

License

&lt;<code>&gt; /**

  • =============================================================================
  • Anchor - A tiny GUI framework for embedded system.
  • =============================================================================
  • Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
  • 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.
  • =============================================================================
  • / &lt;</code>&gt;


Please log in to post comments.